Skip to main content

@terascope/utils / dates

dates

Type Aliases

AdjustDateArgs

AdjustDateArgs: object | object

Source

packages/utils/src/dates.ts:724

Variables

getDurationFunc

const getDurationFunc: object

Type declaration

ISOWeekYears()

ISOWeekYears: (laterDate, earlierDate, options?) => number = differenceInISOWeekYears

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInISOWeekYearsOptionsThe options
Returns

number

businessDays()

businessDays: (laterDate, earlierDate, options?) => number = differenceInBusinessDays

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInBusinessDaysOptionsAn object with options
Returns

number

calendarDays()

calendarDays: (laterDate, earlierDate, options?) => number = differenceInCalendarDays

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInCalendarDaysOptionsThe options object
Returns

number

calendarISOWeekYears()

calendarISOWeekYears: (laterDate, earlierDate, options?) => number = differenceInCalendarISOWeekYears

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInCalendarISOWeekYearsOptionsAn object with options
Returns

number

calendarMonths()

calendarMonths: (laterDate, earlierDate, options?) => number = differenceInCalendarMonths

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInCalendarMonthsOptionsAn object with options
Returns

number

calendarQuarters()

calendarQuarters: (laterDate, earlierDate, options?) => number = differenceInCalendarQuarters

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInCalendarQuartersOptionsAn object with options
Returns

number

calendarWeeks()

calendarWeeks: (laterDate, earlierDate, options?) => number = differenceInCalendarISOWeeks

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInCalendarISOWeeksOptionsAn object with options
Returns

number

calendarYears()

calendarYears: (laterDate, earlierDate, options?) => number = differenceInCalendarYears

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInCalendarYearsOptionsAn object with options
Returns

number

days()

days: (laterDate, earlierDate, options?) => number = differenceInDays

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInDaysOptionsAn object with options
Returns

number

hours()

hours: (laterDate, earlierDate, options?) => number = differenceInHours

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInHoursOptionsAn object with options.
Returns

number

milliseconds()

milliseconds: (laterDate, earlierDate) => number = differenceInMilliseconds

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
Returns

number

minutes()

minutes: (dateLeft, dateRight, options?) => number = differenceInMinutes

Parameters
ParameterTypeDescription
dateLeftstring | number | DateThe later date
dateRightstring | number | DateThe earlier date
options?DifferenceInMinutesOptionsAn object with options.
Returns

number

months()

months: (laterDate, earlierDate, options?) => number = differenceInMonths

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInMonthsOptionsAn object with options
Returns

number

quarters()

quarters: (laterDate, earlierDate, options?) => number = differenceInQuarters

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInQuartersOptionsAn object with options.
Returns

number

seconds()

seconds: (laterDate, earlierDate, options?) => number = differenceInSeconds

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInSecondsOptionsAn object with options.
Returns

number

weeks()

weeks: (laterDate, earlierDate, options?) => number = differenceInWeeks

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInWeeksOptionsAn object with options
Returns

number

years()

years: (laterDate, earlierDate, options?) => number = differenceInYears

Parameters
ParameterTypeDescription
laterDatestring | number | DateThe later date
earlierDatestring | number | DateThe earlier date
options?DifferenceInYearsOptionsAn object with options
Returns

number

Source

packages/utils/src/dates.ts:553


timezoneOffset

const timezoneOffset: number

Source

packages/utils/src/dates.ts:53

Functions

addToDate()

addToDate(input, args): number

Parameters

ParameterType
inputunknown
argsAdjustDateArgs

Returns

number

Source

packages/utils/src/dates.ts:737


addToDateFP()

addToDateFP(args): (input) => number

Parameters

ParameterType
argsAdjustDateArgs

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:747


formatDateValue()

formatDateValue(value, format): string | number

Format the parsed date value

Parameters

ParameterType
valuenumber | Date | DateTuple
formatundefined | string

Returns

string | number

Source

packages/utils/src/dates.ts:523


getDate()

getDate(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:955


getHours()

getHours(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:945


getMilliseconds()

getMilliseconds(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:922


getMinutes()

getMinutes(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:935


getMonth()

getMonth(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:964


getSeconds()

getSeconds(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:926


getTime()

getTime(val?): number | false

Ensure unix time

Parameters

ParameterType
val?DateInputTypes

Returns

number | false

Source

packages/utils/src/dates.ts:248


getTimeBetween()

getTimeBetween(input, args): string | number

Parameters

ParameterType
inputunknown
argsGetTimeBetweenArgs

Returns

string | number

Source

packages/utils/src/dates.ts:573


getTimeBetweenFP()

getTimeBetweenFP(args): (input) => string | number

A functional version of getTimeBetween

Parameters

ParameterType
argsGetTimeBetweenArgs

Returns

Function

Parameters
ParameterType
inputunknown
Returns

string | number

Source

packages/utils/src/dates.ts:611


getTimezoneOffset()

getTimezoneOffset(input, timezone): number

Given a date and timezone, it will return the offset from UTC in minutes. This is more accurate than timezoneToOffset as it can better account for day lights saving time

Parameters

ParameterType
inputunknown
timezonestring

Returns

number

Source

packages/utils/src/dates.ts:820


getTimezoneOffsetFP()

getTimezoneOffsetFP(timezone): (input) => number

Given a timezone, it will return a function that will take in dates that will be converted the offset in minutes. This is more accurate than timezoneToOffset as it can better account for day lights saving time

Parameters

ParameterType
timezonestring

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:834


getUTCDate()

getUTCDate(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:950


getUTCHours()

getUTCHours(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:940


getUTCMinutes()

getUTCMinutes(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:930


getUTCMonth()

getUTCMonth(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:960


getUTCYear()

getUTCYear(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:968


getUnixTime()

getUnixTime(val?): number | false

Parameters

ParameterType
val?DateInputTypes

Returns

number | false

Source

packages/utils/src/dates.ts:255


getValidDate()

getValidDate(val, relativeNow): Date | false

Coerces value into a valid date, returns false if it is invalid. Has added support for converting from date math (i.e. now+1h, now-1m, now+2d/y, 2021-01-01||+2d)

Parameters

ParameterType
valunknown
relativeNowDate

Returns

Date | false

Source

packages/utils/src/dates.ts:121


getValidDateOrNumberOrThrow()

getValidDateOrNumberOrThrow(val): Date | number

Returns a valid date or throws, {@see getValidDate}

Parameters

ParameterType
valunknown

Returns

Date | number

Source

packages/utils/src/dates.ts:231


getValidDateOrThrow()

getValidDateOrThrow(val): Date

Returns a valid date or throws, {@see getValidDate}

Parameters

ParameterType
valunknown

Returns

Date

Source

packages/utils/src/dates.ts:158


getValidDateWithTimezone()

getValidDateWithTimezone(val, getUTC): Date | false

Returns a valid date with the timezone applied {@see getValidDate}

Parameters

ParameterTypeDefault value
valunknownundefined
getUTCbooleanfalse

Returns

Date | false

Source

packages/utils/src/dates.ts:220


getValidDateWithTimezoneOrThrow()

getValidDateWithTimezoneOrThrow(val, getUTC): Date

Returns a valid date with the timezone applied or throws{@see getValidDate}

Parameters

ParameterTypeDefault value
valunknownundefined
getUTCbooleanfalse

Returns

Date

Source

packages/utils/src/dates.ts:209


getYear()

getYear(input): number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/dates.ts:972


isAfter()

isAfter(input, date): boolean

Parameters

ParameterType
inputunknown
dateDateInputTypes

Returns

boolean

Source

packages/utils/src/dates.ts:780


isBefore()

isBefore(input, date): boolean

Parameters

ParameterType
inputunknown
dateDateInputTypes

Returns

boolean

Source

packages/utils/src/dates.ts:769


isBetween()

isBetween(input, args): boolean

Parameters

ParameterType
inputunknown
argsobject
args.endDateInputTypes
args.startDateInputTypes

Returns

boolean

Source

packages/utils/src/dates.ts:791


isDateTuple()

isDateTuple(input): input is DateTuple

Verify if an input is a Date Tuple

Parameters

ParameterType
inputunknown

Returns

input is DateTuple

Source

packages/utils/src/dates.ts:363


isFriday()

isFriday(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:652


isFuture()

isFuture(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:682


isISO8601()

isISO8601(input): input is string

Checks to see if an input is a ISO 8601 date

Parameters

ParameterType
inputunknown

Returns

input is string

Source

packages/utils/src/dates.ts:283


isLeapYear()

isLeapYear(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:696


isMonday()

isMonday(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:624


isPast()

isPast(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:689


isSaturday()

isSaturday(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:659


isSunday()

isSunday(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:617


isThursday()

isThursday(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:645


isToday()

isToday(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:710


isTomorrow()

isTomorrow(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:703


isTuesday()

isTuesday(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:631


isUnixTime()

isUnixTime(input, allowBefore1970): input is number

Checks to see if an input is a unix time

Parameters

ParameterTypeDefault value
inputunknownundefined
allowBefore1970booleantrue

Returns

input is number

Source

packages/utils/src/dates.ts:264


isUnixTimeFP()

isUnixTimeFP(allowBefore1970?): (input) => input is number

A functional version of isUnixTime

Parameters

ParameterType
allowBefore1970?boolean

Returns

Function

Parameters
ParameterType
inputunknown
Returns

input is number

Source

packages/utils/src/dates.ts:274


isValidDate()

isValidDate(val): boolean

A simplified implementation of moment(new Date(val)).isValid()

Parameters

ParameterType
valunknown

Returns

boolean

Source

packages/utils/src/dates.ts:71


isValidDateInstance()

isValidDateInstance(val): val is Date

Parameters

ParameterType
valunknown

Returns

val is Date

Source

packages/utils/src/dates.ts:242


isWednesday()

isWednesday(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:638


isWeekday()

isWeekday(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:666


isWeekend()

isWeekend(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:674


isYesterday()

isYesterday(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/dates.ts:717


makeISODate()

makeISODate(value?): string

A helper function for making an ISODate string

Parameters

ParameterType
value?null | string | number | Date | DateTuple

Returns

string

Source

packages/utils/src/dates.ts:58


parseCustomDateFormat()

parseCustomDateFormat(value, format, referenceDate): number

Parameters

ParameterType
valueunknown
formatstring
referenceDateDate

Returns

number

Source

packages/utils/src/dates.ts:471


parseDateValue()

parseDateValue(value, format, referenceDate): number

Parse a date value (that has already been validated) and return the epoch millis time.

Parameters

ParameterType
valueunknown
formatundefined | string
referenceDateDate

Returns

number

Source

packages/utils/src/dates.ts:496


setDate()

setDate(date): (input) => number

Parameters

ParameterType
datenumber

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:889


setHours()

setHours(hours): (input) => number

Parameters

ParameterType
hoursnumber

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:878


setMilliseconds()

setMilliseconds(ms): (input) => number

Parameters

ParameterType
msnumber

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:845


setMinutes()

setMinutes(minutes): (input) => number

Parameters

ParameterType
minutesnumber

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:867


setMonth()

setMonth(month): (input) => number

Parameters

ParameterType
monthnumber

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:900


setSeconds()

setSeconds(seconds): (input) => number

Parameters

ParameterType
secondsnumber

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:856


setTimezone()

setTimezone(input, timezone): DateTuple

Set the timezone offset of a date, returns a date tuple

Parameters

ParameterType
inputunknown
timezonestring | number

Returns

DateTuple

Source

packages/utils/src/dates.ts:336


setTimezoneFP()

setTimezoneFP(timezone): (input) => DateTuple

A curried version of setTimezone

Parameters

ParameterType
timezonestring | number

Returns

Function

Parameters
ParameterType
inputunknown
Returns

DateTuple

Source

packages/utils/src/dates.ts:344


setYear()

setYear(year): (input) => number

Parameters

ParameterType
yearnumber

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:911


subtractFromDate()

subtractFromDate(input, args): number

Parameters

ParameterType
inputunknown
argsAdjustDateArgs

Returns

number

Source

packages/utils/src/dates.ts:753


subtractFromDateFP()

subtractFromDateFP(args): (input) => number

Parameters

ParameterType
argsAdjustDateArgs

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:763


timezoneToOffset()

timezoneToOffset(timezone): number

Given a timezone, it will return the minutes of its offset from UTC time

Parameters

ParameterType
timezoneunknown

Returns

number

Source

packages/utils/src/dates.ts:809


toEpochMSOrThrow()

toEpochMSOrThrow(input): DateTuple | number

Will convert a date to its epoch millisecond format or throw if invalid

Parameters

ParameterType
inputunknown

Returns

DateTuple | number

Source

packages/utils/src/dates.ts:977


toHumanTime()

toHumanTime(ms): string

converts smaller than a week milliseconds to human readable time

Parameters

ParameterType
msnumber

Returns

string

Source

packages/utils/src/dates.ts:451


toISO8601()

toISO8601(value): string

Convert a value to an ISO 8601 date string. This should be used over makeISODate

Parameters

ParameterType
valueunknown

Returns

string

Source

packages/utils/src/dates.ts:293


toTimeZone()

toTimeZone(val, timezone): DateTuple | null

Parameters

ParameterType
valunknown
timezonestring

Returns

DateTuple | null

Source

packages/utils/src/dates.ts:166


toTimeZoneUsingLocation()

toTimeZoneUsingLocation(val, location): null | DateTuple

Parameters

ParameterType
valunknown
locationunknown

Returns

null | DateTuple

Source

packages/utils/src/dates.ts:180


toTimeZoneUsingLocationFP()

toTimeZoneUsingLocationFP(location): (val) => null | DateTuple

Parameters

ParameterType
locationunknown

Returns

Function

Parameters
ParameterType
valunknown
Returns

null | DateTuple

Source

packages/utils/src/dates.ts:186


trackTimeout()

trackTimeout(timeoutMs): () => number | false

track a timeout to see if it expires

Parameters

ParameterType
timeoutMsnumber

Returns

Function

a function that will returns false if the time elapsed

Returns

number | false

Source

packages/utils/src/dates.ts:438


trimISODateSegment()

trimISODateSegment(segment): (input) => number

Returns a function to trim the ISO 8601 date segment useful for creating yearly, monthly, daily or hourly dates

Parameters

ParameterType
segmentISO8601DateSegment

Returns

Function

Parameters
ParameterType
inputunknown
Returns

number

Source

packages/utils/src/dates.ts:378