Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Olson Timezone Support #46

Closed
alanhamlett opened this issue Apr 24, 2018 · 15 comments
Closed

Olson Timezone Support #46

alanhamlett opened this issue Apr 24, 2018 · 15 comments

Comments

@alanhamlett
Copy link

alanhamlett commented Apr 24, 2018

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.

@operfildoluiz
Copy link

Agreed!

@iamkun
Copy link
Owner

iamkun commented Apr 28, 2018

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?

@brandonros
Copy link

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.

@alanhamlett
Copy link
Author

alanhamlett commented May 1, 2018

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.

@kamranayub
Copy link

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).

@iamkun
Copy link
Owner

iamkun commented Jun 22, 2018

@kamranayub we are working on is, PR #168

Any ideas?

@Toub
Copy link
Contributor

Toub commented Aug 22, 2018

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();

@prantlf
Copy link
Contributor

prantlf commented Sep 4, 2018

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.

@ghost
Copy link

ghost commented Oct 9, 2018

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')

demo -> https://plnkr.co/edit/KjrKnwvxBktn3GJmDwDw

Refer: https://medium.com/@bmarti44/10-helpful-tips-i-wish-i-knew-before-i-started-using-angular-2-c25bcaa6fe2f

@IssueHuntBot
Copy link

@IssueHunt has funded $200.00 to this issue.


@iamkun
Copy link
Owner

iamkun commented Apr 12, 2019

Intl API might be a better choice for our project?

@janat08 janat08 mentioned this issue Jun 2, 2019
@alexsandro-xpt
Copy link

Sad, looking for MomentJS alternative and I found DayJS but it's have no timezone support, So, I will get Luxon any way.

@tommulkins
Copy link

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')

demo -> https://plnkr.co/edit/KjrKnwvxBktn3GJmDwDw

Refer: https://medium.com/@bmarti44/10-helpful-tips-i-wish-i-knew-before-i-started-using-angular-2-c25bcaa6fe2f

This solution works. Just don't do as I did and wonder why timezone doesn't work 😞 (hint: use timeZone, uppercase Z)

@trylovetom
Copy link

Any update dude?

@issuehunt-oss issuehunt-oss bot added the 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt label Apr 15, 2020
@iamkun iamkun removed the 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt label Apr 15, 2020
Repository owner deleted a comment from issuehunt-oss bot Apr 17, 2020
@iamkun
Copy link
Owner

iamkun commented Aug 4, 2020

Update: Day.js Time Zone Plugin https://day.js.org/docs/en/timezone/timezone


@iamkun iamkun closed this as completed Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

12 participants