@fkui/date
    Preparing search index...

    Class FDate

    Represents a date (with year, month and day).

    Implements

    Index

    Accessors

    • get day(): number

      Get the day of the month.

      FDate.now().day// => 1-31
      

      Returns number

    • get dayName(): string

      Get the name of the day.

      FDate.now().dayName// => Monday
      

      Returns string

    • get dayNameShort(): string

      Get the short name of the day.

      FDate.now().dayNameShort// => Mon
      

      Returns string

    • get month(): number

      Get the month.

      Months are one-indexed, so January is month 1.

      FDate.now().month()// => 1-12
      

      Returns number

    • get monthName(): string

      Get the name of the month.

      FDate.now().monthName// => January
      

      Returns string

    • get monthNameShort(): string

      Get the short name of the month.

      FDate.now().monthNameShort// => Jan
      

      Returns string

    • get week(): number

      Get the week according to the Swedish locale.

      Returns number

    • get weekDay(): 0 | Weekday

      Get number of the day in a week. Returns Weekday enum. If date is invalid, 0 is returned.

      FDate.now().weekDay// => Weekday.MONDAY / 1
      

      Returns 0 | Weekday

    • get year(): number

      Get the year.

      FDate.now().year()// => 2022
      

      Returns number

    Methods

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

      FDate().addDays(7)// => FDate
      

      Parameters

      • value: number

      Returns FDate

    • Returns a cloned FDate object with a specified amount of months added. Specify a negative amount in order to subtract months.

      FDate().addMonths(7)// => FDate
      

      Parameters

      • value: number

      Returns FDate

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

      FDate().addYears(7)// => FDate
      

      Parameters

      • value: number

      Returns FDate

    • Compares two FDate objects and returns true if they represent the same date.

      Invalid dates always returns false.

      Parameters

      • rhs: string | FDate

        The date to compare with.

      Returns boolean

      true if the dates represent the same date.

    • Returns true if this date is after given date.

      If the dates are the same this function returns false.

      Parameters

      Returns boolean

    • Returns true if this date is before given date.

      If the dates are the same this function returns false.

      Parameters

      Returns boolean

    • This returns a boolean indicating whether the FDate object contains a valid date or not.

      FDate().isValid()// => boolean
      

      Returns boolean

    • To serialize as an ISO8601 string.

      FDate().toJSON() // "2019-01-25"
      

      Returns string

    • Returns a string representation of the date.

      FDate().toString() // "2022-05-04"
      FDate().toString(DateFormat.FULL) // "onsdag 4 maj 2022"
      FDate().toString(DateFormat.LONG) // "4 maj 2022"
      FDate().toString(DateFormat.ISO8601) // "2022-04-20"

      Parameters

      • format: DateFormat = DateFormat.ISO8601

        Format to use.

      Returns string

    • Compares two FDate 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 date.
      • 1 if a beomes after b.

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

      Parameters

      • a: string | FDate

        First date object to compare.

      • b: string | FDate

        Second date object to compare.

      Returns number

      -1, 0 or 1

    • Create FDate from Date.

      FDate.fromDate(new Date())
      

      Parameters

      • value: Date

      Returns FDate

    • Create FDate from ISO8601 string.

      FDate.fromIso("2022-04-20")
      

      Parameters

      • value: string

      Returns FDate

    • Create FDate from year, month, day.

      FDate.fromYearMonthDay(2023, 1, 1) // => 2023-01-01
      FDate.fromYearMonthDay("2023", "01", "01") // => 2023-01-01

      Parameters

      • year: string | number
      • month: string | number
      • day: string | number

      Returns FDate