index.js 1.0 KB

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