Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@js-temporal/polyfill

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@js-temporal/polyfill

Polyfill for Tc39 Stage 3 proposal Temporal (https://github.com/tc39/proposal-temporal)

  • 0.4.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27K
decreased by-81.64%
Maintainers
3
Weekly downloads
 
Created

What is @js-temporal/polyfill?

@js-temporal/polyfill is a polyfill for the Temporal API, which is a modern date/time API for JavaScript. It provides a more comprehensive and accurate way to handle dates and times compared to the built-in Date object.

What are @js-temporal/polyfill's main functionalities?

Creating Temporal Objects

This feature allows you to create various Temporal objects such as PlainDateTime, PlainDate, PlainTime, etc. The code sample demonstrates creating a PlainDateTime object representing the current date and time in ISO format.

const { Temporal } = require('@js-temporal/polyfill');
const now = Temporal.Now.plainDateTimeISO();
console.log(now.toString());

Date Arithmetic

Temporal makes it easy to perform date arithmetic. The code sample shows how to add one day to the current date to get tomorrow's date.

const { Temporal } = require('@js-temporal/polyfill');
const today = Temporal.Now.plainDateISO();
const tomorrow = today.add({ days: 1 });
console.log(tomorrow.toString());

Time Zones

Temporal provides robust support for time zones. The code sample demonstrates how to get the current date and time in a specific time zone (America/New_York).

const { Temporal } = require('@js-temporal/polyfill');
const now = Temporal.Now.zonedDateTimeISO();
const timeZone = Temporal.TimeZone.from('America/New_York');
const nyTime = now.withTimeZone(timeZone);
console.log(nyTime.toString());

Duration and Intervals

Temporal allows you to work with durations and intervals. The code sample shows how to calculate the duration between two dates.

const { Temporal } = require('@js-temporal/polyfill');
const start = Temporal.PlainDate.from('2023-01-01');
const end = Temporal.PlainDate.from('2023-12-31');
const duration = end.since(start);
console.log(duration.toString());

Other packages similar to @js-temporal/polyfill

Keywords

FAQs

Package last updated on 17 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc