iamkun/dayjs

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!

posted by lhcgoncalves almost 7 years ago

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?

posted by iamkun almost 7 years ago

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.

posted by brandonros almost 7 years ago

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.

posted by alanhamlett almost 7 years ago

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

posted by kamranayub over 6 years ago

@kamranayub we are working on is, PR #168

Any ideas?

posted by iamkun over 6 years ago

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();
posted by Toub over 6 years ago

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.

posted by prantlf over 6 years ago

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

posted by xxyuk over 6 years ago

@issuehunt has funded $200.00 to this issue.


posted by IssueHuntBot almost 6 years ago

Intl API might be a better choice for our project?

posted by iamkun almost 6 years ago

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

posted by alexsandro-xpt over 5 years ago

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)

posted by tommulkins over 5 years ago

Any update dude?

posted by trylovetom over 5 years ago

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


posted by iamkun over 4 years ago

Fund this Issue

$200.00
Rewarded

Rewarded pull request

Other pull requests

Recent activities

iamkun was rewarded for iamkun/dayjs# 46
almost 5 years ago
iamkun submitted an output to  iamkun/ dayjs# 46
almost 5 years ago