interface IDateFunctions {
    now: Date;
    parse: (
        dateString: string,
        formatString: string,
        referenceDate: number | Date,
        options?: {
            firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7;
            locale?: Locale;
            useAdditionalDayOfYearTokens?: boolean;
            useAdditionalWeekYearTokens?: boolean;
            weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
        },
    ) => Date;
    parseISO: (
        argument: string,
        options?: { additionalDigits?: 0 | 1 | 2 },
    ) => Date;
    toAbsolute: (x: string | Date, defValue?: string) => string;
    today: string;
    dateTimeFromSerial(days: number): Date;
    format(dt: Date, fmt?: string): string;
    fromISO(value: string): string;
    fromSerial(days: number): string;
    fromString(
        value: string,
        format?: string | DateFmtEntry[],
        refDate?: Date,
    ): Date;
}

Properties

now: Date

Get the current date and time

Date

parse: (
    dateString: string,
    formatString: string,
    referenceDate: number | Date,
    options?: {
        firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7;
        locale?: Locale;
        useAdditionalDayOfYearTokens?: boolean;
        useAdditionalWeekYearTokens?: boolean;
        weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
    },
) => Date

Parse date from a string

Type declaration

    • (
          dateString: string,
          formatString: string,
          referenceDate: number | Date,
          options?: {
              firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7;
              locale?: Locale;
              useAdditionalDayOfYearTokens?: boolean;
              useAdditionalWeekYearTokens?: boolean;
              weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
          },
      ): Date
    • Parameters

      • dateString: string

        a string with a date value

      • formatString: string

        The date format expected

      • referenceDate: number | Date

        The reference date to handle ambiguity or relative dates

      • Optionaloptions: {
            firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7;
            locale?: Locale;
            useAdditionalDayOfYearTokens?: boolean;
            useAdditionalWeekYearTokens?: boolean;
            weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
        }

        additional parsing options

      Returns Date

      Date

parseISO: (argument: string, options?: { additionalDigits?: 0 | 1 | 2 }) => Date

Parse a date in iso format

Type declaration

    • (argument: string, options?: { additionalDigits?: 0 | 1 | 2 }): Date
    • Parameters

      • argument: string

        value to convert to date

      • Optionaloptions: { additionalDigits?: 0 | 1 | 2 }

      Returns Date

      Date string

toAbsolute: (x: string | Date, defValue?: string) => string

Extra the "Day" of a date object and return it as a string in YYYY-MM-DD format.

Type declaration

    • (x: string | Date, defValue?: string): string
    • Convert a date value to a string containing only the date parts Throws an exception if the input date cannot be parsed.

      Parameters

      • x: string | Date

        Date object or a parseable date string

      • defValue: string = "---"

        Default value to a return if input date is null or undefined

      Returns string

      A string containing a formatted date or the defValue

string

today: string

Get the current date in YYYY-MM-DD format

string

Methods

  • Convert an excel compatible serial to a Date object

    Parameters

    • days: number

      Excel serial value

    Returns Date

    Date

  • Given a string value in ISO format

    Parameters

    • value: string

    Returns string

    string in YYYY-MM-DD foramt

  • convert an excel compatibitl date serial into a string date in the format YYYY-MM-DD

    Parameters

    • days: number

      excel serial value

    Returns string

    string

  • Convert a string value to a date {@see parse}

    Parameters

    • value: string
    • Optionalformat: string | DateFmtEntry[]
    • OptionalrefDate: Date

    Returns Date