Skip to main content

latest
Works with
JSR Score
52%
Published
3 months ago

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;

License

MIT

Add Package

deno add @badosz/holy-time

Import symbol

import * as mod from "@badosz/holy-time";

Add Package

npx jsr add @badosz/holy-time

Import symbol

import * as mod from "@badosz/holy-time";

Add Package

yarn dlx jsr add @badosz/holy-time

Import symbol

import * as mod from "@badosz/holy-time";

Add Package

pnpm dlx jsr add @badosz/holy-time

Import symbol

import * as mod from "@badosz/holy-time";

Add Package

bunx jsr add @badosz/holy-time

Import symbol

import * as mod from "@badosz/holy-time";