date-fns-tz icon indicating copy to clipboard operation
date-fns-tz copied to clipboard

Browser compatibility with zonedTimeToUtc, utcToZonedTime and formatInTimeZone

Open andre-ph opened this issue 2 years ago • 0 comments

First of all, thanks for the great library, it's great to work with. I am running some browser compatbility test right now, and it seems that the test in https://github.com/marnusw/date-fns-tz/blob/master/src/_lib/tzTokenizeDate/index.js#L54 to test if hourCycle is supported always give false (tested in Chromium 72 and Firefox 46-57 on Ubuntu 22.02)

Moreover, it seems that old Firefox can't recognize the America/New_York timezone for some reason, so maybe it's safer to test hourCycle support with UTC.

Indeed, it returns time in 12hours instead of 24 hours in these browsers, also should it be called hourCycleUnsupported or the ternary operator should be other-way round ? As when its false, it uses hourCycle.

Here is an example of a test that can work :

var testDateFormatted = new Intl.DateTimeFormat('en-US', {
  hourCycle: 'h23',
  year: 'numeric',
  month: '2-digit',
  day: '2-digit',
  hour: '2-digit',
  minute: '2-digit',
  second: '2-digit'
}).format(new Date('2014-06-25T00:00:00'));
var hourCycleSupported = testDateFormatted === '06/25/2014, 00:00:00' || testDateFormatted === '‎06‎/‎25‎/‎2014‎ ‎00‎:‎00‎:‎00';

andre-ph avatar Oct 24 '22 15:10 andre-ph