@cityssm/utils-datetime 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/{dateIntegerToDate.d.ts → functions/dateIntegerToDate.d.ts} +0 -1
- package/{dateIntegerToDate.js → functions/dateIntegerToDate.js} +5 -0
- package/{dateIntegerToDate.ts → functions/dateIntegerToDate.ts} +0 -5
- package/functions/dateIntegerToString.d.ts +3 -0
- package/{dateIntegerToString.js → functions/dateIntegerToString.js} +5 -0
- package/{dateIntegerToString.ts → functions/dateIntegerToString.ts} +3 -6
- package/functions/dateStringToDate.d.ts +7 -0
- package/{dateStringToDate.js → functions/dateStringToDate.js} +6 -0
- package/functions/dateStringToInteger.d.ts +2 -0
- package/{dateStringToInteger.js → functions/dateStringToInteger.js} +7 -0
- package/{dateStringToInteger.ts → functions/dateStringToInteger.ts} +7 -1
- package/{dateToInteger.d.ts → functions/dateToInteger.d.ts} +0 -1
- package/{dateToInteger.js → functions/dateToInteger.js} +5 -0
- package/{dateToInteger.ts → functions/dateToInteger.ts} +0 -2
- package/functions/dateToString.d.ts +3 -0
- package/{dateToString.js → functions/dateToString.js} +5 -0
- package/{dateToString.ts → functions/dateToString.ts} +1 -5
- package/{dateToTimeInteger.js → functions/dateToTimeInteger.js} +5 -0
- package/functions/dateToTimePeriodString.d.ts +3 -0
- package/{dateToTimePeriodString.js → functions/dateToTimePeriodString.js} +5 -0
- package/{dateToTimePeriodString.ts → functions/dateToTimePeriodString.ts} +1 -5
- package/functions/dateToTimeString.d.ts +3 -0
- package/{dateToTimeString.js → functions/dateToTimeString.js} +5 -0
- package/{dateToTimeString.ts → functions/dateToTimeString.ts} +1 -5
- package/functions/isSameDay.d.ts +7 -0
- package/functions/isSameDay.js +11 -0
- package/functions/isSameDay.ts +13 -0
- package/functions/isValidDateInteger.d.ts +6 -0
- package/{isValidDateInteger.js → functions/isValidDateInteger.js} +5 -0
- package/functions/isValidDateString.d.ts +7 -0
- package/{isValidDateString.js → functions/isValidDateString.js} +5 -0
- package/{isValidDateString.ts → functions/isValidDateString.ts} +1 -1
- package/functions/isValidTimeInteger.d.ts +6 -0
- package/{isValidTimeInteger.js → functions/isValidTimeInteger.js} +5 -0
- package/functions/isValidTimeString.d.ts +7 -0
- package/{isValidTimeString.js → functions/isValidTimeString.js} +5 -0
- package/{isValidTimeString.ts → functions/isValidTimeString.ts} +1 -1
- package/{timeIntegerToPeriodString.d.ts → functions/timeIntegerToPeriodString.d.ts} +1 -1
- package/{timeIntegerToPeriodString.js → functions/timeIntegerToPeriodString.js} +6 -0
- package/{timeIntegerToPeriodString.ts → functions/timeIntegerToPeriodString.ts} +3 -2
- package/functions/timeIntegerToString.d.ts +7 -0
- package/{timeIntegerToString.js → functions/timeIntegerToString.js} +5 -0
- package/{timeIntegerToString.ts → functions/timeIntegerToString.ts} +1 -1
- package/functions/timeStringToInteger.d.ts +2 -0
- package/functions/timeStringToInteger.js +17 -0
- package/{timeStringToInteger.ts → functions/timeStringToInteger.ts} +10 -0
- package/index.d.ts +41 -38
- package/index.js +40 -37
- package/index.ts +43 -65
- package/package.json +42 -38
- package/{dateTimeTypes.d.ts → types.d.ts} +9 -0
- package/CODE_OF_CONDUCT.md +0 -140
- package/CONTRIBUTING.md +0 -33
- package/SECURITY.md +0 -15
- package/dateIntegerToString.d.ts +0 -4
- package/dateStringToDate.d.ts +0 -1
- package/dateStringToInteger.d.ts +0 -1
- package/dateToString.d.ts +0 -4
- package/dateToTimePeriodString.d.ts +0 -4
- package/dateToTimeString.d.ts +0 -4
- package/isValidDateInteger.d.ts +0 -1
- package/isValidDateString.d.ts +0 -2
- package/isValidTimeInteger.d.ts +0 -1
- package/isValidTimeString.d.ts +0 -2
- package/timeIntegerToString.d.ts +0 -2
- package/timeStringToInteger.d.ts +0 -1
- package/timeStringToInteger.js +0 -7
- /package/{dateStringToDate.ts → functions/dateStringToDate.ts} +0 -0
- /package/{dateToTimeInteger.d.ts → functions/dateToTimeInteger.d.ts} +0 -0
- /package/{dateToTimeInteger.ts → functions/dateToTimeInteger.ts} +0 -0
- /package/{isValidDateInteger.ts → functions/isValidDateInteger.ts} +0 -0
- /package/{isValidTimeInteger.ts → functions/isValidTimeInteger.ts} +0 -0
- /package/{dateTimeTypes.js → types.js} +0 -0
- /package/{dateTimeTypes.ts → types.ts} +0 -0
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@cityssm/utils-datetime)
|
|
4
4
|
[](https://app.deepsource.com/gh/cityssm/node-utils-datetime/)
|
|
5
|
-
[](https://codeclimate.com/github/cityssm/node-utils-datetime/maintainability)
|
|
6
5
|
[](https://codecov.io/gh/cityssm/node-utils-datetime)
|
|
7
6
|
|
|
8
7
|
Date time utilities for Node.js applications.
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export declare function dateIntegerToDate<D extends number | undefined | null, T extends number | undefined | null>(dateInteger: D, timeInteger?: T): Date | undefined;
|
|
2
1
|
export declare function dateIntegerToDate(dateInteger: number, timeInteger?: number): Date | undefined;
|
|
3
2
|
export declare function dateIntegerToDate(dateInteger: undefined | null, timeInteger?: undefined | null): undefined;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { isValidDateInteger } from './isValidDateInteger.js';
|
|
2
2
|
import { isValidTimeInteger } from './isValidTimeInteger.js';
|
|
3
|
+
/**
|
|
4
|
+
* @param dateInteger - A number representing a date (ex. 20241231)
|
|
5
|
+
* @param timeInteger - A number representing a time (ex. 2359)
|
|
6
|
+
* @returns - A Date object (ex. '2024-12-31 23:59')
|
|
7
|
+
*/
|
|
3
8
|
export function dateIntegerToDate(dateInteger, timeInteger = 0) {
|
|
4
9
|
if (!isValidDateInteger(dateInteger) || !isValidTimeInteger(timeInteger)) {
|
|
5
10
|
return undefined;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { isValidDateInteger } from './isValidDateInteger.js'
|
|
2
2
|
import { isValidTimeInteger } from './isValidTimeInteger.js'
|
|
3
3
|
|
|
4
|
-
export function dateIntegerToDate<
|
|
5
|
-
D extends number | undefined | null,
|
|
6
|
-
T extends number | undefined | null
|
|
7
|
-
>(dateInteger: D, timeInteger?: T): Date | undefined
|
|
8
|
-
|
|
9
4
|
export function dateIntegerToDate(
|
|
10
5
|
dateInteger: number,
|
|
11
6
|
timeInteger?: number
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { dateIntegerToDate } from './dateIntegerToDate.js';
|
|
2
2
|
import { dateToString } from './dateToString.js';
|
|
3
3
|
import { isValidDateInteger } from './isValidDateInteger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Formats a date number as a string.
|
|
6
|
+
* @param dateInteger - A number representing a date.
|
|
7
|
+
* @returns - A string representing a date.
|
|
8
|
+
*/
|
|
4
9
|
export function dateIntegerToString(dateInteger) {
|
|
5
10
|
if (!isValidDateInteger(dateInteger)) {
|
|
6
11
|
return '';
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
+
import type { DateString } from '../types.js'
|
|
2
|
+
|
|
1
3
|
import { dateIntegerToDate } from './dateIntegerToDate.js'
|
|
2
|
-
import type { DateString } from './dateTimeTypes.js'
|
|
3
4
|
import { dateToString } from './dateToString.js'
|
|
4
5
|
import { isValidDateInteger } from './isValidDateInteger.js'
|
|
5
6
|
|
|
6
|
-
export function dateIntegerToString<D extends number | undefined | null>(
|
|
7
|
-
dateInteger: D
|
|
8
|
-
): DateString | ''
|
|
9
|
-
|
|
10
7
|
export function dateIntegerToString(dateInteger: number): DateString | ''
|
|
11
8
|
export function dateIntegerToString(dateInteger: null | undefined | 0): ''
|
|
12
9
|
|
|
@@ -22,5 +19,5 @@ export function dateIntegerToString(
|
|
|
22
19
|
return ''
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
return dateToString(dateIntegerToDate(dateInteger))
|
|
22
|
+
return dateToString(dateIntegerToDate(dateInteger) as Date)
|
|
26
23
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a string date and time as a JavaScript Date object.
|
|
3
|
+
* @param dateString - A string representing a date.
|
|
4
|
+
* @param timeString - A string representing a time.
|
|
5
|
+
* @returns - A JavaScript Date object.
|
|
6
|
+
*/
|
|
7
|
+
export declare function dateStringToDate(dateString: string, timeString?: string): Date | undefined;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { isValidDateString } from './isValidDateString.js';
|
|
2
2
|
import { isValidTimeString } from './isValidTimeString.js';
|
|
3
|
+
/**
|
|
4
|
+
* Formats a string date and time as a JavaScript Date object.
|
|
5
|
+
* @param dateString - A string representing a date.
|
|
6
|
+
* @param timeString - A string representing a time.
|
|
7
|
+
* @returns - A JavaScript Date object.
|
|
8
|
+
*/
|
|
3
9
|
export function dateStringToDate(dateString, timeString = '00:00') {
|
|
4
10
|
if (!isValidDateString(dateString) || !isValidTimeString(timeString)) {
|
|
5
11
|
return undefined;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { dateStringToDate } from './dateStringToDate.js';
|
|
2
2
|
import { dateToInteger } from './dateToInteger.js';
|
|
3
3
|
import { isValidDateString } from './isValidDateString.js';
|
|
4
|
+
// export function dateStringToInteger(dateString: Omit<string, DateString> | undefined): undefined
|
|
5
|
+
/**
|
|
6
|
+
* Formats a date string as a number.
|
|
7
|
+
* @param dateString - A date formatted as a string (ex. '2024-12-31')
|
|
8
|
+
* @returns - A number representing a date.
|
|
9
|
+
*/
|
|
4
10
|
export function dateStringToInteger(dateString) {
|
|
5
11
|
if (!isValidDateString(dateString)) {
|
|
6
12
|
return undefined;
|
|
7
13
|
}
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
8
15
|
return dateToInteger(dateStringToDate(dateString));
|
|
9
16
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type { DateString } from '../types.js'
|
|
2
|
+
|
|
1
3
|
import { dateStringToDate } from './dateStringToDate.js'
|
|
2
4
|
import { dateToInteger } from './dateToInteger.js'
|
|
3
5
|
import { isValidDateString } from './isValidDateString.js'
|
|
4
6
|
|
|
7
|
+
export function dateStringToInteger(dateString: DateString): number
|
|
8
|
+
// export function dateStringToInteger(dateString: Omit<string, DateString> | undefined): undefined
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* Formats a date string as a number.
|
|
7
12
|
* @param dateString - A date formatted as a string (ex. '2024-12-31')
|
|
@@ -12,5 +17,6 @@ export function dateStringToInteger(dateString: string): number | undefined {
|
|
|
12
17
|
return undefined
|
|
13
18
|
}
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
21
|
+
return dateToInteger(dateStringToDate(dateString) as Date)
|
|
16
22
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type { DateString } from '
|
|
2
|
-
|
|
3
|
-
export function dateToString<D extends Date | undefined>(
|
|
4
|
-
dateObject: D
|
|
5
|
-
): DateString | ''
|
|
1
|
+
import type { DateString } from '../types.js'
|
|
6
2
|
|
|
7
3
|
export function dateToString(dateObject: Date): DateString
|
|
8
4
|
export function dateToString(dateObject: undefined): ''
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a JavaScript Date as a time period string.
|
|
3
|
+
* @param dateObject - A JavaScript Date object.
|
|
4
|
+
* @returns - A time string formatted with the time period (ex. 1:23 a.m.)
|
|
5
|
+
*/
|
|
1
6
|
export function dateToTimePeriodString(dateObject) {
|
|
2
7
|
if (dateObject === undefined) {
|
|
3
8
|
return '';
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type { TimePeriodString } from '
|
|
2
|
-
|
|
3
|
-
export function dateToTimePeriodString<D extends Date | undefined>(
|
|
4
|
-
dateObject: D
|
|
5
|
-
): TimePeriodString | ''
|
|
1
|
+
import type { TimePeriodString } from '../types.js'
|
|
6
2
|
|
|
7
3
|
export function dateToTimePeriodString(dateObject: Date): TimePeriodString
|
|
8
4
|
export function dateToTimePeriodString(dateObject: undefined): ''
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type { TimeString } from '
|
|
2
|
-
|
|
3
|
-
export function dateToTimeString<D extends Date | undefined>(
|
|
4
|
-
dateObject: D
|
|
5
|
-
): TimeString | ''
|
|
1
|
+
import type { TimeString } from '../types.js'
|
|
6
2
|
|
|
7
3
|
export function dateToTimeString(dateObject: Date): TimeString
|
|
8
4
|
export function dateToTimeString(dateObject: undefined): ''
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if two dates are on the same day, ignoring the time.
|
|
3
|
+
* @param date1 The first date to compare.
|
|
4
|
+
* @param date2 The second date to compare.
|
|
5
|
+
* @returns `true` if the dates are on the same day, `false` otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isSameDay(date1: Date, date2: Date): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if two dates are on the same day, ignoring the time.
|
|
3
|
+
* @param date1 The first date to compare.
|
|
4
|
+
* @param date2 The second date to compare.
|
|
5
|
+
* @returns `true` if the dates are on the same day, `false` otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export function isSameDay(date1, date2) {
|
|
8
|
+
return (date1.getFullYear() === date2.getFullYear() &&
|
|
9
|
+
date1.getMonth() === date2.getMonth() &&
|
|
10
|
+
date1.getDate() === date2.getDate());
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if two dates are on the same day, ignoring the time.
|
|
3
|
+
* @param date1 The first date to compare.
|
|
4
|
+
* @param date2 The second date to compare.
|
|
5
|
+
* @returns `true` if the dates are on the same day, `false` otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export function isSameDay(date1: Date, date2: Date): boolean {
|
|
8
|
+
return (
|
|
9
|
+
date1.getFullYear() === date2.getFullYear() &&
|
|
10
|
+
date1.getMonth() === date2.getMonth() &&
|
|
11
|
+
date1.getDate() === date2.getDate()
|
|
12
|
+
)
|
|
13
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a number is a valid date number.
|
|
3
|
+
* @param possibleDateInteger - A possible date number
|
|
4
|
+
* @returns - True if the possible date integer is valid.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isValidDateInteger(possibleDateInteger: unknown): possibleDateInteger is number;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a number is a valid date number.
|
|
3
|
+
* @param possibleDateInteger - A possible date number
|
|
4
|
+
* @returns - True if the possible date integer is valid.
|
|
5
|
+
*/
|
|
1
6
|
export function isValidDateInteger(possibleDateInteger) {
|
|
2
7
|
return (typeof possibleDateInteger === 'number' &&
|
|
3
8
|
possibleDateInteger >= 101 &&
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DateString } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a string is a valid date string.
|
|
4
|
+
* @param possibleDateString - A possible date string
|
|
5
|
+
* @returns - True when the possible date string is valid
|
|
6
|
+
*/
|
|
7
|
+
export declare function isValidDateString(possibleDateString: unknown): possibleDateString is DateString;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
const dateStringRegex = /^\d{4}-[01]\d-[0-3]\d$/;
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a string is a valid date string.
|
|
4
|
+
* @param possibleDateString - A possible date string
|
|
5
|
+
* @returns - True when the possible date string is valid
|
|
6
|
+
*/
|
|
2
7
|
export function isValidDateString(possibleDateString) {
|
|
3
8
|
return (typeof possibleDateString === 'string' &&
|
|
4
9
|
(possibleDateString ?? '').length === 10 &&
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a number is a valid time number.
|
|
3
|
+
* @param possibleTimeInteger - A possible time number
|
|
4
|
+
* @returns - True if the possible time integer is valid.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isValidTimeInteger(possibleTimeInteger: unknown): possibleTimeInteger is number;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a number is a valid time number.
|
|
3
|
+
* @param possibleTimeInteger - A possible time number
|
|
4
|
+
* @returns - True if the possible time integer is valid.
|
|
5
|
+
*/
|
|
1
6
|
export function isValidTimeInteger(possibleTimeInteger) {
|
|
2
7
|
return (typeof possibleTimeInteger === 'number' &&
|
|
3
8
|
possibleTimeInteger >= 0 &&
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TimeString } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a string is a valid time string.
|
|
4
|
+
* @param possibleTimeString - A possible time string.
|
|
5
|
+
* @returns - True when the possible time string is valid.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isValidTimeString(possibleTimeString: unknown): possibleTimeString is TimeString;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
const timeStringRegex = /^[01]\d:[0-5]\d$/;
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a string is a valid time string.
|
|
4
|
+
* @param possibleTimeString - A possible time string.
|
|
5
|
+
* @returns - True when the possible time string is valid.
|
|
6
|
+
*/
|
|
2
7
|
export function isValidTimeString(possibleTimeString) {
|
|
3
8
|
return (typeof possibleTimeString === 'string' &&
|
|
4
9
|
(possibleTimeString ?? '').length === 5 &&
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { TimePeriodString } from '
|
|
1
|
+
import type { TimePeriodString } from '../types.js';
|
|
2
2
|
export declare function timeIntegerToPeriodString(timeInteger: number): TimePeriodString;
|
|
3
3
|
export declare function timeIntegerToPeriodString(timeInteger: undefined | null): '';
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { dateIntegerToDate } from './dateIntegerToDate.js';
|
|
2
2
|
import { dateToTimePeriodString } from './dateToTimePeriodString.js';
|
|
3
|
+
/**
|
|
4
|
+
* Formats a time represented as a number as a string.
|
|
5
|
+
* @param timeInteger - A number representing a time.
|
|
6
|
+
* @returns - A string representing a time.
|
|
7
|
+
*/
|
|
3
8
|
export function timeIntegerToPeriodString(timeInteger) {
|
|
4
9
|
if (timeInteger === undefined || timeInteger === null) {
|
|
5
10
|
return '';
|
|
6
11
|
}
|
|
12
|
+
// eslint-disable-next-line unicorn/numeric-separators-style
|
|
7
13
|
return dateToTimePeriodString(dateIntegerToDate(19700101, timeInteger));
|
|
8
14
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { TimePeriodString } from '../types.js'
|
|
2
|
+
|
|
1
3
|
import { dateIntegerToDate } from './dateIntegerToDate.js'
|
|
2
|
-
import type { TimePeriodString } from './dateTimeTypes.js'
|
|
3
4
|
import { dateToTimePeriodString } from './dateToTimePeriodString.js'
|
|
4
5
|
|
|
5
6
|
export function timeIntegerToPeriodString(timeInteger: number): TimePeriodString
|
|
@@ -18,5 +19,5 @@ export function timeIntegerToPeriodString(
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
// eslint-disable-next-line unicorn/numeric-separators-style
|
|
21
|
-
return dateToTimePeriodString(dateIntegerToDate(19700101, timeInteger))
|
|
22
|
+
return dateToTimePeriodString(dateIntegerToDate(19700101, timeInteger) as Date)
|
|
22
23
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TimeString } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Formats a number representing a time as a string.
|
|
4
|
+
* @param timeInteger - A number representing a time.
|
|
5
|
+
* @returns - A string representing a time.
|
|
6
|
+
*/
|
|
7
|
+
export declare function timeIntegerToString(timeInteger: number | undefined | null): TimeString;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a number representing a time as a string.
|
|
3
|
+
* @param timeInteger - A number representing a time.
|
|
4
|
+
* @returns - A string representing a time.
|
|
5
|
+
*/
|
|
1
6
|
export function timeIntegerToString(timeInteger) {
|
|
2
7
|
const timeString = `0000${(timeInteger ?? 0).toString()}`.slice(-4);
|
|
3
8
|
return `${timeString.slice(0, 2)}:${timeString.slice(2, 4)}`;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isValidTimeString } from './isValidTimeString.js';
|
|
2
|
+
/*
|
|
3
|
+
export function timeStringToInteger(
|
|
4
|
+
timeString: Omit<string, TimeString> | undefined
|
|
5
|
+
): undefined
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Formats a string representing a time as a number.
|
|
9
|
+
* @param timeString - A string representing a time.
|
|
10
|
+
* @returns - A number representing a time.
|
|
11
|
+
*/
|
|
12
|
+
export function timeStringToInteger(timeString) {
|
|
13
|
+
if (!isValidTimeString(timeString)) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return Number.parseInt(`0${timeString}`.replaceAll(':', ''), 10);
|
|
17
|
+
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
import type { TimeString } from '../types.js'
|
|
2
|
+
|
|
1
3
|
import { isValidTimeString } from './isValidTimeString.js'
|
|
2
4
|
|
|
5
|
+
export function timeStringToInteger(timeString: TimeString): number
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
export function timeStringToInteger(
|
|
9
|
+
timeString: Omit<string, TimeString> | undefined
|
|
10
|
+
): undefined
|
|
11
|
+
*/
|
|
12
|
+
|
|
3
13
|
/**
|
|
4
14
|
* Formats a string representing a time as a number.
|
|
5
15
|
* @param timeString - A string representing a time.
|
package/index.d.ts
CHANGED
|
@@ -1,56 +1,59 @@
|
|
|
1
|
-
import { dateIntegerToDate } from './dateIntegerToDate.js';
|
|
2
|
-
import { dateIntegerToString } from './dateIntegerToString.js';
|
|
3
|
-
import { dateStringToDate } from './dateStringToDate.js';
|
|
4
|
-
import { dateStringToInteger } from './dateStringToInteger.js';
|
|
5
|
-
import { dateToInteger } from './dateToInteger.js';
|
|
6
|
-
import { dateToString } from './dateToString.js';
|
|
7
|
-
import { dateToTimeInteger } from './dateToTimeInteger.js';
|
|
8
|
-
import { dateToTimePeriodString } from './dateToTimePeriodString.js';
|
|
9
|
-
import { dateToTimeString } from './dateToTimeString.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
1
|
+
import { dateIntegerToDate } from './functions/dateIntegerToDate.js';
|
|
2
|
+
import { dateIntegerToString } from './functions/dateIntegerToString.js';
|
|
3
|
+
import { dateStringToDate } from './functions/dateStringToDate.js';
|
|
4
|
+
import { dateStringToInteger } from './functions/dateStringToInteger.js';
|
|
5
|
+
import { dateToInteger } from './functions/dateToInteger.js';
|
|
6
|
+
import { dateToString } from './functions/dateToString.js';
|
|
7
|
+
import { dateToTimeInteger } from './functions/dateToTimeInteger.js';
|
|
8
|
+
import { dateToTimePeriodString } from './functions/dateToTimePeriodString.js';
|
|
9
|
+
import { dateToTimeString } from './functions/dateToTimeString.js';
|
|
10
|
+
import { isSameDay } from './functions/isSameDay.js';
|
|
11
|
+
import { isValidDateInteger } from './functions/isValidDateInteger.js';
|
|
12
|
+
import { isValidDateString } from './functions/isValidDateString.js';
|
|
13
|
+
import { isValidTimeInteger } from './functions/isValidTimeInteger.js';
|
|
14
|
+
import { isValidTimeString } from './functions/isValidTimeString.js';
|
|
15
|
+
import { timeIntegerToPeriodString } from './functions/timeIntegerToPeriodString.js';
|
|
16
|
+
import { timeIntegerToString } from './functions/timeIntegerToString.js';
|
|
17
|
+
import { timeStringToInteger } from './functions/timeStringToInteger.js';
|
|
17
18
|
export declare const months: string[];
|
|
18
19
|
export declare const days: string[];
|
|
19
|
-
export { dateIntegerToDate } from './dateIntegerToDate.js';
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export { dateToTimeInteger } from './dateToTimeInteger.js';
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
20
|
+
export { dateIntegerToDate } from './functions/dateIntegerToDate.js';
|
|
21
|
+
export { dateIntegerToString } from './functions/dateIntegerToString.js';
|
|
22
|
+
export { dateStringToDate } from './functions/dateStringToDate.js';
|
|
23
|
+
export { dateStringToInteger } from './functions/dateStringToInteger.js';
|
|
24
|
+
export { dateToInteger } from './functions/dateToInteger.js';
|
|
25
|
+
export { dateToString } from './functions/dateToString.js';
|
|
26
|
+
export { dateToTimeInteger } from './functions/dateToTimeInteger.js';
|
|
27
|
+
export { dateToTimePeriodString } from './functions/dateToTimePeriodString.js';
|
|
28
|
+
export { dateToTimeString } from './functions/dateToTimeString.js';
|
|
29
|
+
export { isSameDay } from './functions/isSameDay.js';
|
|
30
|
+
export { isValidDateInteger } from './functions/isValidDateInteger.js';
|
|
31
|
+
export { isValidDateString } from './functions/isValidDateString.js';
|
|
32
|
+
export { isValidTimeInteger } from './functions/isValidTimeInteger.js';
|
|
33
|
+
export { isValidTimeString } from './functions/isValidTimeString.js';
|
|
34
|
+
export { timeIntegerToPeriodString } from './functions/timeIntegerToPeriodString.js';
|
|
35
|
+
export { timeIntegerToString } from './functions/timeIntegerToString.js';
|
|
36
|
+
export { timeStringToInteger } from './functions/timeStringToInteger.js';
|
|
36
37
|
declare const _default: {
|
|
37
|
-
months: string[];
|
|
38
|
-
days: string[];
|
|
39
38
|
dateIntegerToDate: typeof dateIntegerToDate;
|
|
40
39
|
dateIntegerToString: typeof dateIntegerToString;
|
|
41
40
|
dateStringToDate: typeof dateStringToDate;
|
|
41
|
+
dateStringToInteger: typeof dateStringToInteger;
|
|
42
42
|
dateToInteger: typeof dateToInteger;
|
|
43
43
|
dateToString: typeof dateToString;
|
|
44
|
-
dateStringToInteger: typeof dateStringToInteger;
|
|
45
44
|
dateToTimeInteger: typeof dateToTimeInteger;
|
|
46
|
-
dateToTimeString: typeof dateToTimeString;
|
|
47
45
|
dateToTimePeriodString: typeof dateToTimePeriodString;
|
|
46
|
+
dateToTimeString: typeof dateToTimeString;
|
|
47
|
+
days: string[];
|
|
48
|
+
isSameDay: typeof isSameDay;
|
|
48
49
|
isValidDateInteger: typeof isValidDateInteger;
|
|
49
50
|
isValidDateString: typeof isValidDateString;
|
|
50
51
|
isValidTimeInteger: typeof isValidTimeInteger;
|
|
51
52
|
isValidTimeString: typeof isValidTimeString;
|
|
52
|
-
|
|
53
|
+
months: string[];
|
|
53
54
|
timeIntegerToPeriodString: typeof timeIntegerToPeriodString;
|
|
55
|
+
timeIntegerToString: typeof timeIntegerToString;
|
|
54
56
|
timeStringToInteger: typeof timeStringToInteger;
|
|
55
57
|
};
|
|
56
58
|
export default _default;
|
|
59
|
+
export type { DateString, TimePeriodString, TimeString } from './types.js';
|