Olson Timezone Support #46
alanhamlett posted onGitHub
Update: Day.js Time Zone Plugin https://day.js.org/docs/en/timezone/timezone
This is great, but without timezone support it's not usable in real-world applications.
Agreed!
Update: Day.js Time Zone Plugin https://day.js.org/docs/en/timezone/timezone
+1 I am just thinking if we should add this to our core code, or as a plugin.
Plus, can you share some of timezone use cases? Or which API do we need?
moment.tz('2018-01-01', 'YYYY-MM-DD', 'America/New_York').unix()
I work on an enterprise platform that involves 3 external vendors in different parts of the country and nobody could get a timestamp right... so... we all had to agree on Eastern.
Plus, can you share some of timezone use cases? Or which API do we need?
The ability to parse, compare, and render dayjs objects from/in any timezone. Matching the Moment Timezone API probably makes sense for portability.
A plugin would be acceptable, especially to keep core low (great for perf-minded folks). Especially since then we could take advantage of code-splitting, dynamic imports, etc. where it makes sense to do TZ related stuff (which admittedly, can be for the entire app but at least you're opting in).
@kamranayub we are working on is, PR #168
Any ideas?
Plus, can you share some of timezone use cases? Or which API do we need?
In a current project, users from different timezone can make appointments, so we have to convert their inputs to UTC before to compare times, then convert back to their local timezone to display on UI.
In that case, timezone is not browser timezone, but profile"s IATA timezone such as "Europe/Paris".
Conversions looks like:
Parsing locale timezone and converting to UTC:
const timezoneDate: Date = momentTimezone.tz('2018-08-22 12:30', 'Europe/Paris').utc().toDate();
Getting UTC offset for a date and a timezone:
// current timezone offset in Paris
const timezoneOffset: number = momentTimezone(new Date()).tz('Europe/Paris').utcOffset();
I am sorry, I did not notice this issue earlier. I opened a feature request #323 for introducing just parsing and formatting support with a specific time zone. I can imagine implementation using both Olson time zone database or the new Intl
support in the browser.
I do not know, if you wanted to make Day.js more complicated by remembering the original time zone in the Day.js object itself and supporting functions like .tz()
or .utcOffset()
. But I believe, that it is possible with still retaining the internal Date
object, with some limitations.
I do this:
dayjs(new Date().toLocaleString("en-US", {timeZone: "America/New_York"})).format('h:mA')
dayjs(new Date().toLocaleString("en-US", {timeZone: "America/Los_Angeles"})).format('h:mA')
@issuehunt has funded $200.00 to this issue.
- Submit pull request via IssueHunt to receive this reward.
- Want to contribute? Chip in to this issue via IssueHunt.
- Checkout the IssueHunt Issue Explorer to see more funded issues.
- Need help from developers? Add your repository on IssueHunt to raise funds.
Intl API might be a better choice for our project?
Sad, looking for MomentJS alternative and I found DayJS but it's have no timezone support, So, I will get Luxon any way.
I do this:
dayjs(new Date().toLocaleString("en-US", {timeZone: "America/New_York"})).format('h:mA') dayjs(new Date().toLocaleString("en-US", {timeZone: "America/Los_Angeles"})).format('h:mA')
This solution works. Just don't do as I did and wonder why timezone
doesn't work 😞 (hint: use timeZone
, uppercase Z)
Any update dude?
Update: Day.js Time Zone Plugin https://day.js.org/docs/en/timezone/timezone
Fund this Issue
Rewarded pull request
Other pull requests
Click to copy link
Recent activities