#1 2014-09-25 21:03:56

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 332

ISO-8601 timezone

Hi, I work with datetime with the following format: YYYY-MM-DDTHH:NN:SS.zzzZ, being zzz=millisenconds and Z=timezone. When I use ISO8601ToDateTime function the last Z is ignored and the datetime is converted regardless the timezone. Then I wrote the following code wrapping the ISO8601ToDateTime function:

class function IMRUtils.ISO8601ToDateTime(const aValue: String): TDateTime;
var
  lTimeZone: TTimeZoneInformation;
begin
  Result := SynCommons.Iso8601ToDateTime(aValue);
  if (aValue <> '') and (aValue[Length(aValue)] in ['Z', 'z']) then
  begin
    GetTimeZoneInformation(lTimeZone);
    Result := IncHour(Result, (lTimeZone.Bias div -60));
  end;
end;

This works fine, but I want to know if the framework support timezone. if so, I could not find.

TIA.

Esteban.


Esteban

Offline

#2 2014-09-25 23:06:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: ISO-8601 timezone

The framework uses UTC time by default.

It is to the ui layer to convert to/from local time.

Offline

#3 2014-09-26 08:23:56

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,534
Website

Re: ISO-8601 timezone

@EMartin code work correctly only for Today() - it not analyze DaylightBias. And DaylightBias is depend not only from winter/summer, but from country lows (before 1970 we do not have Daylight, after have and so on) 
So AB right - the easiest way is to convert DateTime to/from UTC in client - client know his Timezone historic table (there is bugs in Windows XP <= SP2 for some timezones).

But there is another problem - in case client convert DateTime to UTC server also must obviously sad to client dates is in UTC format. As I point in this topic current implementation do not do this.
So in my fork of mORMot I made several modification to add 'Z' (and 'T00:00Z' in case of Date w/o time) to the end of time string ( TSQLTableJSON serialization,  TJSONSerializer.WriteObject ) during serialization result to client.

Offline

#4 2014-09-26 10:36:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: ISO-8601 timezone

You can indeed add 'Z' to every date/time.

Or use it as UTC value by convention on the client side.

Offline

#5 2014-09-26 18:36:33

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 332

Re: ISO-8601 timezone

@ab, @mpv thanks for reply.

I'll investigate how use mORMot UTC with string datetime received from external gateway in the format aforementioned.

Thanks again.

Esteban


Esteban

Offline

#6 2021-04-16 19:34:42

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,534
Website

Re: ISO-8601 timezone

I am facing a new unexpected DateTime serialization problem (problem described in topic above is fixed in mORMot by woDateTimeWithZSuffix serializer option).
My current problem is what even with woDateTimeWithZSuffix is ON we serialize a Date (without time) into  'T00:00Z' (without seconds) and Date with time into  'Txx:yy:zzZ' (with seconds).

My API is used by different clients written using different programming languages, and in some languages de-serialization of the ISO date is "pattern based", for example in Oracle such terrible construction is used:

to_timestamp_tz ('2014-09-12T11:53:06Z', 'YYYY-MM-DD"T"HH24:MI:SSTZH:TZM')

and it fails if ISO string is come without seconds in form '2014-09-12T00:00Z' sad

Something similar is in the Objective-C.

So, my proposal is to add a seconds for dates (change 'T00:00Z' -> 'T00:00:00Z' into mORMot.pas), in this case the same pattern can be used to decode time with and without seconds. I think it should not broke an existed code.

Last edited by mpv (2021-04-16 19:35:46)

Offline

#7 2021-04-16 22:20:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: ISO-8601 timezone

I guess this is a fair fix.

Could you send some pull requests?
Thanks!

Offline

#8 2021-04-17 06:12:58

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,534
Website

Re: ISO-8601 timezone

Offline

#9 2021-04-17 08:16:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: ISO-8601 timezone

Merged.

Thanks!

Offline

Board footer

Powered by FluxBB