Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2020-10

Converting date formats

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryan Joseph

I have some dates formats like this which I would like to convert to TDateTime. Are these supported in the RTL? I tried using the StrToDate functions but I got errors.

program test;
uses
  SysUtils;
begin
  StrToDate('2001-12-14T21:59:43.10Z-05:00');
end.

Regards,
Ryan Joseph

Reply by email

Michael Van Canneyt
to Ryan Joseph
Ryan Joseph wrote 8 lines
I have some dates formats like this which I would like to convert to TDateTime. Are these supported in the RTL? I tried using the StrToDate functions but I got errors. program test; uses SysUtils; begin StrToDate('2001-12-14T21:59:43.10Z-05:00'); end.

Do you ever read the documentation ?

You might then have read why the above will never work.

You probably need this:

https://www.freepascal.org/docs-html/current/rtl/dateutils/iso8601todate.html

or even this

https://www.freepascal.org/docs-html/current/rtl/dateutils/scandatetime.html

If you need full timezone handling, then there are no such routines in the RTL. However, there is somewhere a package (I believe it is mentioned in the wiki) that handles timezones and whatnot.

Michael.

Reply by email

Ryan Joseph
to Michael Van Canneyt
Show quoted text 17 lines
On Oct 3, 2020, at 10:37 AM, Michael Van Canneyt wrote: Do you ever read the documentation ? You might then have read why the above will never work. You probably need this: https://www.freepascal.org/docs-html/current/rtl/dateutils/iso8601todate.html or even this https://www.freepascal.org/docs-html/current/rtl/dateutils/scandatetime.html If you need full timezone handling, then there are no such routines in the RTL. However, there is somewhere a package (I believe it is mentioned in the wiki) that handles timezones and whatnot.

I have no idea about dates and where to find these functions in the RTL. I just saw the date at https://tools.ietf.org/html/rfc3339.

What do those links say about it not being possible? ISO8601ToDate seems to work if I change the decimal representation of the seconds to an integer.

Regards,
Ryan Joseph

Reply by email

Winfried Bartnick
to Ryan Joseph
Ryan Joseph wrote 29 lines
> On Oct 3, 2020, at 10:37 AM, Michael Van Canneyt wrote: > > Do you ever read the documentation ? > > You might then have read why the above will never work. > > You probably need this: > > https://www.freepascal.org/docs-html/current/rtl/dateutils/iso8601todate.html > > or even this > > https://www.freepascal.org/docs-html/current/rtl/dateutils/scandatetime.html > > If you need full timezone handling, then there are no such routines in the > RTL. However, there is somewhere a package (I believe it is mentioned in the > wiki) that handles timezones and whatnot. I have no idea about dates and where to find these functions in the RTL. I just saw the date at https://tools.ietf.org/html/rfc3339. What do those links say about it not being possible? ISO8601ToDate seems to work if I change the decimal representation of the seconds to an integer. Regards, Ryan Joseph _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Hi!

Timezones are handled by the package PascalTZ.

It is available through the Online Package Manager.

Winni

Reply by email

Ryan Joseph
to Winfried Bartnick
Show quoted text 10 lines
On Oct 3, 2020, at 2:15 PM, Winfried Bartnick via fpc-pascal wrote: Hi! Timezones are handled by the package PascalTZ. It is available through the Online Package Manager. Winni

Thanks. I think the format I had was ISO8601 but had decimal precision for the seconds. According to the spec I was following I didn't see any timezones, just a local time with an offset from UTC. I don't understand why this is preferable to timezones however. It's all very confusing if you ask me.

Regards,
Ryan Joseph

Reply by email

Winfried Bartnick
to Ryan Joseph
Ryan Joseph wrote 16 lines
> On Oct 3, 2020, at 2:15 PM, Winfried Bartnick via fpc-pascal wrote: > > Hi! > > > Timezones are handled by the package PascalTZ. > > It is available through the Online Package Manager. > > Winni Thanks. I think the format I had was ISO8601 but had decimal precision for the seconds. According to the spec I was following I didn't see any timezones, just a local time with an offset from UTC. I don't understand why this is preferable to timezones however. It's all very confusing if you ask me. Regards, Ryan Joseph

Hi!

If you have Time offset to UTC then you have all you need - from the technical poin of view.

But there are complications due to daylight saving.

In the summertime Central Europe is 2 hours away from UTC.  In winter only one.

Not enough trouble : There are a lot of algorithms for begin and end of the different countries.

And in the southern half of the globe, the start the daylight saving, when we end it.

That is what PascalTZ can do for you.

Or you do it like the flight buisiness.

All times for the pilots are UTC. And for the passengers this is converted to the local time. Avoids crashes.

And due to political decissions there is a lot of nonsense.

Example very #1: Hawai and Kiribati are around the same longitude.

Hawai is TZ -10. But Kiribati is TZ +14. So they are allways 24 hours ahead. Non-sense.

O Lord - don't ask me questions ...

Winni

_______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Michael Van Canneyt
to Ryan Joseph: I have no idea about dates and where to find these functions in the RTL. I just saw the…
Ryan Joseph wrote
I have no idea about dates and where to find these functions in the RTL. I just saw the date at https://tools.ietf.org/html/rfc3339.

Well, if you are really ignorant about these functions, why not go to the index page (linked to from the top of every page)

https://www.freepascal.org/docs-html/current/rtl/index-8.html

And using your browser's find function look for "date".

Alternatively, Google usually also turns up very good answers.

What do those links say about it not being possible? ISO8601ToDate seems to work if I change the decimal representation of the seconds to an integer.

I was trying to point you in a better direction.

My commend was meant to indicate that the documentation of StrToDate (the function you used) clearly mentions that there is a restriction on allowed formats:

https://www.freepascal.org/docs-html/current/rtl/sysutils/strtodate.html

Reading that would have helped you understand you're using the wrong function.

Blindly using a function and getting errors, my first instinct is to look for documentation.

Michael.

Reply by email