Checker Methods
isBefore()
Signature
isBefore(other: ChronosInput, unit?: TimeUnit, weekStartsOn?: Enumerate<7>): boolean
Parameters
other
: Date to compareunit
: Comparison unitweekStartsOn
: Week start day (from0-6
) (default: 0)
Return Type
boolean
- Whether date is before
Example
new Chronos('2025-01-01').isBefore('2025-02-01'); // true
isAfter()
Signature
isAfter(other: ChronosInput, unit?: TimeUnit, weekStartsOn?: Enumerate<7>): boolean
Parameters
other
: Date to compareunit
: Comparison unitweekStartsOn
: Week start day (from0-6
) (default: 0)
Return Type
boolean
- Whether date is after
Example
new Chronos('2025-02-01').isAfter('2025-01-01'); // true
isSame()
Signature
isSame(other: ChronosInput, unit?: TimeUnit, weekStartsOn?: Enumerate<7>): boolean
Parameters
other
: Date to compareunit
: Comparison unitweekStartsOn
: Week start day (from0-6
) (default: 0)
Return Type
boolean
- Whether dates match
Example
new Chronos('2025-01-15').isSame('2025-01-15', 'day'); // true
isBetween()
Signature
isBetween(
start: ChronosInput,
end: ChronosInput,
inclusive?: '[]' | '[)' | '(]' | '()'
): boolean
Parameters
start
: Range startend
: Range endinclusive
: Range inclusivity (default: '()')
Return Type
boolean
- Whether date is in range
Example
new Chronos('2025-01-15').isBetween('2025-01-01', '2025-01-31'); // true
isToday()
This method is provided by relativeTimePlugin
. You must register it using Chronos.use(relativeTimePlugin)
before calling .isToday()
. Once registered, all Chronos instances will have access to the .isToday()
method.
Signature
isToday(): boolean
Return Type
boolean
- Whether date is today
Example
import { Chronos } from 'nhb-toolbox';
import { relativeTimePlugin } from 'nhb-toolbox/plugins/relativeTimePlugin';
Chronos.use(relativeTimePlugin);
new Chronos().isToday(); // true
isTomorrow()
This method is provided by relativeTimePlugin
. You must register it using Chronos.use(relativeTimePlugin)
before calling .isTomorrow()
. Once registered, all Chronos instances will have access to the .isTomorrow()
method.
Signature
isTomorrow(): boolean
Return Type
boolean
- Whether date is tomorrow
Example
import { Chronos } from 'nhb-toolbox';
import { relativeTimePlugin } from 'nhb-toolbox/plugins/relativeTimePlugin';
Chronos.use(relativeTimePlugin);
new Chronos().add(1, 'day').isTomorrow(); // true
isYesterday()
This method is provided by relativeTimePlugin
. You must register it using Chronos.use(relativeTimePlugin)
before calling .isYesterday()
. Once registered, all Chronos instances will have access to the .isYesterday()
method.
Signature
isYesterday(): boolean
Return Type
boolean
- Whether date is yesterday
Example
import { Chronos } from 'nhb-toolbox';
import { relativeTimePlugin } from 'nhb-toolbox/plugins/relativeTimePlugin';
Chronos.use(relativeTimePlugin);
new Chronos().subtract(1, 'day').isYesterday(); // true
isWeekend()
This method is provided by businessPlugin
. You must register it using Chronos.use(businessPlugin)
before calling .isWeekend()
. Once registered, all Chronos instances will have access to the .isWeekend()
method.
Signature
isWeekend(weekStartsOn?: Enumerate<7>, weekendLength?: 1 | 2): boolean
Parameters
weekStartsOn
: Week start day (from0-6
) (default: 0)weekendLength
: Weekend days (default: 2)
Return Type
boolean
- Whether weekend
Example
import { Chronos } from 'nhb-toolbox';
import { businessPlugin } from 'nhb-toolbox/plugins/businessPlugin';
Chronos.use(businessPlugin);
new Chronos('2025-01-15').isWeekend(); // true (Sunday)
isWorkday()
This method is provided by businessPlugin
. You must register it using Chronos.use(businessPlugin)
before calling .isWorkday()
. Once registered, all Chronos instances will have access to the .isWorkday()
method.
Signature
isWorkday(weekStartsOn?: Enumerate<7>, weekendLength?: 1 | 2): boolean
Parameters
weekStartsOn
: Week start day (from0-6
) (default: 0)weekendLength
: Weekend days (default: 2)
Return Type
boolean
- Whether workday
Example
import { Chronos } from 'nhb-toolbox';
import { businessPlugin } from 'nhb-toolbox/plugins/businessPlugin';
Chronos.use(businessPlugin);
new Chronos('2025-01-16').isWorkday(); // true (Monday)
isBusinessHour()
This method is provided by businessPlugin
. You must register it using Chronos.use(businessPlugin)
before calling .isBusinessHour()
. Once registered, all Chronos instances will have access to the .isBusinessHour()
method.
Signature
isBusinessHour(options?: BusinessHourOptions): boolean
Parameters
options
:Options to configure business hour
Options Type Definitions
interface BusinessHourOptions {
/** - Optional starting hour of business time (0–23). Defaults to `9` (9 AM). */
businessStartHour?: Enumerate<24>;
/**- Optional ending hour of business time (0–23). Defaults to `17` (5 PM). */
businessEndHour?: Enumerate<24>;
/** - Optional day the week starts on (0–6). Default is `0` (Sunday). */
weekStartsOn?: Enumerate<7>;
/**- Optional weekend length (1 or 2). Default is `2`.*/
weekendLength?: 1 | 2;
}
Return Type
boolean
- Whether business hour
Example
import { Chronos } from 'nhb-toolbox';
import { businessPlugin } from 'nhb-toolbox/plugins/businessPlugin';
Chronos.use(businessPlugin);
new Chronos('2025-01-16T10:00:00').isBusinessHour(); // true
isPalindromeDate()
This method is provided by palindromePlugin
. You must register it using Chronos.use(palindromePlugin)
before calling .isPalindromeDate()
. Once registered, all Chronos instances will have access to the .isPalindromeDate()
method.
Signature
isPalindromeDate(shortYear?: boolean): boolean
Parameters
shortYear
: Use 2-digit year (default: false)
Return Type
boolean
- Whether palindrome date
Example
import { palindromePlugin } from 'nhb-toolbox/plugins/palindromePlugin';
Chronos.use(palindromePlugin);
new Chronos('2020-02-02').isPalindromeDate(); // true
isDST()
Signature
isDST(): boolean
Return Type
boolean
- Whether daylight saving time
Notes
- Uses system timezone
Example
new Chronos('2025-07-01').isDST(); // true (in northern hemisphere)
isFirstDayOfMonth()
Signature
isFirstDayOfMonth(): boolean
Return Type
boolean
- Whether first day
Example
new Chronos('2025-01-01').isFirstDayOfMonth(); // true
isLastDayOfMonth()
Signature
isLastDayOfMonth(): boolean
Return Type
boolean
- Whether last day
Example
new Chronos('2025-01-31').isLastDayOfMonth(); // true
isLeapYear()
-
A year is a leap year if it is divisible by 4.
-
However, years divisible by 100 are not leap years unless they are also divisible by 400.
-
For example:
2000
,2400
→ leap years ✅1900
,2100
→ not leap years ❌
Signature
isLeapYear(year?: number): boolean
Parameters
year
(optional): The year to check. If omitted, the method uses the year from the current Chronos
instance.
Return Value
boolean
— Returns true
if the year is a leap year, otherwise false
.
Example Usage
new Chronos().isLeapYear(2024); // true
new Chronos('2025-05-29').isLeapYear(); // false