Comments (5)
Time zone abbreviations can be ambiguous, such as CST
referring to "Central Standard Time" (USA), "China Standard Time" or "Cuba Standard Time". EST
could be "Eastern Standard Time" (USA), or "Eastern Standard Time" (Australia).
Hawaii is usually HAST
, but often HST
depending on whether the Hawaiian you ask knows or cares about the Aleutian islands in Alaska.
So if we support abbreviations at all, they should be with a specific output token for .format()
, and should be completely ignored when parsing.
We can obtain the correct time zone abbreviation from the tz data. Looking at the sample here, you can see that the abbreviation can be obtained by combining Zone.FORMAT
and Rule.LETTER/S
columns.
The list here has most of the common abbreviations, but I'm not sure if they align perfectly with the TZDB.
from moment-timezone.
Digging deeper, I see we are doing this already with both .zoneName()
and .zoneAbbr()
. Why two functions for the same thing?
from moment-timezone.
And from How to read the tz database:
And two last things about the FORMAT column:
- The tz database gives abbreviations for time zones names in popular usage, which is not necessarily “correct” by law. For example, the last line in Zone Pacific/Honolulu (shown below) gives “HST” for “Hawaii standard time” even though the legal name for that time zone is “Hawaii-Aleutian standard time.” This author has read that there are also some places in Australia where popular time zone names differ from the legal ones.
- No attempt is made to localize the abbreviations. They are intended to be the values returned through the "%Z" format specifier to C’s strftime function in the “C” locale.
from moment-timezone.
@mj1856, we have zoneAbbr
and zoneName
for the output for z
and zz
respectively. As zoneName
is usually localized, it is not added in the moment-timezone core, but I wanted to build a hook for it in case it was added later or in case someone wanted to write a plugin to handle it as well.
For the tests, I think we can just try to match the zdump
output. We already have the tokens in the descriptions of the unit tests, we just need to add them to the unit tests themselves.
// note PST and the end of the test description
t.equal(moment("1918-03-31T09:59:59+00:00").tz("America/Los_Angeles").format("HH:mm:ss"), "01:59:59", "1918-03-31T09:59:59+00:00 should be 01:59:59 PST");
from moment-timezone.
I added tests for the zone abbreviations in #82, so if that gets merged, this can be closed.
from moment-timezone.
Related Issues (20)
- Africa/Cairo 2023-4-27 add 1 day, unix value is not correct. HOT 2
- Unable to convert Device timezone HOT 1
- subtract(2, 'month').startOf('month') giving utc time without offset even if timezone is provided HOT 1
- Ignoring DST for "America/Mexico_City" Timezone HOT 1
- Egypt now in daylight savings which are not included in TZ data HOT 1
- Diffrent output in local and prod HOT 4
- Incorrect UTF characters in: date.js and date.min.js HOT 5
- Czechia and Slovakia timezone mixup HOT 1
- Not converting to Daylight Time 2023
- The parser may not ignore non-alphanumeric characters when it is with time zone. HOT 1
- cairo
- Module not found: ValidationError: Invalid parser object.
- "Friendly" should be invalid date, but it read as valid date HOT 2
- Data Mix-up for Canada Time Zones HOT 1
- Undefined (reading 'tz) HOT 2
- Error when using clone() and add() on a date in the America/Santiago timezone, where a daylight saving time change occurs. HOT 1
- moment().valueOf returns a value even though it's invalid HOT 2
- The DST calculation does not take effect. HOT 3
- import moment from 'moment-timezone'; import 'moment/min/locales'; not working HOT 5
- Can not set default timezone HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moment-timezone.