question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

defaultZoneName not changing

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
icambroncommented, Dec 28, 2019

Yeah, you were effectively importing from two different Luxons, setting the setting in one and using it from the other.

1reaction
icambroncommented, Dec 28, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found