Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
@internationalized/date
Advanced tools
Internationalized calendar and date manipulation utilities
@internationalized/date is a JavaScript library that provides utilities for handling dates and times in an internationalized manner. It offers a range of functionalities including date manipulation, formatting, and parsing, all with support for various locales and calendars.
Date Manipulation
This feature allows you to manipulate dates by adding or subtracting days, months, or years. The code sample demonstrates how to add 5 days to a given date.
const { CalendarDate, addDays } = require('@internationalized/date');
const date = new CalendarDate(2023, 10, 5);
const newDate = addDays(date, 5);
console.log(newDate); // Outputs: CalendarDate { year: 2023, month: 10, day: 10 }
Date Formatting
This feature provides utilities to format dates according to different locales. The code sample shows how to format a date in the 'en-US' locale.
const { CalendarDate, DateFormatter } = require('@internationalized/date');
const date = new CalendarDate(2023, 10, 5);
const formatter = new DateFormatter('en-US');
console.log(formatter.format(date)); // Outputs: 10/5/2023
Date Parsing
This feature allows you to parse date strings into date objects according to different locales. The code sample demonstrates parsing a date string in the 'en-US' locale.
const { DateFormatter } = require('@internationalized/date');
const formatter = new DateFormatter('en-US');
const date = formatter.parse('10/5/2023');
console.log(date); // Outputs: CalendarDate { year: 2023, month: 10, day: 5 }
Support for Multiple Calendars
This feature provides support for multiple calendar systems. The code sample shows how to create a date object using the Japanese calendar.
const { CalendarDate, JapaneseCalendar } = require('@internationalized/date');
const date = new CalendarDate(2023, 10, 5, new JapaneseCalendar());
console.log(date); // Outputs: CalendarDate { year: 2023, month: 10, day: 5, calendar: JapaneseCalendar }
Moment.js is a widely-used library for parsing, validating, manipulating, and formatting dates. It offers extensive support for date manipulation and formatting but lacks built-in support for multiple calendar systems and locales compared to @internationalized/date.
date-fns is a modern JavaScript date utility library that provides a comprehensive set of functions for date manipulation and formatting. It is modular and tree-shakeable, making it a lightweight alternative to Moment.js. However, it does not offer the same level of internationalization and calendar support as @internationalized/date.
Luxon is a modern library for working with dates and times in JavaScript. It is built on top of the native JavaScript DateTime API and provides a more comprehensive and easier-to-use interface. Luxon offers good support for internationalization but does not support multiple calendar systems like @internationalized/date.
This package is part of react-spectrum. See the repo for more details.
FAQs
Internationalized calendar, date, and time manipulation utilities
The npm package @internationalized/date receives a total of 1,475,352 weekly downloads. As such, @internationalized/date popularity was classified as popular.
We found that @internationalized/date demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.