Temporal API Cheatsheet: Quick Guide to new JS API Temporal API Cheatsheet: Quick Guide to new JS API
The Temporal API is still a proposal and so not recommended for production use. However, hopefully this post and the cheatsheet will help you try it out on your side projects. If that’s something you will find useful, read on.
Then there are methods to get and set the day, hour and so on for the the new date:
You can set that date in a single step:
date.setFullYear(2023,0,31). Manipulation is another story though. Let’s say you want an account to expire at 23:59 a month from today. You can work out that date and time using these methods but it is messy and there are edge
cases you need to watch out and test for. The new Temporal API does the heavy lifting here and on
top has ergonomic syntax:
On top the API has methods which make working with time zones easier.
The idea of the Temporal API Cheatsheet was to keep a quick reference list of methods I found useful. For more complex cases I would refer to the official docs. As I discover more methods I will add to it. In fact, it is an open-sourced Astro site, so you can add to it yourself .
The temporal API is not net integrated into ECMA Script so you need to add a polyfill package to you project to use it. TC39 give a couple of choices:
Take a look at the Temporal API Cheatsheet site and try it out when you have a moment!
We have had an introduction to the Temporal API and the cheatsheet. In particular, we saw:
- why the Temporal API exists,
- how you can start using the Temporal API in projects and contribute to the cheatsheet,
- that the API is still a proposal and not recommended for production usage.
I hope you found this article useful and am keen to hear how you will the starter on your own projects as well as possible improvements.
- As the Temporal API is still a proposal, it is not recommended for production use. That said you might want to try it out in side projects just to explore and better understand it.
Have you found the post useful? Would you prefer to see posts on another topic instead? Get in touch with ideas for new posts. Also if you like my writing style, get in touch if I can write some posts for your company site on a consultancy basis. Read on to find ways to get in touch, further below. If you want to support posts similar to this one and can spare a few dollars, euros or pounds, please consider supporting me through Buy me a Coffee.
Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on Twitter and also askRodney on Telegram . Also, see further ways to get in touch with Rodney Lab. I post regularly on Astro as well as SvelteKit. Also subscribe to the newsletter to keep up-to-date with our latest projects.