Clamps the given date to the given date range.
Type signature
(min: Date, max: Date) => (date: Date) => Date
Examples
const date = new Date(
"2019-06-15T13:54:33.232Z",
);
const min = new Date(
"2019-02-23T13:54:33.232Z",
);
const max = new Date(
"2019-03-13T13:54:33.232Z",
);
clamp(min, max)(date);
Try in REPL
Questions
- How to clamp a date to the desired date range?
- How to enforce a date to be in a given date range?
TypeScript source • JavaScript source
Clones the given Date object.
Examples
const date = new new Date(
"2019-04-24T13:54:33.232Z",
)();
const cloned = clone(date);
cloned !== date &&
cloned.valueOf() ===
date.valueOf();
Try in REPL
Questions
- How to clone a Date object?
TypeScript source • JavaScript source
Computes a signed difference between two Date objects as milliseconds.
Type signature
(a: Date, b: Date) => number
Examples
dateDiff(
new Date(
"2017-01-01T13:00:00.000Z",
),
new Date(
"2017-01-01T12:00:00.000Z",
),
);
Try in REPL
Questions
- How to compute Date difference?
TypeScript source • JavaScript source
Checks if the given date is between the given date range (inclusive).
Type signature
(from: Date, to: Date) => (date: Date) => boolean
Examples
dateInRange(
new Date(
"2018-06-10T12:00:00.000Z",
),
new Date(
"2018-06-20T12:00:00.000Z",
),
)(
new Date(
"2018-06-15T12:00:00.000Z",
),
);
Try in REPL
Questions
- How to check if a date is within a given date range?
TypeScript source • JavaScript source
Returns a local day range at a particular Date.
Examples
const date = new Date(
"2018-12-31T13:54:33.232Z",
);
dayRange(date);
Try in REPL
Questions
- How to find a date range of a given day?
TypeScript source • JavaScript source
Returns an array of days in a particular months. Number of days in February varies if it is a leap year or not.
Type signature
(leapYear: boolean) => [number, number, number, number, number, number, number, number, number, number, number, number]
Questions
- How to find out how many days are in a particular month?
- How to find out how many days there are in a leap year?
TypeScript source • JavaScript source
Calculates the number of days in a particular year. Varies by the leap year.
Type signature
(year: number) => 366 | 365
Questions
- How many days are in a particular year?
- How many days are in a leap year?
- How many days are in a common year?
TypeScript source • JavaScript source
Displays padded time string.
Type signature
(source: [number, number, number], showSeconds: boolean) => string
Questions
- How to display padded time?
TypeScript source • JavaScript source
Returns a local Date of an end of the day at a particular Date.
Examples
endOfDay(
new Date(
"2018-12-31T13:54:33.232Z",
),
);
Try in REPL
Questions
- How to find a date of an end of a given day?
TypeScript source • JavaScript source
Formats a given date as a simple YYYY-MM-DD string.
Examples
formatDate(
new Date("2019-02-24T01:12:34"),
);
Try in REPL
Questions
- How to render a date in a YYYY-MM-DD format?
TypeScript source • JavaScript source
Formats a given date as a simple YYYY-MM-DD HH:MM(:SS) string.
Type signature
(sourceDate: Date, showSeconds?: boolean) => string
Examples
formatDateTime(
new Date("2019-02-24T01:12:34"),
);
Try in REPL
formatDateTime(
new Date("2019-02-24T01:12:34"),
true,
);
Try in REPL
Questions
- How to render a date in a YYYY-MM-DD HH:MM format?
- How to render a date in a YYYY-MM-DD HH:MM:SS format?
TypeScript source • JavaScript source
Formats a duration in milliseconds to a padded time string.
Type signature
(duration: number, showSeconds?: boolean) => string
Questions
- How to render a formatted duration?
TypeScript source • JavaScript source
Formats a given date as a simple HH:MM(:SS) string.
Type signature
(date: Date, showSeconds?: boolean) => string
Examples
formatTime(
new Date("2019-02-24T01:12:34"),
);
Try in REPL
formatTime(
new Date("2019-02-24T01:12:34"),
true,
);
Try in REPL
Questions
- How to render a date in a HH:MM format?
- How to render a date in a HH:MM:SS format?
TypeScript source • JavaScript source
Converts the given day count to milliseconds.
Questions
- How to find how many milliseconds are in a given number of days?
TypeScript source • JavaScript source
Converts the given hour count to milliseconds.
Type signature
(hours: number) => number
Questions
- How to find how many milliseconds are in a given number of hours?
TypeScript source • JavaScript source
Converts the given minute count to milliseconds.
Type signature
(minutes: number) => number
Questions
- How to find how many milliseconds are in a given number of minutes?
TypeScript source • JavaScript source
Converts the given second count to milliseconds.
Type signature
(seconds: number) => number
Questions
- How to find how many milliseconds are in a given number of seconds?
TypeScript source • JavaScript source
Joins a date-time pair into a date-time string.
Type signature
(date: string, time: string) => string
Examples
joinDateTime(
"2019-01-15",
"13:54:33.232Z",
);
Try in REPL
Questions
- How to join date and time to get ISO-compliant date-time string?
TypeScript source • JavaScript source
Detects if a given year is a leap year.
Type signature
(year: number) => boolean
Questions
- How to find if the given year is a leap year?
TypeScript source • JavaScript source
Parses HH:MM string into hours and minutes.
Type signature
(text?: string) => [number, number]
Questions
- How to parse time string into hours and minutes?
TypeScript source • JavaScript source
Splits a date-time string into a date-time pair.
Type signature
(dateTimeString: string) => [string, string]
Examples
splitDateTime(
"2019-01-15T13:54:33.232Z",
);
Try in REPL
Questions
- How to split ISO-compliant date-time string into a date and time pair?
TypeScript source • JavaScript source
Returns a local Date of a start of the day at a particular Date.
Examples
endOfDay(
new Date(
"2019-01-01T13:54:33.232Z",
),
);
Try in REPL
Questions
- How to find a date of the start of a given day?
TypeScript source • JavaScript source
Subtracts the given number of days from the given Date object.
Type signature
(sourceDate: Date, numberOfDays: number) => Date
Examples
subtractDays(
new Date(
"2019-01-15T13:54:33.232Z",
),
1,
);
Try in REPL
Questions
- How to subtract days from a given date?
TypeScript source • JavaScript source
Extracts padded YYYY-MM-DD date string out of the given date object.
Examples
toDate(
new Date(
"2019-01-15T12:00:00.000Z",
),
);
Try in REPL
Questions
- How to get only the date from a Date object?
TypeScript source • JavaScript source
Converts the given array of values into Dates using the Date constructor.
Type signature
(xs: (string | number | Date)[]) => Date[]
Examples
toDates([
"2019-01-15T13:54:33.232Z",
new Date(
"2019-01-15T13:54:33.232Z",
).valueOf(),
new Date(
"2019-01-15T13:54:33.232Z",
),
]);
Try in REPL
Questions
- How to convert an array of string and timestamps into an array of Date objects?
TypeScript source • JavaScript source
Converts milliseconds into days.
Type signature
(milliseconds: number) => number
Questions
- How to convert milliseconds into days?
TypeScript source • JavaScript source
Converts milliseconds into hours.
Type signature
(milliseconds: number) => number
Questions
- How to convert milliseconds into hours?
TypeScript source • JavaScript source
Returns an ISO-compliant date-time string.
Examples
toISO(
new Date(
"2019-04-24T13:54:33.232Z",
),
);
Try in REPL
Questions
- How to convert Date object to ISO-compliant date string?
TypeScript source • JavaScript source
Converts milliseconds into minutes.
Type signature
(milliseconds: number) => number
Questions
- How to convert milliseconds into minutes?
TypeScript source • JavaScript source
Converts milliseconds into seconds.
Type signature
(milliseconds: number) => number
Questions
- How to convert milliseconds into seconds?
TypeScript source • JavaScript source
Checks if the given date is present and it is valid.
Type signature
(date?: unknown) => boolean
Questions
- How to check if a Date is valid or not?
TypeScript source • JavaScript source