Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
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 date math util

Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
967K
-4.78%
Maintainers
1
Weekly downloads
 
Created
Source

Date Arthmetic

A simple object containing some date math utils in the spirit of Moment.js. Unlike Moment this module, returns real date objects, so it isn't chainable.

var dateMath = require('date-arithmetic')

var date = dateMath.month(new Date) 

API

all api methods return a new date. Date objects are never mutated.

Localization

startOfWeek() method returns a number (usually 0-6) indicating the start of the week day. Override this function to specify a a culture specific start day. the default is 0.

Accessors

get and set date part values.

  • dateMath.milliseconds(date, [value])
  • dateMath.seconds(date, [value])
  • dateMath.minutes(date, [value])
  • dateMath.hours(date, [value])
  • dateMath.date(date, [value])
  • dateMath.day(date, [value])
  • dateMath.weekday(date, [value])
  • dateMath.month(date, [value])
  • dateMath.year(date, [value])
  • dateMath.decade(date, [value])
  • dateMath.century(date, [value])

startOf(data, unit)

return a new date with the relevent date parts zero'd out.

dateMath.startOf(new Date, 'day') // -> no time components

Valid unit values are; "second", "minutes", "hours", "day", "week", "month", "year", "decade", "century"

endOf(data, unit)

the opposite of startOf

dateMath.endOf(new Date, 'day') // -> one millisecond before tomorrow

Valid unit values are; "milliseconds", "second", "minutes", "hours", "day", "weekday", "month", "year", "decade", "century".

Math Functions

Arithmetic functions

  • dateMath.add(date, value, unit)
  • dateMath.subtract(date, value, unit)
  • dateMath.eq(dateA, dateB)
  • dateMath.neq(dateA, dateB)
  • dateMath.gte(dateA, dateB)
  • dateMath.gt(dateA, dateB)
  • dateMath.lte(dateA, dateB)
  • dateMath.lt(dateA, dateB)
  • dateMath.inRange(day, min, max, unit)
  • dateMath.min(dateA, dateB, dateN)
  • dateMath.max(dateA, dateB, dateN)

Valid unit values are; "second", "minutes", "hours", "day", "week", "month", "year", "decade", "century"

Keywords

moment

FAQs

Package last updated on 06 Jan 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