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

@types/date-fns

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/date-fns

Stub TypeScript definitions entry for date-fns, which provides its own types definitions

  • 2.6.3
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is @types/date-fns?

@types/date-fns provides TypeScript type definitions for the date-fns library, which is a modern JavaScript date utility library. It offers a wide range of functions for manipulating and formatting dates.

What are @types/date-fns's main functionalities?

Date Formatting

The format function allows you to format dates in various patterns. In this example, the date is formatted to 'yyyy-MM-dd'.

import { format } from 'date-fns';
const formattedDate = format(new Date(2023, 9, 10), 'yyyy-MM-dd');
console.log(formattedDate); // Output: 2023-10-10

Date Comparison

The isAfter and isBefore functions allow you to compare dates. In this example, date1 is compared with date2 to check if it is after or before.

import { isAfter, isBefore } from 'date-fns';
const date1 = new Date(2023, 9, 10);
const date2 = new Date(2023, 9, 11);
console.log(isAfter(date1, date2)); // Output: false
console.log(isBefore(date1, date2)); // Output: true

Date Arithmetic

The addDays and subMonths functions allow you to perform arithmetic operations on dates. In this example, 5 days are added to the date and 1 month is subtracted from the date.

import { addDays, subMonths } from 'date-fns';
const date = new Date(2023, 9, 10);
const newDate1 = addDays(date, 5);
const newDate2 = subMonths(date, 1);
console.log(newDate1); // Output: 2023-10-15
console.log(newDate2); // Output: 2023-09-10

Date Parsing

The parse function allows you to parse a date string into a Date object. In this example, the date string '10-10-2023' is parsed into a Date object.

import { parse } from 'date-fns';
const dateString = '10-10-2023';
const parsedDate = parse(dateString, 'MM-dd-yyyy', new Date());
console.log(parsedDate); // Output: Tue Oct 10 2023 00:00:00 GMT+0000 (Coordinated Universal Time)

Other packages similar to @types/date-fns

FAQs

Package last updated on 23 Oct 2024

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