DateUtils: {
    add(args, date?): Date;
    adjustDate(args, date, direction): Date;
    calculateAge(date): null | number;
    calculateDaysBetween(first, second): number;
    compareDates(a, b, order?): number;
    convertToDate(dateStr): Date;
    copyTimeToDate(fromDate, toDate): Date;
    getAge(birthDate, referenceDate?): number;
    getDaysInMonth(year, month): number;
    getDaysBetweenInclusive(startDate, endDate): number;
    getFirstDayOfMonth(date?): Date;
    getFirstDayOfQuarter(date?): Date;
    getFirstDayOfWeek(date?): Date;
    getFirstDayOfYear(date?): Date;
    getEndOfDay(date?): Date;
    getLastDayOfMonth(date?): Date;
    getLastDayOfQuarter(date?): Date;
    getLastDayOfWeek(date?): Date;
    getLastDayOfYear(date?): Date;
    getQuarter(date?): number;
    getStartOfDay(date?): Date;
    getWeekNumber(date?): number;
    isAfter(date1, date2): boolean;
    isBefore(date1, date2): boolean;
    isDateInThePast(date): boolean;
    isSameDay(date1, date2): boolean;
    isSameTime(date1, date2): boolean;
    isToday(date): boolean;
    isTomorrow(date): boolean;
    isValidDate(date): boolean;
    isWeekday(date): boolean;
    isWeekend(date): boolean;
    isYesterday(date): boolean;
    normalizeDate(date): null | Date;
    subtract(args, date?): Date;
    toLocalISOString(date): string;
    validateTimeUnits(args): void;
} = ...

Type declaration

  • add:function
    • Adds specified time units to a date.

      Parameters

      • args: TimeUnitArgs

        Object containing time units to add

      • date: DateArg = ...

        Date to add to (defaults to current date)

      Returns Date

      New date with added time units

      Throws

      If any time unit is negative

      Example

      DateUtils.add({ days: 7, hours: 2 }); // Add 7 days and 2 hours to now
      DateUtils.add({ months: 1 }, new Date('2023-01-15')); // Add 1 month to specific date
  • adjustDate:function
    • Internal helper for modifying a date by adding or subtracting time units

      Parameters

      • args: TimeUnitArgs

        Object containing time units

      • date: DateArg

        Date to modify

      • direction: -1 | 1

        1 for addition, -1 for subtraction

      Returns Date

      New date with modified time units

  • calculateAge:function
    • Calculates age based on birth date

      Parameters

      • date: null | string | Date

        Birth date to calculate age from

      Returns null | number

      Age in years or null if date is invalid

  • calculateDaysBetween:function
    • Calculates the number of days between two dates

      Parameters

      Returns number

      Number of days between dates

  • compareDates:function
    • Compares two dates and returns the result based on order parameter

      Parameters

      • a: DateArg

        First date to compare

      • b: DateArg

        Second date to compare

      • order: "asc" | "desc" = "asc"

        Sort order ('asc' or 'desc')

      Returns number

      Comparison result (-1, 0, or 1)

  • convertToDate:function
    • Converts various date formats to a Date object

      Parameters

      • dateStr: DateArg

        Date to convert (Date, number, or string)

      Returns Date

      Date object

      Throws

      Error if date string is invalid

  • copyTimeToDate:function
    • Copies time from one date to another

      Parameters

      • fromDate: DateArg

        Source date to copy time from

      • toDate: DateArg

        Target date to copy time to

      Returns Date

      New date with copied time

  • getAge:function
    • Returns the age in years between two dates

      Parameters

      • birthDate: DateArg

        Birth date

      • referenceDate: DateArg = ...

        Reference date (defaults to current date)

      Returns number

      Age in years

  • getDaysInMonth:function
    • Returns the number of days in a given month

      Parameters

      • year: number

        Year to check

      • month: number

        Month to check (0-11)

      Returns number

      Number of days in the month

  • getDaysBetweenInclusive:function
    • Returns the number of days between two dates, inclusive

      Parameters

      Returns number

      Number of days between dates, inclusive

  • getFirstDayOfMonth:function
    • Returns the first day of the month

      Parameters

      • date: DateArg = ...

        Date to get first day of month for (defaults to current date)

      Returns Date

      Date set to first day of month

  • getFirstDayOfQuarter:function
    • Returns the first day of the quarter

      Parameters

      • date: DateArg = ...

        Date to get first day of quarter for (defaults to current date)

      Returns Date

      Date set to first day of quarter

  • getFirstDayOfWeek:function
    • Returns the first day of the week (Sunday)

      Parameters

      • date: DateArg = ...

        Date to get first day of week for (defaults to current date)

      Returns Date

      Date set to first day of week

  • getFirstDayOfYear:function
    • Returns the first day of the year

      Parameters

      • date: DateArg = ...

        Date to get first day of year for (defaults to current date)

      Returns Date

      Date set to first day of year

  • getEndOfDay:function
    • Returns the end of the day (23:59:59.999)

      Parameters

      • Optional date: DateArg

        Date to get end of day for (defaults to current date)

      Returns Date

      Date set to end of day

  • getLastDayOfMonth:function
    • Returns the last day of the month

      Parameters

      • date: DateArg = ...

        Date to get last day of month for (defaults to current date)

      Returns Date

      Date set to last day of month

  • getLastDayOfQuarter:function
    • Returns the last day of the quarter

      Parameters

      • date: DateArg = ...

        Date to get last day of quarter for (defaults to current date)

      Returns Date

      Date set to last day of quarter

  • getLastDayOfWeek:function
    • Returns the last day of the week (Saturday)

      Parameters

      • date: DateArg = ...

        Date to get last day of week for (defaults to current date)

      Returns Date

      Date set to last day of week

  • getLastDayOfYear:function
    • Returns the last day of the year

      Parameters

      • date: DateArg = ...

        Date to get last day of year for (defaults to current date)

      Returns Date

      Date set to last day of year

  • getQuarter:function
    • Returns the quarter (1-4) of the year

      Parameters

      • date: DateArg = ...

        Date to get quarter for (defaults to current date)

      Returns number

      Quarter number

  • getStartOfDay:function
    • Returns the start of the day (00:00:00.000)

      Parameters

      • Optional date: DateArg

        Date to get start of day for (defaults to current date)

      Returns Date

      Date set to start of day

  • getWeekNumber:function
    • Returns the week number of the year (1-53)

      Parameters

      • date: DateArg = ...

        Date to get week number for (defaults to current date)

      Returns number

      Week number

  • isAfter:function
    • Checks if a date is after another date

      Parameters

      • date1: DateArg

        First date to compare

      • date2: DateArg

        Second date to compare

      Returns boolean

      True if date1 is after date2

  • isBefore:function
    • Checks if a date is before another date

      Parameters

      • date1: DateArg

        First date to compare

      • date2: DateArg

        Second date to compare

      Returns boolean

      True if date1 is before date2

  • isDateInThePast:function
    • Checks if a date is in the past

      Parameters

      Returns boolean

      True if date is in the past

  • isSameDay:function
    • Checks if two dates are the same day

      Parameters

      • date1: DateArg

        First date to compare

      • date2: DateArg

        Second date to compare

      Returns boolean

      True if dates are the same day

  • isSameTime:function
    • Checks if two dates have the same time

      Parameters

      • date1: DateArg

        First date to compare

      • date2: DateArg

        Second date to compare

      Returns boolean

      True if dates have the same time

  • isToday:function
    • Checks if a date is today

      Parameters

      Returns boolean

      True if date is today

  • isTomorrow:function
    • Checks if a date is tomorrow

      Parameters

      Returns boolean

      True if date is tomorrow

  • isValidDate:function
    • Checks if a date is valid

      Parameters

      Returns boolean

      True if date is valid

  • isWeekday:function
    • Checks if a date falls on a weekday

      Parameters

      Returns boolean

      True if the date is a weekday

  • isWeekend:function
    • Checks if a date falls on a weekend

      Parameters

      Returns boolean

      True if the date is a weekend

  • isYesterday:function
    • Checks if a date is yesterday

      Parameters

      Returns boolean

      True if date is yesterday

  • normalizeDate:function
    • Normalizes a date to UTC midnight

      Parameters

      Returns null | Date

      Normalized date or null if invalid

  • subtract:function
    • Subtracts specified time units from a date

      Parameters

      • args: TimeUnitArgs

        Object containing time units to subtract

      • date: DateArg = ...

        Date to subtract from (defaults to current date)

      Returns Date

      New date with subtracted time units

      Throws

      Error if any time unit is negative

  • toLocalISOString:function
    • Converts a date to a local ISO string

      Parameters

      • date: Date

        Date to convert

      Returns string

      Local ISO string representation

  • validateTimeUnits:function
    • Validates time unit arguments

      Parameters

      Returns void

      Throws

      Error if any time unit is negative