Skip to content

Changing system/OS time zone, changes dates/times of posted messages

The SMB when_written.time message header field is supposed to reflect the wallclock time at the site a message was written. This value is initialized with the return value of time() for locally posted messages and in most cases for networked messages, is initialized by parsing a date/time string into a struct tm and converting that value to a time[32]_t by calling mktime[32]().

Unfortunately, time_t doesn't store/reflect Wallclock time, it stores an absolute/global time (in UTC). When the time is displayed, it can be displayed in UTC (e.g. using gmtime[_r]()) or displayed in the equivalent local time (using localtime[_r]()) as is usually the case. Unfortunately, the conversion to local time uses the current system/OS time zone. So if that time zone was changed at any point (to a different UTC offset, not counting changes between daylight and standard time), then the displayed time of the post no longer reflects the local/wallclock date/time at the site of the author/poster.

time_t and the underlying conversion functions are not a good choice for storing a wallclock time. Storing an encoding of a ISO-8601 date/time stamp would be a better choice.

Create to Deon for asking good questions and making me rethink this 30 year old design.