UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.

71 lines 3.6 kB
import type { Enumerate, NumberRange } from '../../number/types'; import type { BusinessHourOptions, Quarter } from '../types'; type MainChronos = typeof import('../Chronos').Chronos; declare module '../Chronos' { interface Chronos { /** * @instance Checks if the current date falls on a weekend. * * @param weekStartsOn Optional day the week starts on (0–6). Default is `0` (Sunday). * @param weekendLength Optional length of the weekend (1 or 2). Default is `2`. * @returns Whether the date is a weekend. * * @description * Weekend is determined based on `weekStartsOn` and `weekendLength`. * * - `weekStartsOn` is a 0-based index (0 = Sunday, 1 = Monday, ..., 6 = Saturday). * - `weekendLength` defines how many days are considered weekend (1 or 2). Default is 2. * If 1, only the last day of the week is treated as weekend. * If 2, the last two days are treated as weekend. */ isWeekend(weekStartsOn?: Enumerate<7>, weekendLength?: 1 | 2): boolean; /** * @instance Checks if the current date is a workday (non-weekend day). * * @param weekStartsOn Optional day the week starts on (0–6). Default is `0` (Sunday). * @param weekendLength Optional length of the weekend (1 or 2). Default is `2`. * @returns Whether the date is a workday. * * @description * Weekends are determined by `weekStartsOn` and `weekendLength`. * * - `weekStartsOn` is a 0-based index (0 = Sunday, 1 = Monday, ..., 6 = Saturday). * - `weekendLength` defines how many days are considered weekend (1 or 2). Default is 2. */ isWorkday(weekStartsOn?: Enumerate<7>, weekendLength?: 1 | 2): boolean; /** * @instance Checks if the current date and time fall within business hours. * * @param options Options to configure business hour * * @returns Whether the current time is within business hours. * * @remarks * * Business hours are typically 9 AM to 5 PM on weekdays. * * Supports standard and overnight business hours. Overnight means `end < start`. * * Example: `businessStartHour = 22`, `businessEndHour = 6` will cover 10 PM to 6 AM next day. * * * *Weekends are determined by `weekStartsOn` and `weekendLength` using the `isWeekend()` method.* * * - Business hours are `[businessStartHour, businessEndHour)`. * - If `weekendLength` is `1`, only the last day of the week is treated as weekend. * - If `weekendLength` is `2`, the last two days are treated as weekend. */ isBusinessHour(options?: BusinessHourOptions): boolean; /** * @instance Returns the academic year based on a typical start in July and end in June. * @returns The academic year in format `YYYY-YYYY`. */ toAcademicYear(): `${number}-${number}`; /** * @instance Returns the fiscal quarter based on custom fiscal year start (defaults to July). * @param startMonth - The fiscal year start month (1-12), default is July (7). * @returns The fiscal quarter (1-4). */ toFiscalQuarter(startMonth?: NumberRange<1, 12>): Quarter; } } /** * Plugin to inject `business` related methods */ export declare const businessPlugin: (ChronosClass: MainChronos) => void; export {}; //# sourceMappingURL=businessPlugin.d.ts.map