DEV Community

Zaid Rehman
Zaid Rehman

Posted on

2

Stage 3: Temporal

Provides new standard objects and functions for working with dates and times, solving all previous issues with Date.

Date has been a long-standing pain point in ECMAScript. Temporal, is a global Object that acts as a top-level namespace (like Math), that brings a modern date/time API to the ECMAScript language.
For a detailed look at some of the problems with Date, and the motivations for Temporal, see: Fixing JavaScript Date.

Temporal fixes these problems by:

  • Providing easy-to-use APIs for date and time computations
  • First-class support for all time zones, including DST-safe arithmetic
  • Dealing only with objects representing fixed dates and times
  • Parsing a strictly specified string format
  • Supporting non-Gregorian calendars

Object Relationship
Object Relationship Of Temporal

Code examples

Temporal.Now

Temporal.Now.instant() - get the exact time since Unix epoch
Temporal.Now.timeZone() - get the current system time zone

Temporal.Instant

const instant = Temporal.Instant.from('1969-07-20T20:17Z');
instant.toString();  // => '1969-07-20T20:17:00Z'
instant.epochMilliseconds;  // => -14182980000
Enter fullscreen mode Exit fullscreen mode

Temporal.PlainDate

const date = Temporal.PlainDate.from({ year:  2006, month:  8, day:  24  });  // => 2006-08-24 
date.year;  // => 2006 
date.inLeapYear;  // => false 
date.toString();  // => '2006-08-24'
Enter fullscreen mode Exit fullscreen mode

Cookbook
https://tc39.es/proposal-temporal/docs/cookbook.html

Polyfills
https://www.npmjs.com/package/@js-temporal/polyfill

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️