@cityssm/utils-datetime 1.1.2 → 1.1.3
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/dateIntegerToDate.ts +3 -3
- package/dateIntegerToString.ts +2 -2
- package/dateStringToDate.ts +4 -4
- package/dateStringToInteger.ts +2 -2
- package/dateToInteger.js +1 -1
- package/dateToInteger.ts +2 -2
- package/dateToString.ts +2 -2
- package/dateToTimeInteger.ts +2 -2
- package/dateToTimePeriodString.ts +2 -2
- package/dateToTimeString.ts +2 -2
- package/isValidDateInteger.ts +2 -2
- package/isValidDateString.ts +2 -2
- package/isValidTimeInteger.ts +2 -2
- package/isValidTimeString.ts +2 -2
- package/package.json +6 -6
- package/timeIntegerToPeriodString.d.ts +1 -1
- package/timeIntegerToPeriodString.js +1 -1
- package/timeIntegerToPeriodString.ts +4 -4
- package/timeIntegerToString.ts +2 -2
- package/timeStringToInteger.ts +2 -2
package/dateIntegerToDate.ts
CHANGED
|
@@ -17,9 +17,9 @@ export function dateIntegerToDate(
|
|
|
17
17
|
): undefined
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
22
|
-
* @returns
|
|
20
|
+
* @param dateInteger - A number representing a date (ex. 20241231)
|
|
21
|
+
* @param timeInteger - A number representing a time (ex. 2359)
|
|
22
|
+
* @returns - A Date object (ex. '2024-12-31 23:59')
|
|
23
23
|
*/
|
|
24
24
|
export function dateIntegerToDate(
|
|
25
25
|
dateInteger: number | undefined | null,
|
package/dateIntegerToString.ts
CHANGED
|
@@ -12,8 +12,8 @@ export function dateIntegerToString(dateInteger: null | undefined | 0): ''
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Formats a date number as a string.
|
|
15
|
-
* @param
|
|
16
|
-
* @returns
|
|
15
|
+
* @param dateInteger - A number representing a date.
|
|
16
|
+
* @returns - A string representing a date.
|
|
17
17
|
*/
|
|
18
18
|
export function dateIntegerToString(
|
|
19
19
|
dateInteger: number | undefined | null
|
package/dateStringToDate.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { isValidTimeString } from './isValidTimeString.js'
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Formats a string date and time as a JavaScript Date object.
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
6
|
+
* @param dateString - A string representing a date.
|
|
7
|
+
* @param timeString - A string representing a time.
|
|
8
|
+
* @returns - A JavaScript Date object.
|
|
9
9
|
*/
|
|
10
10
|
export function dateStringToDate(
|
|
11
11
|
dateString: string,
|
|
12
|
-
timeString
|
|
12
|
+
timeString = '00:00'
|
|
13
13
|
): Date | undefined {
|
|
14
14
|
if (!isValidDateString(dateString) || !isValidTimeString(timeString)) {
|
|
15
15
|
return undefined
|
package/dateStringToInteger.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { isValidDateString } from './isValidDateString.js'
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Formats a date string as a number.
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
7
|
+
* @param dateString - A date formatted as a string (ex. '2024-12-31')
|
|
8
|
+
* @returns - A number representing a date.
|
|
9
9
|
*/
|
|
10
10
|
export function dateStringToInteger(dateString: string): number | undefined {
|
|
11
11
|
if (!isValidDateString(dateString)) {
|
package/dateToInteger.js
CHANGED
package/dateToInteger.ts
CHANGED
|
@@ -5,8 +5,8 @@ export function dateToInteger(dateObject: undefined): undefined
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Formats a JavaScript Date object as a number.
|
|
8
|
-
* @param
|
|
9
|
-
* @returns
|
|
8
|
+
* @param dateObject - A JavaScript Date object.
|
|
9
|
+
* @returns - A number representing the date.
|
|
10
10
|
*/
|
|
11
11
|
export function dateToInteger(
|
|
12
12
|
dateObject: Date | undefined
|
package/dateToString.ts
CHANGED
|
@@ -9,8 +9,8 @@ export function dateToString(dateObject: undefined): ''
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Formats a JavaScript Date object as a date string.
|
|
12
|
-
* @param
|
|
13
|
-
* @returns
|
|
12
|
+
* @param dateObject - A JavaScript Date object
|
|
13
|
+
* @returns - A date string.
|
|
14
14
|
*/
|
|
15
15
|
export function dateToString(dateObject: Date | undefined): DateString | '' {
|
|
16
16
|
if (dateObject === undefined) {
|
package/dateToTimeInteger.ts
CHANGED
|
@@ -7,8 +7,8 @@ export function dateToTimeInteger(dateObject: undefined): undefined
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Formats the time in a JavaScript Date as a number.
|
|
10
|
-
* @param
|
|
11
|
-
* @returns
|
|
10
|
+
* @param dateObject - A JavaScript Date object.
|
|
11
|
+
* @returns - A number representing a time.
|
|
12
12
|
*/
|
|
13
13
|
export function dateToTimeInteger(
|
|
14
14
|
dateObject: Date | undefined
|
|
@@ -9,8 +9,8 @@ export function dateToTimePeriodString(dateObject: undefined): ''
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Formats a JavaScript Date as a time period string.
|
|
12
|
-
* @param
|
|
13
|
-
* @returns
|
|
12
|
+
* @param dateObject - A JavaScript Date object.
|
|
13
|
+
* @returns - A time string formatted with the time period (ex. 1:23 a.m.)
|
|
14
14
|
*/
|
|
15
15
|
export function dateToTimePeriodString(
|
|
16
16
|
dateObject: Date | undefined
|
package/dateToTimeString.ts
CHANGED
|
@@ -9,8 +9,8 @@ export function dateToTimeString(dateObject: undefined): ''
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Formats a JavaScript Date object as a time string.
|
|
12
|
-
* @param
|
|
13
|
-
* @returns
|
|
12
|
+
* @param dateObject - A JavaScript Date object.
|
|
13
|
+
* @returns - A string representing the time.
|
|
14
14
|
*/
|
|
15
15
|
export function dateToTimeString(
|
|
16
16
|
dateObject: Date | undefined
|
package/isValidDateInteger.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Determines if a number is a valid date number.
|
|
3
|
-
* @param
|
|
4
|
-
* @returns
|
|
3
|
+
* @param possibleDateInteger - A possible date number
|
|
4
|
+
* @returns - True if the possible date integer is valid.
|
|
5
5
|
*/
|
|
6
6
|
export function isValidDateInteger(
|
|
7
7
|
possibleDateInteger: unknown
|
package/isValidDateString.ts
CHANGED
|
@@ -4,8 +4,8 @@ const dateStringRegex = /^\d{4}-[01]\d-[0-3]\d$/
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Determines if a string is a valid date string.
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
7
|
+
* @param possibleDateString - A possible date string
|
|
8
|
+
* @returns - True when the possible date string is valid
|
|
9
9
|
*/
|
|
10
10
|
export function isValidDateString(
|
|
11
11
|
possibleDateString: unknown
|
package/isValidTimeInteger.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Determines if a number is a valid time number.
|
|
3
|
-
* @param
|
|
4
|
-
* @returns
|
|
3
|
+
* @param possibleTimeInteger - A possible time number
|
|
4
|
+
* @returns - True if the possible time integer is valid.
|
|
5
5
|
*/
|
|
6
6
|
export function isValidTimeInteger(
|
|
7
7
|
possibleTimeInteger: unknown
|
package/isValidTimeString.ts
CHANGED
|
@@ -4,8 +4,8 @@ const timeStringRegex = /^[01]\d:[0-5]\d$/
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Determines if a string is a valid time string.
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
7
|
+
* @param possibleTimeString - A possible time string.
|
|
8
|
+
* @returns - True when the possible time string is valid.
|
|
9
9
|
*/
|
|
10
10
|
export function isValidTimeString(
|
|
11
11
|
possibleTimeString: unknown
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityssm/utils-datetime",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Date time utilities for Node.js applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"test": "test"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"test": "
|
|
29
|
-
"coverage": "c8
|
|
28
|
+
"test": "node --test",
|
|
29
|
+
"coverage": "c8 --reporter=lcov --reporter=text --reporter=text-summary node --test"
|
|
30
30
|
},
|
|
31
31
|
"author": "The Corporation of the City of Sault Ste. Marie",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
34
|
+
"@types/node": "^20.14.5",
|
|
35
|
+
"eslint-config-cityssm": "^5.0.0",
|
|
36
|
+
"prettier-config-cityssm": "^1.0.0"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { TimePeriodString } from './dateTimeTypes.js';
|
|
2
|
-
export declare function timeIntegerToPeriodString(timeInteger?: number): TimePeriodString | '';
|
|
2
|
+
export declare function timeIntegerToPeriodString(timeInteger?: number | undefined | null): TimePeriodString | '';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dateIntegerToDate } from './dateIntegerToDate.js';
|
|
2
2
|
import { dateToTimePeriodString } from './dateToTimePeriodString.js';
|
|
3
3
|
export function timeIntegerToPeriodString(timeInteger = 0) {
|
|
4
|
-
return dateToTimePeriodString(dateIntegerToDate(19700101, timeInteger));
|
|
4
|
+
return dateToTimePeriodString(dateIntegerToDate(19700101, timeInteger ?? 0));
|
|
5
5
|
}
|
|
@@ -4,12 +4,12 @@ import { dateToTimePeriodString } from './dateToTimePeriodString.js'
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Formats a time represented as a number as a string.
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
7
|
+
* @param timeInteger - A number representing a time.
|
|
8
|
+
* @returns - A string representing a time.
|
|
9
9
|
*/
|
|
10
10
|
export function timeIntegerToPeriodString(
|
|
11
|
-
timeInteger: number = 0
|
|
11
|
+
timeInteger: number | undefined | null = 0
|
|
12
12
|
): TimePeriodString | '' {
|
|
13
13
|
// eslint-disable-next-line unicorn/numeric-separators-style
|
|
14
|
-
return dateToTimePeriodString(dateIntegerToDate(19700101, timeInteger))
|
|
14
|
+
return dateToTimePeriodString(dateIntegerToDate(19700101, timeInteger ?? 0))
|
|
15
15
|
}
|
package/timeIntegerToString.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { TimeString } from './dateTimeTypes.js'
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Formats a number representing a time as a string.
|
|
5
|
-
* @param
|
|
6
|
-
* @returns
|
|
5
|
+
* @param timeInteger - A number representing a time.
|
|
6
|
+
* @returns - A string representing a time.
|
|
7
7
|
*/
|
|
8
8
|
export function timeIntegerToString(
|
|
9
9
|
timeInteger: number | undefined | null
|
package/timeStringToInteger.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { isValidTimeString } from './isValidTimeString.js'
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Formats a string representing a time as a number.
|
|
5
|
-
* @param
|
|
6
|
-
* @returns
|
|
5
|
+
* @param timeString - A string representing a time.
|
|
6
|
+
* @returns - A number representing a time.
|
|
7
7
|
*/
|
|
8
8
|
export function timeStringToInteger(timeString: string): number | undefined {
|
|
9
9
|
if (!isValidTimeString(timeString)) {
|