formkit / tempo

📆 Parse, format, manipulate, and internationalize dates and times in JavaScript and TypeScript.
https://tempo.formkit.com
MIT License
2.37k stars 33 forks source link

Override the default timezone #64

Open joelstein opened 4 months ago

joelstein commented 4 months ago

Would you consider adding a feature to set the default timezone that Tempo would use to format dates?

Perhaps deviceTZ() could be enhanced to consult a default timezone override, falling back to the device timezone if unset?

ghiscoding commented 3 months ago

isn't tzDate() enough though? I asked similar question for UTC in an issue that I closed not long after getting more info from the author in this comment

So yes, if you want to create the utc time, in utc you can do tzDate('2020-02-04', 'utc'), but you can also do tzDate('2020-02-04T09:30', 'America/New_York') which would return a Date object (utc timestamp) for 9:30am on Feb 4th, 2020 in new york.

see tzDate docs

joelstein commented 3 months ago

Thank you. I'm primarily concerned with formatting the dates. All of my dates come from the server in UTC, but I always want them displayed in the website's local timezone (which may be different than the user's timezone).

That's why I think being able to set a default format (or display) timezone would be useful.

As it is now, I have to remember to set the timezone in every call to format() (and there are many in this application we're building).