Sign in Join

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

Mailing lists / fpc-pascal / 2020-05

Zoned date/time conversions

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

I need to do timezone enabled date/time conversions...

Use case 1)
We want the application server to always use UCT and the application server might not be in the sime timezone as the client app. So we need to convert local time to UCT, do some time based processing on the server, then return data and convert all times back to the local time.

Use case 2)
Client's home address is in Spain. The application server is hosted in London. The client is on holiday in Australia. They book a grocery delivery while on holiday, and it must be delivered at 4pm the day they return from their holiday. So 4pm will be local Spainish time.

Data will be transported to/from the application server using JSON and REST API. So date/time info needs to be converted to/from string format.

What classes or methods are available in FPC to convert local date/time to UCT based time with offset and zone information?

Regards,
Graeme

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 23 lines
Hi, I need to do timezone enabled date/time conversions... Use case 1) We want the application server to always use UCT and the application server might not be in the sime timezone as the client app. So we need to convert local time to UCT, do some time based processing on the server, then return data and convert all times back to the local time. Use case 2) Client's home address is in Spain. The application server is hosted in London. The client is on holiday in Australia. They book a grocery delivery while on holiday, and it must be delivered at 4pm the day they return from their holiday. So 4pm will be local Spainish time. Data will be transported to/from the application server using JSON and REST API. So date/time info needs to be converted to/from string format. What classes or methods are available in FPC to convert local date/time to UCT based time with offset and zone information?

In the RTL, there is none.
There are some methods to find out local time zone, but that's about it.

However, there is some third-party class which has complete date/time handling:
https://wiki.freepascal.org/PascalTZ
sources on :
https://github.com/dezlov/PascalTZ

Michael.

Reply by email