Date Timer is a simple date timer library written in Typescript. Currently the core is being developed so do not use for production codebases yet.
Use yarn or npm to install date-timer
# Yarn
yarn add date-timer
#npm
npm i date-timer
// ES5
const DateTimer = require('date-timer')
const date = new DateTimer()
// Creates a new date timer object with the current timestamp
// ES6+
import DateTimer from 'date-timer'
const date = new DateTimer()
// Creates a new date timer object with the current timestamp
Most methods in the DateTimer class return the DateTimer object so chaining methods is available
const date = new DateTimer() // 2020-01-01T00:00:00.000Z
date.addYears(2).addMonths(3).addDays(2) // 2022-04-03T00:00:00.000Z
Click to Open
Adds years to the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01
date.addYears(1) // 2021-01-01
Adds months to the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01
date.addMonth(1) // 2020-02-01
Adds weeks to the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01
date.addWeeks(1) // 2020-01-08
Adds days to the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01
date.addDays(1) // 2020-01-02
Adds hours to the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01T00:00:00.000Z
date.addHours(1) // 2020-01-01T01:00:00.000Z
Adds minutes to the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01T00:00:00.000Z
date.addMinutes(1) // 2020-01-01T00:01:00.000Z
Adds seconds to the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01T00:00:00.000Z
date.addSeconds(1) // 2020-01-01T00:00:01.000Z
Adds milliseconds to the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01T00:00:00.000Z
date.addMilliseconds(1) // 2020-01-01T00:00:00.001Z
Subtracts years from the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01
date.subYears(1) // 2019-01-01
Subtracts months from the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01
date.subMonths(1) // 2019-12-01
Subtracts weeks from the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01
date.subWeeks(1) // 2019-12-25
Subtracts days from the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01
date.subDays(1) // 2019-12-31
Subtracts hours from the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01T00:00:00.000Z
date.subHours(1) // 2019-12-31T23:00:00.000Z
Subtracts minutes from the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01T00:00:00.000Z
date.subMinutes(1) // 2019-12-31T23:59:00.000Z
Subtracts seconds from the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01T00:00:00.000Z
date.subSeconds(1) // 2019-12-31T23:59:59.000Z
Subtracts milliseconds from the date. Returns the DateTimer Object.
const date = new DateTimer() // 2020-01-01T00:00:00.000Z
date.subMilliseconds(1) // 2019-12-31T23:59:59.999Z
- Build for web
- Add more comparison methods
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.