Class DateValue

Date of a chess game. It can be either partially defined (with the year only, or with the year and month but without day of month), or fully defined (with year, month and day of month).

Constructors

  • Parameters

    • year: number
    • Optionalmonth: number

      If provided, must be between 1 (January) and 12 (December) inclusive.

    • Optionalday: number

      If provided, must be between 1 and the number of days in the corresponding month (thus 31 at most).

    Returns DateValue

  • Construct a DateValue object from a standard JavaScript Date object.

    With this constructor, the type of the returned object is always 'ymd' (see DateValue.type).

    Parameters

    • date: Date

    Returns DateValue

Methods

  • Day in month, valued between 1 and the number of days in the corresponding month (thus 31 at most).

    Returns number

    exception.IllegalArgument if the current type is 'y' or 'ym' (see DateValue.type).

  • Convert the current object into a standard JavaScript Date object.

    If the type of the current object is 'ym', the returned Date object points at the first day of the corresponding month. If the type of the current object is 'y', the returned Date object points at the first day of the corresponding year.

    Returns Date

  • Get the date of the game as a human-readable string (e.g. 'November 1955', 'September 4, 2021').

    Parameters

    • Optionallocales: string | string[]

      Locales to use to generate the result. If undefined, the default locale of the execution environment is used. See Intl documentation for more details.

    Returns string

  • Get the date in a PGN format (e.g. '2022.07.19', '2022.07.??' or '2022.??.??' depending on the type of the current object).

    Returns string

  • Get the date in a compact format (e.g. '2022-07-19', '2022-07-**' or '2022-**-**' depending on the type of the current object).

    Returns string

  • Type of date value:

    • 'y' means that only the year is defined,
    • 'ym' means that the year and the month are defined, but not the day in month,
    • 'ymd' means that the exact day is defined.

    Returns "y" | "ym" | "ymd"

  • Year (e.g. 2022).

    Returns number

  • Parse the given value as a date in PGN format (e.g. '2022.07.19', '2022.07.??' or '2022.??.??').

    Parameters

    • value: string

    Returns undefined | DateValue

    undefined if the value does not represent a valid date.

  • Parse the given value as a date in compact format (e.g. '2022-07-19', '2022-07-**' or '2022-**-**').

    Parameters

    • value: string

    Returns undefined | DateValue

    undefined if the value does not represent a valid date.

  • Whether the given year/month/day would corresponds to a valid date or not.

    Parameters

    • year: number
    • Optionalmonth: number
    • Optionalday: number

    Returns boolean