@fkui/date
    Preparing search index...

    Class FYear

    Represents a year.

    v6.12.0

    Implements

    Index

    Accessors

    • get value(): number

      Get the year as number (four digits)

      FYear.now().value; // => 1999
      

      Returns number

    Methods

    • Returns a new FYear object with a specified amount of years added. Specify a negative amount in order to subtract years.

      FYear().addYears(7); // => FYear
      

      Parameters

      • amount: number

        The amount of years to add to this one.

      Returns FYear

    • Compares two FYear objects and returns true if they represent the same year.

      Invalid dates always returns false.

      Parameters

      • rhs: string | number | FYear

        The year to compare with.

      Returns boolean

      true if the years are the same.

    • Returns true if this year is after given year.

      If the years are the same this function returns false.

      Parameters

      • rhs: string | number | FYear

        The year to compare with.

      Returns boolean

      true if this year is after given year.

    • Returns true if this year is before given year.

      If the years are the same this function returns false.

      Parameters

      • rhs: string | number | FYear

        The year to compare with.

      Returns boolean

      true if this year is before given year.

    • This returns a boolean indicating whether the FYear object contains a valid year or not.

      FYear().isValid(); // => boolean
      

      Returns boolean

    • Returns a new FYear object with the year before this one.

      FYear(2025).previous(); // => FYear { 2024 }
      

      Returns FYear

    • Serializes to a JSON value.

      Returns null | number

    • Returns a string representation of the year.

      Returns string

    • Compares two FYear objects. Returns and integer indicating whenever a comes before or after or is equal to b.

      • -1 if a beomes before b.
      • 0 if a and b are the same year.
      • 1 if a beomes after b.

      If either or both years is invalid the result is undefined behaviour and should not be relied on. Use FYear.isValid to ensure validity first, e.g. myArray.filter(it => it.isValid()) before sorting.

      Parameters

      • a: string | number | FYear

        First year object to compare.

      • b: string | number | FYear

        Second year object to compare.

      Returns number

      -1, 0 or 1

      yearArray.sort(FYear.compare);
      
    • Create FYear from an FDate or Date object.

      Parameters

      • value: Date | FDate

        The date to get year from.

      Returns FYear

      FYear.fromDate(FDate.now());
      FYear.fromDate(new Date());
    • Create FYear from a year (stored as number or string with four digits).

      Parameters

      • value: string | number

        The year to set the FYear object to.

      Returns FYear

      FYear.fromYear(1999);
      FYear.fromYear("1999");