Options
All
  • Public
  • Public/Protected
  • All
Menu

@navikt/sif-common-utils

Index

Enumerations

Interfaces

Type aliases

Variables

Functions

Type aliases

DateDurationMap: {}

Type declaration

  • [isoDate: ISODate]: { hours: string; minutes: string; percentage?: number }
    • hours: string
    • minutes: string
    • Optional percentage?: number
DurationWeekdays: { friday?: Duration; monday?: Duration; thursday?: Duration; tuesday?: Duration; wednesday?: Duration }

Type declaration

ISODate: string

YYYY-MM-DD

ISODateRange: string

YYYY-MM-DD/YYYY-MM-DD

ISODuration: string

PT0H0M - kun timer og minutter

InputDateDurationMap: {}

Type declaration

  • [isoDate: ISODate]: { hours: string | undefined; minutes: string | undefined; percentage?: number }
    • hours: string | undefined
    • minutes: string | undefined
    • Optional percentage?: number
MaybeDateRange: Partial<DateRange>

Variables

dateFormatter: { compact: (date: Date) => string; dateShortMonthYear: (date: Date) => string; day: (date: Date) => string; dayCompactDate: (date: Date) => string; dayDateMonth: (date: Date) => string; dayDateMonthYear: (date: Date) => string; dayDateShortMonth: (date: Date) => string; dayDateShortMonthYear: (date: Date) => string; full: (date: Date) => string } = ...

Type declaration

  • compact: (date: Date) => string
      • (date: Date): string
      • Parameters

        • date: Date

        Returns string

        01.01.2020

  • dateShortMonthYear: (date: Date) => string
      • (date: Date): string
      • Parameters

        • date: Date

        Returns string

        1. jan. 2021
  • day: (date: Date) => string
      • (date: Date): string
      • Parameters

        • date: Date

        Returns string

        fredag

  • dayCompactDate: (date: Date) => string
      • (date: Date): string
      • Parameters

        • date: Date

        Returns string

        fredag 01.01.2021

  • dayDateMonth: (date: Date) => string
      • (date: Date): string
      • Parameters

        • date: Date

        Returns string

        fredag 1. jan.

  • dayDateMonthYear: (date: Date) => string
      • (date: Date): string
      • returnsfredag
        1. januar 2021

        Parameters

        • date: Date

        Returns string

  • dayDateShortMonth: (date: Date) => string
      • (date: Date): string
      • Parameters

        • date: Date

        Returns string

        fredag 1. januar

  • dayDateShortMonthYear: (date: Date) => string
      • (date: Date): string
      • Parameters

        • date: Date

        Returns string

        fredag 1. jan. 2021

  • full: (date: Date) => string
      • (date: Date): string
      • Parameters

        • date: Date

        Returns string

        1. januar 2021
dateRangeUtils: { ISODateRangeToDateRange: (isoDateRange: string) => DateRange; ISODateRangeToISODates: (isoDateRange: string) => { from: string; to: string }; ISODateToISODateRange: (isoDate: string) => string; dateRangeToISODateRange: (dateRange: DateRange) => string; dateRangesCollide: (dateRanges: DateRange[], fromDateCanBeSameAsPreviousToDate?: boolean) => boolean; datesCollideWithDateRanges: (dates: Date[], dateRanges: DateRange[]) => boolean; getDateRangeFromDateRanges: (dateRanges: DateRange[]) => DateRange; getDateRangesBetweenDateRanges: (dateRanges: DateRange[]) => DateRange[]; getMonthDateRange: (date: Date, onlyWeekDays?: boolean) => DateRange; getMonthsInDateRange: (dateRange: DateRange, returnFullMonths?: boolean) => DateRange[]; getNumberOfDaysInDateRange: (dateRange: DateRange, onlyWeekDays?: boolean) => number; getWeekDateRange: (date: Date, onlyWeekDays?: boolean) => DateRange; isDateInDateRange: (date: Date, dateRange: DateRange) => boolean; isDateInMaybeDateRange: (date: Date, dateRange: Partial<DateRange>) => boolean; isDateInsideDateRange: (date: Date, dateRange: DateRange) => boolean; isDateRange: (dateRange: any) => dateRange is DateRange; sortDateRange: (d1: DateRange, d2: DateRange) => number; sortDateRangeByToDate: (d1: DateRange, d2: DateRange) => number } = ...

Type declaration

  • ISODateRangeToDateRange: (isoDateRange: string) => DateRange
      • Converts ISODateRange to DateRange

        Parameters

        • isoDateRange: string

        Returns DateRange

  • ISODateRangeToISODates: (isoDateRange: string) => { from: string; to: string }
      • (isoDateRange: string): { from: string; to: string }
      • Extracts from and to ISODates from ISODateRanges

        Parameters

        • isoDateRange: string

        Returns { from: string; to: string }

        • from: string
        • to: string
  • ISODateToISODateRange: (isoDate: string) => string
      • (isoDate: string): string
      • Return an ISODateRange with the same from and to date

        Parameters

        • isoDate: string

        Returns string

        ISODateRange

  • dateRangeToISODateRange: (dateRange: DateRange) => string
      • Converts dateRange to ISODateRange

        Parameters

        Returns string

  • dateRangesCollide: (dateRanges: DateRange[], fromDateCanBeSameAsPreviousToDate?: boolean) => boolean
      • (dateRanges: DateRange[], fromDateCanBeSameAsPreviousToDate?: boolean): boolean
      • Checks if date ranges spans the same dates

        Parameters

        • dateRanges: DateRange[]
        • fromDateCanBeSameAsPreviousToDate: boolean = false

        Returns boolean

        boolean

  • datesCollideWithDateRanges: (dates: Date[], dateRanges: DateRange[]) => boolean
      • (dates: Date[], dateRanges: DateRange[]): boolean
      • Check if one or more dates are within dateranges

        Parameters

        Returns boolean

        boolean

  • getDateRangeFromDateRanges: (dateRanges: DateRange[]) => DateRange
  • getDateRangesBetweenDateRanges: (dateRanges: DateRange[]) => DateRange[]
      • Returns an array of DateRanges between other @dateRanges

        Parameters

        Returns DateRange[]

        date ranges between @dateRanges

  • getMonthDateRange: (date: Date, onlyWeekDays?: boolean) => DateRange
      • (date: Date, onlyWeekDays?: boolean): DateRange
      • Returns a DateRange for the month which date is a part of.

        Parameters

        • date: Date
        • onlyWeekDays: boolean = false

          Exclude saturday and sunday from dateRange

        Returns DateRange

        DateRange

  • getMonthsInDateRange: (dateRange: DateRange, returnFullMonths?: boolean) => DateRange[]
      • Returns array of DateRange representing the months in @dateRange.

        Parameters

        • dateRange: DateRange
        • returnFullMonths: boolean = false

          Set to return full months, not cap the months by @dateRange

        Returns DateRange[]

        array of DateRange

  • getNumberOfDaysInDateRange: (dateRange: DateRange, onlyWeekDays?: boolean) => number
      • (dateRange: DateRange, onlyWeekDays?: boolean): number
      • Returns number of days within @dateRange

        Parameters

        • dateRange: DateRange
        • onlyWeekDays: boolean = false

        Returns number

  • getWeekDateRange: (date: Date, onlyWeekDays?: boolean) => DateRange
      • (date: Date, onlyWeekDays?: boolean): DateRange
      • Returns a DateRange for the week which date is a part of.

        Parameters

        • date: Date
        • onlyWeekDays: boolean = false

          Exclude saturday and sunday from dateRange

        Returns DateRange

        DateRange

  • isDateInDateRange: (date: Date, dateRange: DateRange) => boolean
      • Check if a date is in a date range, including date range from-date and date range to-date

        Parameters

        Returns boolean

        boolean

  • isDateInMaybeDateRange: (date: Date, dateRange: Partial<DateRange>) => boolean
      • (date: Date, dateRange: Partial<DateRange>): boolean
      • Check if date is within a date range or open dateRange

        Parameters

        Returns boolean

        boolean

  • isDateInsideDateRange: (date: Date, dateRange: DateRange) => boolean
      • Check if a date is inside a date range, excluding date range from-date and date range to-date

        Parameters

        Returns boolean

        boolean

  • isDateRange: (dateRange: any) => dateRange is DateRange
      • Typecheck for DateRange object

        Parameters

        • dateRange: any

        Returns dateRange is DateRange

        boolean

  • sortDateRange: (d1: DateRange, d2: DateRange) => number
  • sortDateRangeByToDate: (d1: DateRange, d2: DateRange) => number
dateToday: Date = ...
dateUtils: { ISODateToDate: (isoDate: string) => Date; dateToISODate: (date: Date) => string; dateToday: Date; getDatesInMonth: (month: Date, onlyWeekDays?: boolean) => Date[]; getFirstOfTwoDates: (date1: Date, date2: Date) => Date; getFirstWeekDayInMonth: (month: Date) => Date; getISOWeekdayFromISODate: (isoDate: string) => number; getLastOfTwoDates: (date1: Date, date2: Date) => Date; getLastWeekDayInMonth: (month: Date) => Date; getYearMonthKey: (date: Date) => string; isDateInDates: (date: Date, dates?: Date[]) => boolean; isDateWeekDay: (date: Date) => boolean } = ...

Type declaration

  • ISODateToDate: (isoDate: string) => Date
      • (isoDate: string): Date
      • Parameters

        • isoDate: string

        Returns Date

  • dateToISODate: (date: Date) => string
      • (date: Date): string
      • Parameters

        • date: Date

        Returns string

  • dateToday: Date
  • getDatesInMonth: (month: Date, onlyWeekDays?: boolean) => Date[]
      • (month: Date, onlyWeekDays?: boolean): Date[]
      • Parameters

        • month: Date
        • onlyWeekDays: boolean = false

        Returns Date[]

  • getFirstOfTwoDates: (date1: Date, date2: Date) => Date
      • (date1: Date, date2: Date): Date
      • Parameters

        • date1: Date
        • date2: Date

        Returns Date

  • getFirstWeekDayInMonth: (month: Date) => Date
      • (month: Date): Date
      • Parameters

        • month: Date

        Returns Date

  • getISOWeekdayFromISODate: (isoDate: string) => number
      • (isoDate: string): number
      • Parameters

        • isoDate: string

        Returns number

  • getLastOfTwoDates: (date1: Date, date2: Date) => Date
      • (date1: Date, date2: Date): Date
      • Parameters

        • date1: Date
        • date2: Date

        Returns Date

  • getLastWeekDayInMonth: (month: Date) => Date
      • (month: Date): Date
      • Parameters

        • month: Date

        Returns Date

  • getYearMonthKey: (date: Date) => string
      • (date: Date): string
      • Parameters

        • date: Date

        Returns string

  • isDateInDates: (date: Date, dates?: Date[]) => boolean
      • (date: Date, dates?: Date[]): boolean
      • Parameters

        • date: Date
        • Optional dates: Date[]

        Returns boolean

  • isDateWeekDay: (date: Date) => boolean
      • (date: Date): boolean
      • Parameters

        • date: Date

        Returns boolean

durationUtils: { ISODurationToDecimalDuration: (isoDuration: string) => undefined | number; ISODurationToDuration: (duration: string) => undefined | Duration; ISODurationToNumberDuration: (duration: string) => undefined | NumberDuration; decimalDurationToDuration: (duration: number) => Duration; decimalDurationToISODuration: (duraction: number) => string; decimalDurationToNumberDuration: (duration: number) => NumberDuration; durationAsNumberDuration: (duration: Partial<Duration>) => NumberDuration; durationIsGreatherThanZero: (duration: undefined | Duration) => boolean; durationIsZero: (duration: NumberDuration | Partial<Duration>) => boolean; durationToDecimalDuration: (duration: NumberDuration | Partial<Duration>) => number; durationToISODuration: (duration: NumberDuration | Partial<Duration>) => string; durationsAreEqual: (duration1?: NumberDuration | Partial<Duration>, duration2?: NumberDuration | Partial<Duration>) => boolean; ensureDuration: (duration: NumberDuration | Partial<Duration>) => Duration; ensureNumberDuration: (duration: Partial<Duration> | Partial<NumberDuration>) => NumberDuration; getDateDurationDiff: (durations1: DateDurationMap, durations2: DateDurationMap) => DateDurationMap; getDateRangeFromDateDurationMap: (dateDurationMap: DateDurationMap) => DateRange; getDatesWithDurationLongerThanZero: (duration: InputDateDurationMap | DateDurationMap) => string[]; getDurationsDiff: (durations1: DateDurationMap, durations2: DateDurationMap) => DateDurationMap; getDurationsInDateRange: (dateDurationMap: DateDurationMap, dateRange: DateRange) => DateDurationMap; getNumberDurationOrUndefined: (duration?: Duration) => undefined | NumberDuration; getPercentageOfDecimalDuration: (decimalDuration: number, percentage: number) => number; getPercentageOfDuration: (duration: Duration, percentage: number) => Duration; getPercentageOfISODuration: (isoDuration: string, percentage: number) => undefined | string; getValidDurations: (durationMap: InputDateDurationMap | DateDurationMap) => DateDurationMap; isValidDuration: (duration: undefined | NumberDuration | Partial<Duration>) => duration is NumberDuration; numberDurationAsDuration: (duration: NumberDuration | Partial<Duration>) => Duration; summarizeDateDurationMap: (durationMap: DateDurationMap) => NumberDuration; summarizeDurations: (durations: (undefined | NumberDuration | Partial<Duration>)[]) => NumberDuration } = ...

Type declaration

Functions

  • ISODateRangeToDateRange(isoDateRange: string): DateRange
  • ISODateRangeToISODates(isoDateRange: string): { from: string; to: string }
  • Extracts from and to ISODates from ISODateRanges

    Parameters

    • isoDateRange: string

    Returns { from: string; to: string }

    • from: string
    • to: string
  • ISODateToDate(isoDate: string): Date
  • ISODateToISODateRange(isoDate: string): string
  • Return an ISODateRange with the same from and to date

    Parameters

    • isoDate: string

    Returns string

    ISODateRange

  • ISODurationToDecimalDuration(isoDuration: string): undefined | number
  • ISODurationToDuration(validDuration: string): Duration
  • ISODurationToMaybeDuration(duration: string): undefined | Duration
  • ISODurationToNumberDuration(duration: string): undefined | NumberDuration
  • dateRangeToISODateRange(dateRange: DateRange): string
  • dateRangesCollide(dateRanges: DateRange[], fromDateCanBeSameAsPreviousToDate?: boolean): boolean
  • Checks if date ranges spans the same dates

    Parameters

    • dateRanges: DateRange[]
    • fromDateCanBeSameAsPreviousToDate: boolean = false

    Returns boolean

    boolean

  • dateToISODate(date: Date): string
  • datesCollideWithDateRanges(dates: Date[], dateRanges: DateRange[]): boolean
  • Check if one or more dates are within dateranges

    Parameters

    Returns boolean

    boolean

  • decimalDurationToDuration(duration: number): Duration
  • decimalDurationToISODuration(duraction: number): string
  • durationIsGreatherThanZero(duration: undefined | Duration): boolean
  • getDatesInDateRange(dateRange: DateRange, onlyWeekDays?: boolean): Date[]
  • Returns an array of all dates within @dateRange, with our without weekends

    Parameters

    • dateRange: DateRange
    • onlyWeekDays: boolean = false

      only include weekdays

    Returns Date[]

    Date[]

  • getDatesInMonth(month: Date, onlyWeekDays?: boolean): Date[]
  • Parameters

    • month: Date
    • onlyWeekDays: boolean = false

    Returns Date[]

  • getDatesInMonthOutsideDateRange(month: Date, dateRange: DateRange): Date[]
  • Gets all dates in @month, not inside @dateRange

    Parameters

    Returns Date[]

    array of dates not within the dateRange

  • getFirstOfTwoDates(date1: Date, date2: Date): Date
  • getFirstWeekDayInMonth(month: Date): Date
  • getFirstWeekdayOnOrAfterDate(date: Date): Date
  • getISODatesInISODateRange(range: string, onlyWeekDays?: boolean): string[]
  • Returns all dates in date range as ISODates, weekends excluded

    Parameters

    • range: string
    • onlyWeekDays: boolean = false

    Returns string[]

  • getISOWeekdayFromISODate(isoDate: string): number
  • getISOWeekdaysFromDurationWeekdays(durationWeekdays: DurationWeekdays): number[]
  • getLastOfTwoDates(date1: Date, date2: Date): Date
  • getLastWeekDayInMonth(month: Date): Date
  • getLastWeekdayOnOrBeforeDate(date: Date): Date
  • getMonthDateRange(date: Date, onlyWeekDays?: boolean): DateRange
  • Returns a DateRange for the month which date is a part of.

    Parameters

    • date: Date
    • onlyWeekDays: boolean = false

      Exclude saturday and sunday from dateRange

    Returns DateRange

    DateRange

  • Returns array of DateRange representing the months in @dateRange.

    Parameters

    • dateRange: DateRange
    • returnFullMonths: boolean = false

      Set to return full months, not cap the months by @dateRange

    Returns DateRange[]

    array of DateRange

  • getNumberOfDaysInDateRange(dateRange: DateRange, onlyWeekDays?: boolean): number
  • getPercentageOfDecimalDuration(decimalDuration: number, percentage: number): number
  • getPercentageOfISODuration(isoDuration: string, percentage: number): undefined | string
  • Parameters

    • isoDuration: string
    • percentage: number

    Returns undefined | string

  • getPositiveNumberValue(value: any): undefined | number | "invalidNumberValue"
  • Parameters

    • value: any

    Returns undefined | number | "invalidNumberValue"

  • getWeekDateRange(date: Date, onlyWeekDays?: boolean): DateRange
  • Returns a DateRange for the week which date is a part of.

    Parameters

    • date: Date
    • onlyWeekDays: boolean = false

      Exclude saturday and sunday from dateRange

    Returns DateRange

    DateRange

  • getWeekFromDate(date: Date, withinSameMonth?: boolean): DateRange
  • getWeekdayDOW(weekday: Weekday): number
  • getWeekdayFromDate(date: Date): undefined | Weekday
  • getWeeksInMonth(month: Date, includeWholeWeeks?: boolean): DateRange[]
  • getYearMonthKey(date: Date): string
  • getYearsInDateRanges(dateRanges: DateRange[]): number[]
  • Returns array with all years defined i the dateRanges from value

    Parameters

    Returns number[]

    array of unique years in dateRange.from

  • isDateInDateRange(date: Date, dateRange: DateRange): boolean
  • Check if a date is in a date range, including date range from-date and date range to-date

    Parameters

    Returns boolean

    boolean

  • isDateInDates(date: Date, dates?: Date[]): boolean
  • Parameters

    • date: Date
    • Optional dates: Date[]

    Returns boolean

  • isDateInMaybeDateRange(date: Date, dateRange: Partial<DateRange>): boolean
  • Check if date is within a date range or open dateRange

    Parameters

    Returns boolean

    boolean

  • isDateInWeekdays(date: Date, weekdays: undefined | Weekday[]): boolean
  • isDateInsideDateRange(date: Date, dateRange: DateRange): boolean
  • Check if a date is inside a date range, excluding date range from-date and date range to-date

    Parameters

    Returns boolean

    boolean

  • isDateRange(dateRange: any): dateRange is DateRange
  • isDateWeekDay(date: Date): boolean
  • nthItemFilter(index: number, nth: number): boolean
  • Parameters

    • index: number
    • nth: number

    Returns boolean

  • sortDateArray(dates: Date[]): Date[]

Generated using TypeDoc