Chrome 67 and Historic Time Zone Changes
In the recent Chrome 67 update, developers have encountered an issue with time zone handling for dates prior to 1970. This article aims to address this error and provide guidance for developers affected by it.
Problem Description
When invoking new Date("1900-01-01T00:00:00").getTimezoneOffset(), users observe an offset of -150 minutes in Chrome 67, whereas other browsers, such as Edge, Internet Explorer, and Firefox, consistently return -180 minutes. This discrepancy has caused confusion and errors in code relying on accurate time zone information.
Analysis and Solution
The different time zone offsets in Chrome 67 compared to other browsers are attributed to the way the underlying time zone data is sourced and handled. Chrome 67 appears to be using data from the IANA time zone database, which provides more detailed information about historical time zone changes. According to the IANA database, the time zone in question (Europe/Moscow) had an offset of 02:30:17 in 1900. Chrome rounds this down to 02:30, resulting in the offset of -150 minutes.
However, for dates before 1970, IANA explicitly states that the data is "best effort" and may not be entirely accurate. Therefore, relying on precise time zone information for dates prior to 1970 is discouraged.
To mitigate this issue, developers are advised to avoid using the Date constructor with dates prior to 1970. Instead, they should stick to dates after the Unix epoch (January 1, 1970), as IANA data is generally more reliable for this period. If accurate historical time zone information is essential, developers may need to explore alternative sources of data.
The above is the detailed content of Why is Chrome 67 returning a different time zone offset for dates before 1970?. For more information, please follow other related articles on the PHP Chinese website!