defaultZoneName not changing
See original GitHub issueI have this function that I am using in React 16.12 with Luxon 1.21.3
export const setSystemTimezone = (timezone) => {
Settings.defaultZoneName = timezone;
console.log(DateTime.local().zoneName);
}
When the function is called with any valid timezone (“utc”, “America/Los_Angeles”, etc.) I always get my system timezone logged America/New_York
.
Also, my other datetimes are still America/New_York
when being displayed with
export const formatDatetime = (datetime) => {
return datetime.toFormat("fff");
}
My expectation is that setSystemTimezone("Europe/Berlin")
would log Europe/Berlin
and that the other datetimes in my app would have their timestamps changed and display in GMT+1
upon re-render.
Am I doing something wrong or is this expectation incorrect?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Settings defaultZoneName doesn't seem to apply. · Issue #1003
Try Settings.defaultZone = "Europe/Paris"; . This is a 2.0 breaking change: https://moment.github.io/luxon/#/upgrading?id=default-zone ...
Read more >How to use the luxon.Settings.defaultZoneName function in ...
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >How to Handle Time Zones using DateTime and Luxon
The defaultZoneName can be used as a set or get method for the default time zone when you're working with the library.
Read more >luxon 3.1.1 | Documentation
Returns a string representation of a Duration with all units included. To modify its behavior use the listStyle and any Intl.NumberFormat option, though ......
Read more >Weird timezone issue with pytz - python - Stack Overflow
Time zones and offsets change over the years. The default zone name and offset delivered when pytz creates a timezone object are the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, you were effectively importing from two different Luxons, setting the setting in one and using it from the other.
The first issue–that the default zone doesn’t seem to take for new DateTimes-- is unexpected. In fact, I can’t reproduce it. Here is a fiddle of it: https://jsfiddle.net/wemdo92r/. Maybe you have something weird in your environment where Settings is being imported from a separate place from DateTime? I’m just guessing, but it has to be something.
On the second issue, that depends: are you recreating the instances? Changing the default timezone will not update existing instances. It only determines the zone for new instances.