luxon: 1.11.4 fix which returns default timezone if set for the alias 'local' breaks everything

Hello.

Until the recent update to 1.11.4 using local time zone as a string explicitly set the zone to the browser default. While this was unexpected initially, we worked around it as follows:

// Set default time zone for project:
Settings.defaultZoneName = timezone || 'local';

// To interpret server side dates given in ISO:
const zonedDate = DateTime.fromISO(date); // Interprets it as the project timezone

// Show on the UI: Must be scoped to browser timezone so as to show it in terms of the local time
// which may be different from the project timezone (Ex: A user in Japan selecting shift timings in a 
// date input for a project in India - The user in Japan must be able to select times (say 8am to 3pm) 
// in his/her worldview without having to do conversions
const displayDate = zoneDate.setZone('local', {keepLocalTime: true});

// Parse input from the date-picker in browser zone, convert to project timezone, convert to ISO for server
const utc = DateTime
                                .fromJSDate(date, {zone: 'local'})
                                 // Get project time zone by checking the zone of .a new DateTime object
                                .setZone(DateTime.local().zoneName, {keepLocalTime: true})
                                .setZone('utc')
                                .toMillis()

Now obviously this has stopped working. I have to admit that the new behaviour should be the expected behaviour. I was initially surprised by the older behaviour and had to code around it. Now this fix is breaking all our code 😆 . While this is something which can be fixed on our end, I feel there is a legitimate need to be able to quick access the browser default.

Perhaps we can introduce a new alias like local such as system? Or is there a better solution I’m not seeing? (I’d like to avoid the use of the timeZoneOffset from the native date object although that is one feasible solution)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

Upon reflection, I agree with this proposal and I’d be happy to contribute to the PR.