Comments (2)
Yes, a big difference between tempo and other date libraries is that the tokens are locale aware. So if you want to force a given locale you either need to set that as your system locale, or manually specify it per function call.
As for the .utc()
from moment β the answer is yes and no. Moment uses a non native date object to store information like timezone offsets. Tempo, by contrast, only uses native Date objects. You can choose to view this as a positive or a negative, personally, I greatly prefer it because it helps clarify what is actually occurring with date manipulation, and allows us to keep bundle sizes much smaller.
So βΒ how do you mark something as UTC in tempo? Well you donβt really, all native Date objects are essentially just UTC timestamps (when you console log them or interact with their methods they always show localized values for that underlying timestamp). Instead, tempo lets you create that date object (utc timestamp) by specifying the time in a given location. 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.
Hope that helps
from tempo.
So yes, if you want to create the utc time, in utc you can do
tzDate('2020-02-04', 'utc')
, but you can also dotzDate('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.
Yeah in my case, I'll go with the first option since I use it in a datagrid open source project and I have no clue what TZ the user is in, so the utc
option in tzDate()
is great for that.
On a side note, I tried many times to migrate away from MomentJS (I tried DayJS, date-fns, Luxon)... but Tempo was the only one that really worked out of the box. The parse/format is really important in a datagrid and Tempo works amazingly well and since you guys have the same token as MomentJS, it was easy to migrate... oh and the fact that you provide an ESM build is just the cherry on top π
Thanks for the great lib, I think I can close the issue since you answered all my questions. A big thanks
from tempo.
Related Issues (20)
- Incorrect GMT offset when using FormatOptions with timezone HOT 2
- various mobile ui issues (ios) HOT 3
- [Feature request] Dates comparing HOT 4
- Add full range of same{Unit} functions. HOT 3
- Feature Request: setXxx
- Incorrect formatting between local DST boundaries
- Generate exports size table for docs HOT 2
- Bugfix deviceTZ undefined case error HOT 3
- Unnecessary code in bundles HOT 5
- Are there any plans to support timezone formats like +-HH:mm in the parse function?
- Feature Request: Difference between datetimes HOT 1
- format YYYY-MM returns YYYY-M HOT 3
- yearStart and yearEnd may need to be added to types - v0.1.15 HOT 2
- Feature request: weekNumber HOT 8
- Feature request: `differenceInMilliseconds` / `differenceInSeconds` / `differenceInMinutes` / etc. HOT 1
- FeatureReuet: Support for timezone format +-HH:mm in format token. HOT 1
- Filtering out year still includes comma HOT 2
- Invalid offset error for +0000 HOT 2
- Optional argument in `is*` functions HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tempo.