index.js 879 B

12345678910111213141516
  1. /**
  2. * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
  3. * They usually appear for dates that denote time before the timezones were introduced
  4. * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
  5. * and GMT+01:00:00 after that date)
  6. *
  7. * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
  8. * which would lead to incorrect calculations.
  9. *
  10. * This function returns the timezone offset in milliseconds that takes seconds in account.
  11. */
  12. export default function getTimezoneOffsetInMilliseconds(date) {
  13. var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
  14. utcDate.setUTCFullYear(date.getFullYear());
  15. return date.getTime() - utcDate.getTime();
  16. }