# date-arithmetic

> simple date math util

Latest version **4.1.0** (published 2020-01-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install date-arithmetic
pnpm add date-arithmetic
yarn add date-arithmetic
bun add date-arithmetic
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2020-01-02 |
| First published | 2014-08-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/date-arithmetic) |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 28.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 54 |
| Author | Jason Quense @monasticpanic |
| Maintainers | monastic.panic |
| Keywords | moment, date, math |

## Links

- npm: https://www.npmjs.com/package/date-arithmetic
- Repository: https://github.com/jquense/date-math
- Issues: https://github.com/jquense/date-math/issues
- npm.io page: https://npm.io/package/date-arithmetic

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2020-01-02
- 4.0.1 — 2019-06-26
- 4.0.0 — 2019-06-10
- 3.1.0 — 2016-06-03
- 3.0.1 — 2015-08-23
- 3.0.0 — 2015-04-25
- 2.0.0 — 2015-01-06
- 1.0.0 — 2014-08-19

## README

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" `

---
_Source: https://npm.io/package/date-arithmetic · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
