moment-timezone
moment-timezone copied to clipboard
Is there a way to get duration of DST change?
Moment-timezone version which you use:
Version: 0.5.34
Issue description:
It is actually not a bug, but question/request: is there a way to get a duration when time is changing (daylight saving)?
eg. for "Europe/Warsaw" it is +/-60min but for "Australia/Lord_Howe" it is +/-30min
Can I get the "60" or "30" in any way?
I don't think there's currently a built-in way to do that. You could try doing some manual calculations with the offset data returned by moment.tz.zone(zoneName)
.
There are some methods on the zone
object for specific timestamps: https://momentjs.com/timezone/docs/#/zone-object/
But you can also get the raw data:
moment.tz.zone('Australia/Lord_Howe').offsets
// returns...
[
-600, -630, -690, -630, -690, -630, -690, -630, -690, -630,
-660, -630, -660, -630, -660, -630, -660, -630, -660, -630,
-660, -630, -660, -630, -660, -630, -660, -630, -660, -630,
-660, -630, -660, -630, -660, -630, -660, -630, -660, -630,
// ...etc
]
Something to be aware of, though. Moment Timezone only knows about offsets and abbreviations; it doesn't know about whether DST is active. This means that sometimes an offset change in the data is not because of DST, but because the zone has changed its base offset (e.g. North Korea in both 2015 and 2018).
@nezriffic what you could do is start jumping by 6 months (i.e january - may) and look at the offset. If you get the diff of the offsets you'll get the DST jump.
However, as @gilmoreorless pointed out, it's never that simple. If you want to go more in-dept you can check the tasks/data-*.js
scripts and learn more about the iana tzdata format. The zdump files (after you run grunt data
you'll have them under temp/tzdata/latest/**/*.zdump
) have information about each particular "jump", how much was it and what is the DST state (i.e active, inactive or other).
I won't hold my breath for having this available in moment-timezone -- look for other alternatives (not sure if Intl handles this) or roll your own.