tzdb icon indicating copy to clipboard operation
tzdb copied to clipboard

Error: Invalid unit value NaN in getTimeZones() method

Open cassiolacerda opened this issue 6 years ago • 9 comments

Hello!

I have that error when I try it:

index.js

import { getTimeZones, rawTimeZones, timeZonesNames } from "@vvo/tzdb"; console.log(getTimeZones());

error

InvalidArgumentError: Invalid unit value NaN at asNumber (C:\Users\lacer\Desktop\testando\node_modules\luxon\build\node\luxon.js:439:87) at normalizeObject (C:\Users\lacer\Desktop\testando\node_modules\luxon\build\node\luxon.js:450:35) at Function.fromObject (C:\Users\lacer\Desktop\testando\node_modules\luxon\build\node\luxon.js:2868:15) at getOffsetString (C:\Users\lacer\Desktop\testando\node_modules@vvo\tzdb\dist\formatTimeZone.js:23:50) at format (C:\Users\lacer\Desktop\testando\node_modules@vvo\tzdb\dist\formatTimeZone.js:18:44) at C:\Users\lacer\Desktop\testando\node_modules@vvo\tzdb\dist\getTimeZones.js:29:54 at Array.map () at getTimeZones (C:\Users\lacer\Desktop\testando\node_modules@vvo\tzdb\dist\getTimeZones.js:19:53) at Object. (C:\Users\lacer\Desktop\testando\index.js:2:13) at Module._compile (internal/modules/cjs/loader.js:1158:30)

Am i doing something wrong?

cassiolacerda avatar Aug 16 '20 00:08 cassiolacerda

Hi there, I just tried the latest version and it's working well, so there must be some difference in our environments here.

Can you tell me:

  • what's the Node.js version you're using?
  • are you trying to use the code with webpack or any other bundler?
  • are you on Windows?

Thanks!

vvo avatar Aug 16 '20 13:08 vvo

@vvo/tzdb: "^5.4.0" Node: v12.16.1 No bundlers Windows Home 10 version 1909

Probably is environment, I think so...

cassiolacerda avatar Aug 16 '20 17:08 cassiolacerda

I tried to debug the code and I found the problem. In C:\Users\lacer\Desktop\testando\node_modules@vvo\tzdb\dist\getTimeZones.js, line 20, there is a method from luxon that gets currentDate for using in currentTimeOffsetInMinutes:

=================

const currentDate = _luxon.DateTime.fromObject({ locale: "en-US", zone: timeZone.name });

console.log(currentDate);

const timeZoneWithCurrentTimeData = { ...timeZone,
  currentTimeOffsetInMinutes: currentDate.offset
};

When I log timeZone.name === "Antarctica/McMurdo", the date object returned from luxon shows that zone is not supported:

================= DateTime { ts: 1597603035971, _zone: LocalZone {}, loc: Locale { locale: 'pt-BR', numberingSystem: null, outputCalendar: null, intl: 'pt-BR', weekdaysCache: { format: {}, standalone: {} }, monthsCache: { format: {}, standalone: {} }, meridiemCache: null, eraCache: {}, specifiedLocale: null, fastNumbersCached: null }, invalid: Invalid { reason: 'unsupported zone', explanation: 'the zone "Antarctica/McMurdo" is not supported' }, weekData: null, c: null, o: null, isLuxonDateTime: true }

I removed the "Antarctica/McMurdo" from raw-time-zones.json and run correct!

The problem is my luxon version not recognized this zone. Maybe you need validate if currentDate returns a valid value to determine that loop should be execute, or run the next one.

cassiolacerda avatar Aug 16 '20 18:08 cassiolacerda

Having the same issue, same stack trace.

tzdb 5.4.0, luxon 1.24.1 Safari 13.1 on iOS 13.6

I'm getting this from our client-side error reporting and unfortunately cannot reproduce even with the same Safari version, so cannot tell on which timezone it stumbles. But ignoring unsupported timezones seems like a good idea, as they may differ in different environments.

dbanisimov avatar Aug 19 '20 23:08 dbanisimov

A reproducible example here on RunKit. Seems to work fine with Node v14, but not the latest LTS v12.

MaybeThisIsRu avatar Aug 20 '20 07:08 MaybeThisIsRu

Ok got it, I believe Node v14 is the only version that added this timezone, let me fix this!

vvo avatar Aug 20 '20 08:08 vvo

:tada: This issue has been resolved in version 5.4.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

vvo avatar Aug 20 '20 08:08 vvo

Let me know if this is working for you now

vvo avatar Aug 20 '20 08:08 vvo

Perfect! The new validation is running! Thanks guy!!!!!

cassiolacerda avatar Aug 21 '20 23:08 cassiolacerda