Issues Date/Time With Serverless functions
- Published on
- Authors
- Name
- Binh Bui
- @bvbinh
Photo by Boxed Water Is Better
Issues Dealing With Date/Time
Today my team got a complaint from a customer about
Timestamp is different between PROD and STG
There are quite a few issues with dates time and distributed system in general(distributed clients as well as distributed decision services)
- Identical Serverless functions could be running in different data center with different TZ
- Two client UIs could be running in different TZ.
- Mobile users, using the same application may travel to a different place. They expect the application to continue working correctly.
Solutions.
Convert all date/time to UTC before writing to the JSON payload:
For example:
2022-05-20T00:00:00.000Z This represents the date/time as ISO 8601 directly to the UTC reference (that is with no time zone specified).
1653004800000 The same date/time as the number of ms since epoch