Dayjs timezone causes Invalid Date
Hi
Using dayjs, I want to change the timezone from UTC to the user timezone, e.g. Europe/Copenhagen.
Using the demo example from dayjs:
dayjs("2013-11-18 11:55:20").tz("America/Toronto")
Produces:
"Invalid Date"
https://day.js.org/docs/en/timezone/timezone
Node version 16.18.1
Time Zone · Day.js
Day.js supports time zone via the Internationalization API in supported environments. By using the native API, no extra bytes of tim...
14 Replies
Project ID:
860a5b73-658e-40e5-9897-6aac8389fe03
860a5b73-658e-40e5-9897-6aac8389fe03
outputs
though I am on Node.js v18.4.0
Thank you for taking your time.
Did you run that snippet on railway?
Because in most other node environments it works for me, just not on railway.
Your snippet works for example fine in 16.18.1 on runkit: https://npm.runkit.com/dayjs
RunKit
RunKit notebooks are interactive javascript playgrounds connected to a complete node environment right in your browser. Every npm module pre-installed.
I have not, ran locally, I will try to run that code on railway and get back to you
okay after some testing, I think what's happening is there is no zoneinfo being built into the container, or for whatever reason, it's not being detected by node. the easiest solution I can think of would be to build with a Dockerfile like this:
the above code works as expected on railway when built with that Dockerfile
I think we do need to document this. Lemme see what we can do here. Nothing immediate can be done unless we look at the builder + provider.
Sorry for my late reply. I don't get Discord notifications for some reason.
If i run: dayjs.tz.guess() i get "UTC". Not sure if that's just default or related to zoneinfo.
Is it possible to add zoneinfo manually?
I'm deploying Strapi on railway. Is there a specific dockerfile for Strapi?
I tried to add environment variable TZ="America/Toronto" and that does change the timestamps in the logs and the dayjs guess, but still get Invalid Date
are you deploying strapi from a template?
Yes, the strapi template
github.com/railwayapp-templates/strapi
yeah that builds with nixpacks that doesn't seem to be including timezone data in the final container, you would need to clone that repo and add a dockerfile like the one above, or wait until this missing timezone thing gets figured out by a team member. but beyond that i cant help because ive never used strapi, sorry
two other people have had issues related to missing timezone data, on python so i hope this gets looked at soon
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Thank you for linking that issue.
I can confirm that patching dayjs makes timezone work. Follow the link for details on this issue.
@×huggi× hi man, how did you patch it?