Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I use js-joda timezone operations in node?

I am attempting to use @js-joda/core in this code snippet in a node environment:

LocalDateTime.parse(row.date + "T" + row.time)
    .atZone(ZoneId.of("America/Los_Angeles"))
    .toInstant()
    .toEpochMilli()

I get this error:

ERROR: unsupported ZoneId:America/Los_Angeles 

 {
  "stack": "Error\n    at getRules (/Users/kevin/project/node_modules/@js-joda/core/dist/js-joda.js:4395:15)\n    at ofId (/Users/kevin/project/node_modules/@js-joda/core/dist/js-joda.js:4406:39)\n    at of (/Users/kevin/project/node_modules/@js-joda/core/dist/js-joda.js:10262:27)\n    at <anonymous> (/Users/kevin/project/app/app/scripts/create-tags.ts:119:30)\n    at <anonymous> (/Users/kevin/project/app/app/scripts/create-tags.ts:79:25)\n    at map (native)\n    at <anonymous> (/Users/kevin/project/app/app/scripts/create-tags.ts:79:14)\n    at processTicksAndRejections (native)",
  "message": "unsupported ZoneId:America/Los_Angeles"
} 

I can run this code fine in the browser console at https://js-joda.github.io/js-joda/:
working

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What do I need to set up to make this work in a node environment?

>Solution :

Js-joda package has been deprecated, you can use @js-joda/core instead

npm i @js-joda/core @js-joda/timezone

and

you need to import @js-joda/timezone at the top of the file, this will enable time zone

import '@js-joda/timezone';

then try this

LocalDateTime.parse(row.date + "T" + row.time)
    .atZone(ZoneId.of("America/Los_Angeles"))
    .toInstant()
    .toEpochMilli()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading