Search code examples
datetimerusttimedst

Is `SystemTime::now` affected by Daylight saving time?


At time T, I invoke a SystemTime::now().duration_since(UNIX_EPOCH);

At at time T +10, when Daylight saving time has started, I invoke the same call.

Can I expect any weird behavior between the two instances?


Solution

  • SystemTime itself is completely independent of timezones. Timezones, as a concept, talk about how time is displayed to humans in a way that is helpful — SystemTime doesn’t talk to humans at all, it just gets the current time. Therefore, as UNIX_EPOCH is a point in time completely unaffected by timezones (it is defined to be 1970-01-01 00:00:00 UTC which is a fixed point in time irrespective of timezone), it is impossible to observe the effects of timezone factors like daylight savings on SystemTime.

    chrono should be used when you wish to show times to users in a human-readable format, or when you wish to parse times from user input, or otherwise do more complex programming that deals with human interpretations of time rather than the raw concept of time and duration itself. Just computing Unix timestamp, for example, should not be done with chrono (and chrono would not help).