How to avoid leaps and repetition caused by daylight savings?

Hi,

I have two ways of reading out an integer timestamp (in milliseconds) that seem to give the exact same values:

DateTime.utc_now() |> DateTime.to_unix(:millisecond)

and

System.os_time(:millisecond)

Are these the same under the hood? Are these prone to skipping or repeating an hour when daylight saving happens? Which one should I use when I want to avoid the side effects of daylight savings?

They are equivalent. They both return the OS time. In production, you generally don’t check the OS time/clock, you keep it in UTC, so there should be no jumps. If you are worried about jumps still, you can use System.monotonic_time.

2 Likes

How to avoid leaps and repetition caused by daylight savings?

By quitting computer science :upside_down_face: :wink:

6 Likes

I live in Belgium with timezeone UTC+1 and we are currently using DST and an UTC+2 timezone (summer time). Internally I use UTC (also in the DB) and only have to deal with DST when communicating with the outside world (input/output from/to a user interface or other systems) or when scheduling stuff (hours outside the DST ambiguous overlapping time). It avoids a lot of problems.