GithubHelp home page GithubHelp logo

Comments (2)

justin-schroeder avatar justin-schroeder commented on May 24, 2024

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.

ghiscoding avatar ghiscoding commented on May 24, 2024

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.

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.