tomcru / holy-time

Yet another (type-safe) date time library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

holyTime

Holy Time



Yet another (type-safe) date time library

Installation

$ npm install holy-time

OR

$ yarn add holy-time

Examples

import HolyTime from 'holy-time'

HolyTime
  .in(4, 'days')
  .add(2, 'weeks')
  .subtract(4, 'minutes')
  .isWeekend()

HolyTime.between(
  HolyTime.add(HolyTime.startOf('day'), 10_000), 
  HolyTime.now()
)

HolyTime.max(1666224000000, HolyTime.next('year'))

new HolyTime('2022-10-20')
  .isAfter(
    HolyTime.subtract(
      HolyTime.in(4, 'days'), 
      8, 'weeks'
    )
  )

HolyTime
  .duration(2, 'hours')
  .add(30, 'minutes')
  .in('seconds')

Instance Methods

add(amount: number, unit: HumanUnit): this;
subtract(amount: number, unit: HumanUnit): this;

isLeapYear(): boolean;
isWeekend(): boolean;
isAfter(time: TimeResolvable): boolean;
isBefore(time: TimeResolvable): boolean;
isEqual(time: TimeResolvable): boolean;

startOf(unit: IntervalUnit, timeZone?: TimeZone): HolyTime;
endOf(unit: IntervalUnit, timeZone?: TimeZone): HolyTime;
next(unit: IntervalUnit, timeZone?: TimeZone): HolyTime;

getDate(): Date;
getTime(): number;
getISOString(): string;

format(format: string, timeZone?: TimeZone): string;
getRelativeTo(time: TimeResolvable): string;
getRelativeFrom(time: TimeResolvable): string;

Static Methods

now(): HolyTime;
in(amount: number, unit: HumanUnit): HolyTime

add(time: TimeResolvable, amount: number, unit: HumanUnit): HolyTime;
subtract(time: TimeResolvable, amount: number, unit: HumanUnit): HolyTime;

between(timeA: TimeResolvable, timeB: TimeResolvable): number;
since(time: TimeResolvable): number;

isLeapYear(time: TimeResolvable): boolean;
isWeekend(time: TimeResolvable): boolean;
isAfter(timeA: TimeResolvable, timeB: TimeResolvable): boolean;
isBefore(timeA: TimeResolvable, timeB: TimeResolvable): boolean;
isEqual(timeA: TimeResolvable, timeB: TimeResolvable): boolean;

max(...times: TimeResolvable[]): HolyTime;
min(...times: TimeResolvable[]): HolyTime;

startOf(unit: IntervalUnit, time: TimeResolvable, timeZone?: TimeZone): HolyTime;
endOf(unit: IntervalUnit, time: TimeResolvable, timeZone?: TimeZone): HolyTime;
next(unit: IntervalUnit, time: TimeResolvable, timeZone?: TimeZone): HolyTime;

format(time: TimeResolvable, format: string, timeZone?: TimeZone): string;
relativeFromTo(timeA: TimeResolvable, timeB: TimeResolvable): string;

duration(amount: number, unit: HumanUnit): HolyDuration;

Planned

  • .set(unit, value)
  • .get(unit)
  • .toObject()

License

MIT

About

Yet another (type-safe) date time library


Languages

Language:TypeScript 100.0%