luxon: toFormat() does not work with i18n and fails on Node.js

Trying in Node.js with the following (this is the documentation example): DateTime.fromISO('2014-08-06T13:07:04.054').setLocale('fr').toFormat('yyyy LLL dd'); I get the result: "null Aug null".

The Node app runs on a server in UK (which has not brexited yet 😉 and rather than the French “aou.” for month I get the English “Aug”. Moreover day (dd) and year (yyyy) miserably fail 😭

Luckily, the toLocalString works. But I need to handle various user format.

See screen shot.

screenshot_2018-10-12 15 51 47_yl7br8

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 23 (6 by maintainers)

Most upvoted comments

I was experiencing the same error when running my code using Firebase cloud functions. Upgrading my firebase functions from Node 6 to Node 8 fixed it for me.

@matthiasg thanks a lot for claryfying. The polyfill is indeed not needed. - My personal issue is closed thereby.

One more thing: I guess my observation still hits people in environments where the polyfill IS NEEDED. What’s you opinion?

Greetings from Karlsruhe

In order to have Node.js process international formats:

  1. Add full-icu as a dependency
  2. set NODE_ICU_DATA in the environment to the path of the module (relative from start or absolute, e.g node_modules/full-icu)

Let’s separate a few things out here:

  1. The OP is running Node 10 and it isn’t working as expected. That’s an issue; I just can’t reproduce it so I haven’t made any progress
  2. @dvlsg is right that runtime flags aren’t how you enable ICU (instead, follow the Luxon instructions here). However, that’s neither here nor there, because Luxon doesn’t fail like that in the absence of Intl; it just falls back to English
  3. Node 6 doesn’t support formatToParts and thus can’t do Intl parsing and formatting whether or not it has access to the ICU data. That’s just how it is. You can see that documented here.
  4. edited That said, even Node 6 should be falling back to English, not spitting out nulls

@PierreKauffmann the only thing I can think of is to make super extra sure you’re really running the version of Node you think you are. Can you check process.version in the same process you’re testing Luxon? probably not the problem