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

date-arithmetic

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date-arithmetic

simple immutable date math util

  • 3.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
364K
decreased by-2.78%
Maintainers
1
Weekly downloads
 
Created

What is date-arithmetic?

The date-arithmetic npm package provides utility functions for performing arithmetic operations on JavaScript Date objects. It allows you to add, subtract, and manipulate dates easily without dealing with the complexities of native Date methods.

What are date-arithmetic's main functionalities?

Add Time

This feature allows you to add a specified amount of time to a date. In this example, we add one week to the current date.

const dateArithmetic = require('date-arithmetic');
const now = new Date();
const nextWeek = dateArithmetic.add(now, 1, 'week');
console.log(nextWeek);

Subtract Time

This feature allows you to subtract a specified amount of time from a date. In this example, we subtract one month from the current date.

const dateArithmetic = require('date-arithmetic');
const now = new Date();
const lastMonth = dateArithmetic.subtract(now, 1, 'month');
console.log(lastMonth);

Difference Between Dates

This feature calculates the difference between two dates in a specified unit of time. In this example, we calculate the difference in days between January 1, 2023, and December 31, 2023.

const dateArithmetic = require('date-arithmetic');
const date1 = new Date(2023, 0, 1);
const date2 = new Date(2023, 11, 31);
const diff = dateArithmetic.diff(date1, date2, 'days');
console.log(diff);

Start of a Unit of Time

This feature returns the start of a specified unit of time for a given date. In this example, we get the start of the current month.

const dateArithmetic = require('date-arithmetic');
const now = new Date();
const startOfMonth = dateArithmetic.startOf(now, 'month');
console.log(startOfMonth);

End of a Unit of Time

This feature returns the end of a specified unit of time for a given date. In this example, we get the end of the current year.

const dateArithmetic = require('date-arithmetic');
const now = new Date();
const endOfYear = dateArithmetic.endOf(now, 'year');
console.log(endOfYear);

Other packages similar to date-arithmetic

Keywords

FAQs

Package last updated on 23 Aug 2015

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