Timezone support for moment.js

Overview

Moment Timezone

NPM version NPM downloads MIT License Build Status FOSSA Status SemVer compatibility

IANA Time zone support for Moment.js

Project Status

Moment-Timezone is an add-on for Moment.js. Both are considered legacy projects, now in maintenance mode. In most cases, you should choose a different library.

For more details and recommendations, please see Project Status in the Moment docs.

Thank you.

Resources

Examples

var june = moment("2014-06-01T12:00:00Z");
june.tz('America/Los_Angeles').format('ha z'); // 5am PDT
june.tz('America/New_York').format('ha z');    // 8am EDT
june.tz('Asia/Tokyo').format('ha z');          // 9pm JST
june.tz('Australia/Sydney').format('ha z');    // 10pm EST

var dec = moment("2014-12-01T12:00:00Z");
dec.tz('America/Los_Angeles').format('ha z');  // 4am PST
dec.tz('America/New_York').format('ha z');     // 7am EST
dec.tz('Asia/Tokyo').format('ha z');           // 9pm JST
dec.tz('Australia/Sydney').format('ha z');     // 11pm EST

License

Moment-timezone is freely distributable under the terms of the MIT license.

FOSSA Status

Comments
  • Guess current timezone

    Guess current timezone

    This adds the ability to guess the browser's timezone. See #138.

    Demo

    http://jsfiddle.net/bvjxt7jr/11/

    Implementation

    The implementation is fairly similar to jstimezonedetect. We look through a whitelist of zones and check if the offset matches in both January and June.

    There are about 500 different timezone identifiers, and about 60 unique January/June offset pairs in use this year. The limitations of jstimezonedetect also apply here. We don't differentiate between Europe/Berlin and Europe/Stockholm as they are equivalent in recent years.

    Whitelisted names

    These are the whitelisted timezone names for each January/June offset pair.

    | Jan | Jul | Timezone Name | | --- | --- | --- | | -11:00 | -11:00 | Pacific/Pago_Pago | | -10:00 | -10:00 | Pacific/Honolulu | | -10:00 | -09:00 | America/Adak | | -09:30 | -09:30 | Pacific/Marquesas | | -09:00 | -09:00 | Pacific/Gambier | | -09:00 | -08:00 | America/Anchorage | | -08:00 | -08:00 | Pacific/Pitcairn | | -08:00 | -07:00 | America/Los_Angeles | | -07:00 | -07:00 | America/Phoenix | | -07:00 | -06:00 | America/Denver | | -06:00 | -06:00 | America/Guatemala | | -06:00 | -05:00 | America/Chicago | | -05:00 | -05:00 | Pacific/Easter | | -05:00 | -04:00 | America/New_York | | -04:30 | -04:30 | America/Caracas | | -04:00 | -04:00 | America/Santo_Domingo | | -04:00 | -03:00 | America/Halifax | | -03:30 | -02:30 | America/St_Johns | | -03:00 | -04:00 | America/Campo_Grande | | -03:00 | -03:00 | America/Santiago | | -03:00 | -02:00 | America/Godthab | | -02:00 | -03:00 | America/Montevideo | | -02:00 | -02:00 | America/Noronha | | -01:00 | -01:00 | Atlantic/Cape_Verde | | -01:00 | +00:00 | Atlantic/Azores | | +00:00 | +00:00 | Etc/UTC | | +00:00 | +01:00 | Europe/London | | +00:00 | +02:00 | Antarctica/Troll | | +01:00 | +01:00 | Africa/Lagos | | +01:00 | +02:00 | Europe/Berlin | | +02:00 | +01:00 | Africa/Windhoek | | +02:00 | +02:00 | Africa/Johannesburg | | +02:00 | +03:00 | Asia/Beirut | | +03:00 | +03:00 | Europe/Moscow | | +03:30 | +04:30 | Asia/Tehran | | +04:00 | +04:00 | Asia/Dubai | | +04:00 | +05:00 | Asia/Baku | | +04:30 | +04:30 | Asia/Kabul | | +05:00 | +05:00 | Asia/Yekaterinburg | | +05:30 | +05:30 | Asia/Kolkata | | +05:45 | +05:45 | Asia/Kathmandu | | +06:00 | +06:00 | Asia/Omsk | | +06:30 | +06:30 | Asia/Rangoon | | +07:00 | +07:00 | Asia/Krasnoyarsk | | +07:00 | +08:00 | Asia/Hovd | | +08:00 | +08:00 | Asia/Shanghai | | +08:00 | +09:00 | Asia/Ulaanbaatar | | +08:45 | +08:45 | Australia/Eucla | | +09:00 | +09:00 | Asia/Yakutsk | | +09:30 | +09:30 | Australia/Darwin | | +10:00 | +10:00 | Australia/Brisbane | | +10:30 | +09:30 | Australia/Adelaide | | +11:00 | +10:00 | Australia/Sydney | | +11:00 | +10:30 | Australia/Lord_Howe | | +11:00 | +11:00 | Pacific/Noumea | | +11:30 | +11:30 | Pacific/Norfolk | | +12:00 | +12:00 | Pacific/Tarawa | | +13:00 | +12:00 | Pacific/Auckland | | +13:00 | +13:00 | Pacific/Tongatapu | | +13:45 | +12:45 | Pacific/Chatham | | +14:00 | +13:00 | Pacific/Apia | | +14:00 | +14:00 | Pacific/Kiritimati |

    Keeping whitelist up to date

    It is likely that this list will change based on updates to the tzdb, so we will probably need a way to tie this to data updates.

    One problem we will need to solve is how to determine which timezone to use in the whitelist for a given offset pair. For example, there are many timezones that match -08:00/-07:00 this year. America/Dawson, America/Ensenada, America/Los_Angeles, America/Santa_Isabel, America/Tijuana, America/Vancouver, America/Whitehorse, Canada/Pacific, Canada/Yukon, Mexico/BajaNorte, PST8PDT, US/Pacific, US/Pacific-New.

    The current whitelist is mostly based on the list from jstimezonedetect with a couple additions for new tzdb data. Ideally, we could get data for the population in each timezone and use that to choose the best candidate, but I'm not sure where we could find that data.

    User added whitelisting

    Because we are just looking through an array of names, we can expose that list to the user to add their own names.

    moment.tz.currentZone(); // America/Chicago
    moment.tz.currentZoneWhitelist.unshift('US/Central');
    moment.tz.currentZone(); // US/Central
    

    We should probably make a dedicated api for this rather than having to know the internals of whether to push or unshift onto the array.

    Bikeshedding

    Now the fun part.

    There are a few different names we could go with here.

    moment.tz.identify();
    moment.tz.detect();
    moment.tz.guess();
    moment.tz.currentZone();
    moment.tz.guessZone();
    moment.tz.userZone();
    

    To add user defined whitelisted names, we also have a couple options.

    moment.tz.detect('US/Pacific'); // used as a getter/setter
    moment.tz.identify('US/Pacific');
    moment.tz.canDetect('US/Pacific');
    moment.tz.canGuess('US/Pacific');
    moment.tz.currentZoneWhitelist('US/Pacific');
    moment.tz.userZoneWhitelist('US/Pacific');
    
    New Feature 
    opened by timrwood 99
  • change default timezone

    change default timezone

    It would be great to have a method to change the default timezone (eg: when the application starts moment.tz.setDefault('America/New_York')). Then, all the subsequent calls to moment() will automatically set the timezone with the default one.

    enhancement 
    opened by fabriziofortino 74
  • Do not log error when requiring moment-timezone multiple times in Node

    Do not log error when requiring moment-timezone multiple times in Node

    In Node it is quite common to require a module in multiple places

    Right now if I require moment-timezone in multiple places I am getting

    Moment Timezone 0.4.0 was already loaded with data from 2015d
    

    That comes from this line (#212 )

    This shouldn't be logged as an error and just clutters the server logs. If anything, it should be a warning but in Node env it shouldn't be printed at all IMO

    enhancement 
    opened by mderazon 42
  • Get the browsers current time zone.

    Get the browsers current time zone.

    Unless I'm missing something it seems that there is no way to get the current time zone?? I know there are third party libs to get the olson name.. I just thought this would be included.

    moment.tz().zoneName() moment.tz(new Date()).zoneName() moment.tz(new Date()).zone()

    enhancement 
    opened by niemyjski 40
  • Adding country functionality from metadata

    Adding country functionality from metadata

    PR for adding country functionality from metadata.

    API: var zones = moment.tz.zonesForCountry('US'); // returns ['America/Chicago', ' America/New_York', etc...] var country = moment.tz.zone('America/Los_Angeles').country; // returns ['US']

    Countries has been added to each zone containing the countries within the zone as well as a countries section containing the abbreviation and zones inside to both the packed and unpacked data.

    I welcome any feedback and feel free to ask any questions or for further development.

    Sorry for the delay adding the feature, I am a student at university and have a high workload at the moment.

    Issues requesting the feature:

    • https://github.com/moment/moment-timezone/issues/289
    • https://github.com/moment/moment-timezone/issues/400

    Original Pull Request: https://github.com/moment/moment-timezone/pull/377 ** had some difficulty with not being able to merge and so created new pull request, sorry for any inconvenience.

    opened by adgrace 36
  • construct moment in zone

    construct moment in zone

    This creates the moment in local time:

    moment("2013-01-01T00:00:00")
    

    This creates the moment in UTC:

    moment.utc("2013-01-01T00:00:00")
    

    So I would expect to be able to create a moment in a particular zone with:

    moment.tz("America/New_York","2013-01-01T00:00:00")
    

    That gives an error, so I tried this:

    moment.tz("2013-01-01T00:00:00", "America/New_York")
    

    And it works, but gives a result of 2013-01-01T02:00:00-05:00. I would expect 2013-01-01T00:00:00-05:00.

    I think it is assuming the input value is in my local offset (-07:00) and then converting it to the time zone specified.

    All together, I'd expect to be able to convert from time zone A to time zone B like this:

    moment.tz("2013-01-01T00:00:00","America/New_York").tz("America/Los_Angeles").format()
    

    Also - we need a way to deal with ambiguous or invalid input times.

    enhancement pending 
    opened by mattjohnsonpint 28
  • I don't see a way to get an easy list of the available timezones

    I don't see a way to get an easy list of the available timezones

    My use case is populating a select element with options for the available timezones so the user can set their timezone. I was hoping for something along the lines of

    moment.tz.getTimezones() which would return something like

    [
        {
            name: "Eastern Standard Time"
          , locale: "America/New_York"
          , abbreviation: "EST"
          , offset: "-5"
        }
      , {
            name: "Central Standard Time"
          , abbreviation: "CST"
          , locale: "America/Chicago"
          , offset: "-6"
        }
    ]
    
    opened by hughlomas 24
  • Uncaught TypeError: Cannot read property 'version' of undefined

    Uncaught TypeError: Cannot read property 'version' of undefined

    This is a problem i'm currently having using https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.11/moment-timezone.js

    From what I can see, the moment-timezone on cdnjs is different from http://momentjs.com/downloads/moment-timezone.min.js

    opened by haskaalo 23
  • Timezone America/Sao_Paulo is wrong DST (now is -2 and correct is -3)

    Timezone America/Sao_Paulo is wrong DST (now is -2 and correct is -3)

    In this link is possible see the wrong when click in America/Sao_paulo https://momentjs.com/timezone/

    Brazil stop using DST but , moment timezone is using DST.

    Can I set the configuration for stop using DST?

    opened by alissonjdb 21
  • Wrong timezone for China/Schanghai

    Wrong timezone for China/Schanghai

    According to wiki The abbr. CST stands both for Central Standard Time (North America) and China Standard Time

    If you set your timezone on your PC to Shanghai, moment determines timezone: America/Chicago

    System Ubuntu, FF or Chrome "moment": "2.18.1", "moment-timezone": "0.5.13"

    chrome-console

    timezone

    Troubleshooting 
    opened by philipp-serfling 20
  • Brazilian daylight time

    Brazilian daylight time

    Hi, in 2019-04-29 the President of Brazil decreated the end of daylight time for 2019/2020. Yours have a prevision of publish a correction of the problem?

    opened by jgarcia-gv 19
  • Bump json5

    Bump json5

    Bumps json5 and json5. These dependencies needed to be updated together. Updates json5 from 2.2.0 to 2.2.3

    Release notes

    Sourced from json5's releases.

    v2.2.3

    v2.2.2

    • Fix: Properties with the name __proto__ are added to objects and arrays. (#199) This also fixes a prototype pollution vulnerability reported by Jonathan Gregson! (#295).

    v2.2.1

    • Fix: Removed dependence on minimist to patch CVE-2021-44906. (#266)
    Changelog

    Sourced from json5's changelog.

    v2.2.3 [code, diff]

    v2.2.2 [code, diff]

    • Fix: Properties with the name __proto__ are added to objects and arrays. (#199) This also fixes a prototype pollution vulnerability reported by Jonathan Gregson! (#295).

    v2.2.1 [code, diff]

    • Fix: Removed dependence on minimist to patch CVE-2021-44906. (#266)
    Commits
    • c3a7524 2.2.3
    • 94fd06d docs: update CHANGELOG for v2.2.3
    • 3b8cebf docs(security): use GitHub security advisories
    • f0fd9e1 docs: publish a security policy
    • 6a91a05 docs(template): bug -> bug report
    • 14f8cb1 2.2.2
    • 10cc7ca docs: update CHANGELOG for v2.2.2
    • 7774c10 fix: add proto to objects and arrays
    • edde30a Readme: slight tweak to intro
    • 97286f8 Improve example in readme
    • Additional commits viewable in compare view

    Updates json5 from 2.2.1 to 2.2.3

    Release notes

    Sourced from json5's releases.

    v2.2.3

    v2.2.2

    • Fix: Properties with the name __proto__ are added to objects and arrays. (#199) This also fixes a prototype pollution vulnerability reported by Jonathan Gregson! (#295).

    v2.2.1

    • Fix: Removed dependence on minimist to patch CVE-2021-44906. (#266)
    Changelog

    Sourced from json5's changelog.

    v2.2.3 [code, diff]

    v2.2.2 [code, diff]

    • Fix: Properties with the name __proto__ are added to objects and arrays. (#199) This also fixes a prototype pollution vulnerability reported by Jonathan Gregson! (#295).

    v2.2.1 [code, diff]

    • Fix: Removed dependence on minimist to patch CVE-2021-44906. (#266)
    Commits
    • c3a7524 2.2.3
    • 94fd06d docs: update CHANGELOG for v2.2.3
    • 3b8cebf docs(security): use GitHub security advisories
    • f0fd9e1 docs: publish a security policy
    • 6a91a05 docs(template): bug -> bug report
    • 14f8cb1 2.2.2
    • 10cc7ca docs: update CHANGELOG for v2.2.2
    • 7774c10 fix: add proto to objects and arrays
    • edde30a Readme: slight tweak to intro
    • 97286f8 Improve example in readme
    • Additional commits viewable in compare view

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    peer-dependencies 
    opened by dependabot[bot] 0
  • tz is current date dependent

    tz is current date dependent

    Moment-timezone version which you use:

    Version: 0.5.39

    Issue description:

    console.log(moment.tz('05-1', 'MM-d', true, 'UTC'));
    // returns Invalid date in 2022
    // returns 2023-05-01T00:00:00.000Z from January 1st, 2023
    // returns Invalid date in 2024
    
    opened by achifal 0
  • Incorrect value when adding week to date and crossing PST daylight savings

    Incorrect value when adding week to date and crossing PST daylight savings

    Moment-timezone version which you use:

    Version: "moment-timezone": "0.5.39" and "0.5.21"

    Issue description:

    Hello,

    I want to confirm if I'm using something incorrectly or if there is an issue:

    Adding a week to 2018-03-04T02:00:00-08:00 in PST gives me different results in moment, browser's Date and dotnet.

    For example, with 5.39:

    var moment = require("moment-timezone");
    console.log(
      moment.utc("2018-03-04T02:00:00-08:00").tz("America/Los_Angeles").add(1, "weeks").toISOString(true)
    );
    
    OUTPUTS "2018-03-11T02:00:00.000-07:00"  <- Notice the "2AM" and "-7:00".
    

    With 5.21:

    OUTPUTS: "2018-03-11T01:00:00.000-08:00"  <- Notice the "1AM" and "-8:00".
    

    However, browsers in a machine running PST, give a different date if we add 7-days' worth of milliseconds:

    new Date(new Date("2018-03-04T02:00:00-08:00").getTime() + 604800000)
    OUTPUTS: "Sun Mar 11 2018 03:00:00 GMT-0700 (Pacific Daylight Time)"  <- Notice the "3AM" and "-7:00"
    

    dotnet seems to agree with the 3AM value (in a machine running PST):

    TimeZoneInfo.ConvertTime(DateTimeOffset.Parse("2018-03-04T02:00:00-08:00").AddDays(7), TimeZoneInfo.Local).ToString("o")
    OUTPUTS: "2018-03-11T03:00:00.0000000-07:00"  <- Notice the "3AM" and "-7:00"
    

    Two questions:

    • why values returned by moment changed between 5.21 and 5.39? change in timezone data?
    • why values returned by moment do not match what browsers and dotnet return?

    Thanks

    bug 
    opened by fpintos 1
  • Dramatic increase in package size

    Dramatic increase in package size

    Moment-timezone version which you use:

    Version: 0.5.36

    Note: many issues are resolved if you just upgrade to the latest version

    Issue description:

    Package has increased size dramatically and AWS lambda layer rejecting the size. Seems it has gotten one additional folder in package - temp.back - which was not there in previous version.

    image

    Troubleshooting zdump-issue 
    opened by manishatcodal 11
  • Security vulnerability due to obsolete moment version

    Security vulnerability due to obsolete moment version

    Moment-timezone version which you use:

    Version: 0.5.34

    Issue description:

    Security vulnerability reported in our private repository due to moment-timezone. Please see advisory https://github.com/advisories/GHSA-wc69-rhjr-hc9g "Inefficient Regular Expression Complexity in moment". Current version of moment-timezone uses moment 2.9.0 . Please update dependency to at least 2.29.4 to fix the vulnerability.

    peer-dependencies wait-for-input 
    opened by VB-at-Bis 4
Releases(0.5.40)
Replace moment with dayjs, support use in vite, rollup, webpack

Replace moment with dayjs, support use in vite, rollup, webpack

null 11 Dec 6, 2022
A lightweight javascript timezone library

Isn't it weird how we can do math in our head, but not date math? how many days until the end of the year? what time was it, 11 hours ago? is it lunch

spencer kelly 3.7k Dec 29, 2022
⚡️ Fast parsing, formatting and timezone manipulations for dates

node-cctz CCTZ is a C++ library for translating between absolute and civil times using the rules of a time zone. Install You will need C++11 compatibl

Vsevolod Strukchinsky 59 Oct 3, 2022
⏰ Day.js 2KB immutable date-time library alternative to Moment.js with the same modern API

English | 简体中文 | 日本語 | Português Brasileiro | 한국어 | Español (España) | Русский Fast 2kB alternative to Moment.js with the same modern API Day.js is a

null 41.7k Dec 28, 2022
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API

English | 简体中文 | 日本語 | Português Brasileiro | 한국어 | Español (España) | Русский Fast 2kB alternative to Moment.js with the same modern API Day.js is a

null 41.7k Dec 28, 2022
:clock8: The original jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago").

timeago: a jQuery plugin Timeago is a jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "ab

Ryan McGeary 3.8k Dec 25, 2022
DEPRECATED: Timezone-enabled JavaScript Date object. Uses Olson zoneinfo files for timezone data.

TimezoneJS.Date A timezone-enabled, drop-in replacement for the stock JavaScript Date. The timezoneJS.Date object is API-compatible with JS Date, with

Matthew Eernisse 830 Nov 20, 2022
Replace moment with dayjs, support use in vite, rollup, webpack

Replace moment with dayjs, support use in vite, rollup, webpack

null 11 Dec 6, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A lightweight javascript timezone library

Isn't it weird how we can do math in our head, but not date math? how many days until the end of the year? what time was it, 11 hours ago? is it lunch

spencer kelly 3.7k Dec 29, 2022
⚡️ Fast parsing, formatting and timezone manipulations for dates

node-cctz CCTZ is a C++ library for translating between absolute and civil times using the rules of a time zone. Install You will need C++11 compatibl

Vsevolod Strukchinsky 59 Oct 3, 2022
💠 Webapp to see what time is in any timezone

Timero Webapp to see what time is in any timezone. Deploy https://ultirequiem.github.io/timero Characteristic Responsive Design Uses Packup as Bundler

Eliaz Bobadilla 7 May 15, 2022
Minimal utility to convert to or from any timezone. Deno/Node/Browser. ESM/CommonJS.

minitz Features Convert dates between any timezone supported by the system. Parses ISO8601 time strings. MIT licensed, use the library any way you wan

Hexagon 14 Oct 10, 2022
⏰ Day.js 2KB immutable date-time library alternative to Moment.js with the same modern API

English | 简体中文 | 日本語 | Português Brasileiro | 한국어 | Español (España) | Русский Fast 2kB alternative to Moment.js with the same modern API Day.js is a

null 41.7k Dec 28, 2022
Timers for your websites using moment.js

web-timers Timers for your websites using moment.js This small library allows you to make a timer. The process is very simple. Installation You just n

The Rediverse 1 Sep 9, 2022
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API

English | 简体中文 | 日本語 | Português Brasileiro | 한국어 | Español (España) | Русский Fast 2kB alternative to Moment.js with the same modern API Day.js is a

null 41.7k Dec 28, 2022
This adapter allows the use of Moment.js with Chart.js

chartjs-adapter-moment Overview This adapter allows the use of Moment.js with Chart.js. Moment.js is a very heavy library and thus not recommended for

Chart.js 26 Dec 27, 2022
A JavaScript component that is a date & time range picker, no need to build, no dependencies except Moment.js, that is based on Dan Grossman's bootstrap-daterangepicker.

vanilla-datetimerange-picker Overview. A JavaScript component that is a date & time range picker, no need to build, no dependencies except Moment.js,

null 22 Dec 6, 2022