Closed gauravrane2212 closed 5 years ago
The way Moment Timezone handles data means there are 2 scenarios that can happen when filtering the data:
matchZones
option of this plugin to exclude entire zones.Moment Timezone has no data for {zone name}.
startYear
and/or endYear
options of this plugin.Using your example of a date range from 2018 to 2030:
In many cases, this will accidentally give you the right UTC offset, but not always.
As an example to demonstrate... here in Sydney, my UTC offset is +10:00 by default, and +11:00 during daylight saving from October to April. Because daylight saving is active at the changeover of years, stripping out any data before 2018 will make Moment Timezone think Sydney was always +11:00 before 2018:
moment.tz('2018-07-01', 'Australia/Sydney').format()
// "2018-07-01T00:00:00+10:00" --> correct
moment.tz('2018-01-01', 'Australia/Sydney').format()
// "2018-01-01T00:00:00+11:00" --> correct
moment.tz('2017-07-01', 'Australia/Sydney').format()
// "2017-07-01T00:00:00+11:00" --> incorrect
moment.tz('2017-01-01', 'Australia/Sydney').format()
// "2017-01-01T00:00:00+11:00" --> correct, but only by accident
Oh, this explanation helps a lot. Especially the part where you mention how the timezone offsets to the nearest piece of data.
- Moment Timezone knows about an offset for that zone, using the nearest piece of data available, and uses that as a sort of "best guess".
Anyway, for my task, I am going to include some good amount of startYear
buffer to account for this offsetting. Closing this issue.
Hi All,
I am trying to test my code with PST , with years +-10 from current year, i could not find a year that fails the range, can you help
I am currently exploring this webpack plugin to reduce the import size of moment-timezone library in my project. I have set the following options in my webpack config file.
The reason I have this start year, is I wanted to test what would happen if I tried formatting a date which has a year before 2018 eg say 2017, 2016. (P.S. I noticed that the size of the import drastically reduced as per the documentation) However upon building the app and running it, I noticed that even though I was formatting dates with older years, it was still formatting the date correctly.
I am curious to know if this is expected or if you have seen the side effects of using the
startYear
or evenendYear
such that it doesn't correctly format the date? Do you have an example to demonstrate this.Thanks.