4.1.0 • Published 4 years ago

date-arithmetic v4.1.0

Weekly downloads
178,713
License
MIT
Repository
github
Last release
4 years ago

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.

import * as dateMath from 'date-arithmetic'

var date = dateMath.month(new Date)

API

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

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], [firstOfWeek = 0])
  • dateMath.month(date, [value])
  • dateMath.year(date, [value])
  • dateMath.decade(date, [value])
  • dateMath.century(date, [value])

startOf(data, unit, [firstOfWeek = 0])

return a new date with the relevent date parts zero'd out. You only need to provide a firstOfWeek when the unit is 'week'

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

Valid unit values are; "seconds", "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", "seconds", "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, [unit])
  • dateMath.neq(dateA, dateB, [unit])
  • dateMath.gte(dateA, dateB, [unit])
  • dateMath.gt(dateA, dateB, [unit])
  • dateMath.lte(dateA, dateB, [unit])
  • dateMath.lt(dateA, dateB, [unit])
  • dateMath.inRange(day, min, max, unit)
  • dateMath.min(dateA, dateB, dateN)
  • dateMath.max(dateA, dateB, dateN)
  • dateMath.diff(dateA, dateB, unit, asFloat)

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

carbonio-calendars-ui@fadi-saadeldin/react-big-calenderinstant-bookergribovsky-react-big-calendarreact-widgetsfork@everything-registry/sub-chunk-1447optune-react-big-calendarnpm-blacklabel-calendarpps-attendance-calendarmetaboly-react-big-calendarmy-own-fs-big-calendarmy-test-calendarnb-date-rangenbucciarelli-react-big-calendarpublishing-calendarqh-fork-react-big-calendarprivorockij-react-big-calendarprivorockij-react-calendar@cdb/calendar@chroniq/chroniq@chroniq/chroniq-storybook@cicobuff/react-big-calendar@checksub_team/react-widgets@denindka/react-big-calendar@craigmorton/react-big-calendar@cm-iv/react-bigger-calendar@clickonmedia/clickon-react-big-calendar@clickonmedia/react-big-calendar@connerl/react-big-calendarcadence-big-calendarcadence-calendar@davidmh/react-big-calendar@danielmackenzie8/react-widgetschimpdesk-react-big-calendarchroniqwebdoods-react-big-calendar@vietmoney/react-big-calendar@beisen/pps-calendar@beisen/m-calendar@beisen/m-m-calendar@beisen/calendarauchindoun-react-big-calendar@billchenchina/react-big-calendar@atenaganji/arsh-react-big-calendar@atenaganji/react-big-calendar@atenaganji/react-big-calendar-arsh@beisen-platform/calendarbcv-react-big-calendar-fork@brainwayltd/react-big-calendar@b.taranenko/react-big-calendarautomated-rules-calendar@getinsitu/react-big-calendarcitrusbyte-calendarwink-react-big-calendar@veupathdb/componentsubiatar-react-big-calendar@aerotime/react-big-calendar@ahaui/full-calendar@alex_lai/gg-react-big-calendarappdoc-componenttrello-cal@trialspark/react-big-calendar@truehome/react-big-calendar@targetprocess/logs-listcodepilots-react-big-calendarhw-calendarjalali-react-calendarjalali-react-big-calendarjvenusaur-react-big-calendarkyon-react-big-calendarkatoto-big-calendaric-react-big-calendariqatestappivelum-react-widgetsirx-react-big-calendarliu-big-calendarm-ceshi-calendarkandooit_calendarkandooit_schedulerjg-react-big-calendarjhockett-react-big-calendarjnarwold-react-big-calendarmana-calendarleyserplus-react-big-calendarnewsource-react-big-calendarreact-sp-calendarreact-stockwell-calendarreact-touch-big-calendarreact-widgetsreact-widgets-2react-widgets-3react-widgets-binckreact-widgets-editreact-widgets-enhancedreact-widgets-persianreact-widgets-testreact-schedule-calendarreact-scheduler-hcreact-scheduler-smartdatareact-scheduler-theralytics
4.1.0

4 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.1.0

8 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.0.0

9 years ago

1.0.0

10 years ago