@cityssm/utils-datetime 1.3.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/functions/dateIntegerToDate.js +5 -0
- package/functions/dateIntegerToString.js +5 -0
- package/functions/dateStringToDate.d.ts +6 -0
- package/functions/dateStringToDate.js +6 -0
- package/functions/dateStringToInteger.d.ts +0 -1
- package/functions/dateStringToInteger.js +7 -0
- package/functions/dateStringToInteger.ts +2 -1
- package/functions/dateToInteger.js +5 -0
- package/functions/dateToString.js +5 -0
- package/functions/dateToTimeInteger.js +5 -0
- package/functions/dateToTimePeriodString.js +5 -0
- package/functions/dateToTimeString.js +5 -0
- package/functions/isSameDay.d.ts +7 -0
- package/functions/isSameDay.js +11 -0
- package/functions/isSameDay.ts +13 -0
- package/functions/isValidDateInteger.d.ts +5 -0
- package/functions/isValidDateInteger.js +5 -0
- package/functions/isValidDateString.d.ts +5 -0
- package/functions/isValidDateString.js +5 -0
- package/functions/isValidTimeInteger.d.ts +5 -0
- package/functions/isValidTimeInteger.js +5 -0
- package/functions/isValidTimeString.d.ts +5 -0
- package/functions/isValidTimeString.js +5 -0
- package/functions/timeIntegerToPeriodString.js +6 -0
- package/functions/timeIntegerToString.d.ts +5 -0
- package/functions/timeIntegerToString.js +5 -0
- package/functions/timeStringToInteger.d.ts +0 -1
- package/functions/timeStringToInteger.js +10 -0
- package/functions/timeStringToInteger.ts +3 -0
- package/index.d.ts +15 -12
- package/index.js +14 -11
- package/index.ts +17 -39
- package/package.json +42 -37
- package/types.d.ts +9 -0
- package/CODE_OF_CONDUCT.md +0 -140
- package/CONTRIBUTING.md +0 -33
- package/SECURITY.md +0 -15
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,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,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 +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
|
+
*/
|
|
1
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
|
}
|
|
@@ -5,7 +5,7 @@ import { dateToInteger } from './dateToInteger.js'
|
|
|
5
5
|
import { isValidDateString } from './isValidDateString.js'
|
|
6
6
|
|
|
7
7
|
export function dateStringToInteger(dateString: DateString): number
|
|
8
|
-
export function dateStringToInteger(dateString: Omit<string, DateString> | undefined): undefined
|
|
8
|
+
// export function dateStringToInteger(dateString: Omit<string, DateString> | undefined): undefined
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Formats a date string as a number.
|
|
@@ -17,5 +17,6 @@ export function dateStringToInteger(dateString: string): number | undefined {
|
|
|
17
17
|
return undefined
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
20
21
|
return dateToInteger(dateStringToDate(dateString) as Date)
|
|
21
22
|
}
|
|
@@ -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 '';
|
|
@@ -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
|
+
}
|
|
@@ -1 +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
|
+
*/
|
|
1
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 &&
|
|
@@ -1,2 +1,7 @@
|
|
|
1
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
|
+
*/
|
|
2
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 &&
|
|
@@ -1 +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
|
+
*/
|
|
1
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 &&
|
|
@@ -1,2 +1,7 @@
|
|
|
1
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
|
+
*/
|
|
2
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,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,2 +1,7 @@
|
|
|
1
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
|
+
*/
|
|
2
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)}`;
|
|
@@ -1,4 +1,14 @@
|
|
|
1
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
|
+
*/
|
|
2
12
|
export function timeStringToInteger(timeString) {
|
|
3
13
|
if (!isValidTimeString(timeString)) {
|
|
4
14
|
return undefined;
|
|
@@ -3,9 +3,12 @@ import type { TimeString } from '../types.js'
|
|
|
3
3
|
import { isValidTimeString } from './isValidTimeString.js'
|
|
4
4
|
|
|
5
5
|
export function timeStringToInteger(timeString: TimeString): number
|
|
6
|
+
|
|
7
|
+
/*
|
|
6
8
|
export function timeStringToInteger(
|
|
7
9
|
timeString: Omit<string, TimeString> | undefined
|
|
8
10
|
): undefined
|
|
11
|
+
*/
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* Formats a string representing a time as a number.
|
package/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { dateToString } from './functions/dateToString.js';
|
|
|
7
7
|
import { dateToTimeInteger } from './functions/dateToTimeInteger.js';
|
|
8
8
|
import { dateToTimePeriodString } from './functions/dateToTimePeriodString.js';
|
|
9
9
|
import { dateToTimeString } from './functions/dateToTimeString.js';
|
|
10
|
+
import { isSameDay } from './functions/isSameDay.js';
|
|
10
11
|
import { isValidDateInteger } from './functions/isValidDateInteger.js';
|
|
11
12
|
import { isValidDateString } from './functions/isValidDateString.js';
|
|
12
13
|
import { isValidTimeInteger } from './functions/isValidTimeInteger.js';
|
|
@@ -17,40 +18,42 @@ import { timeStringToInteger } from './functions/timeStringToInteger.js';
|
|
|
17
18
|
export declare const months: string[];
|
|
18
19
|
export declare const days: string[];
|
|
19
20
|
export { dateIntegerToDate } from './functions/dateIntegerToDate.js';
|
|
21
|
+
export { dateIntegerToString } from './functions/dateIntegerToString.js';
|
|
20
22
|
export { dateStringToDate } from './functions/dateStringToDate.js';
|
|
23
|
+
export { dateStringToInteger } from './functions/dateStringToInteger.js';
|
|
21
24
|
export { dateToInteger } from './functions/dateToInteger.js';
|
|
22
25
|
export { dateToString } from './functions/dateToString.js';
|
|
23
|
-
export { dateIntegerToString } from './functions/dateIntegerToString.js';
|
|
24
|
-
export { dateStringToInteger } from './functions/dateStringToInteger.js';
|
|
25
26
|
export { dateToTimeInteger } from './functions/dateToTimeInteger.js';
|
|
26
|
-
export { dateToTimeString } from './functions/dateToTimeString.js';
|
|
27
27
|
export { dateToTimePeriodString } from './functions/dateToTimePeriodString.js';
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export { timeStringToInteger } from './functions/timeStringToInteger.js';
|
|
31
|
-
export type { DateString, TimeString, TimePeriodString } from './types.js';
|
|
28
|
+
export { dateToTimeString } from './functions/dateToTimeString.js';
|
|
29
|
+
export { isSameDay } from './functions/isSameDay.js';
|
|
32
30
|
export { isValidDateInteger } from './functions/isValidDateInteger.js';
|
|
33
31
|
export { isValidDateString } from './functions/isValidDateString.js';
|
|
34
32
|
export { isValidTimeInteger } from './functions/isValidTimeInteger.js';
|
|
35
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';
|
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { dateToString } from './functions/dateToString.js';
|
|
|
7
7
|
import { dateToTimeInteger } from './functions/dateToTimeInteger.js';
|
|
8
8
|
import { dateToTimePeriodString } from './functions/dateToTimePeriodString.js';
|
|
9
9
|
import { dateToTimeString } from './functions/dateToTimeString.js';
|
|
10
|
+
import { isSameDay } from './functions/isSameDay.js';
|
|
10
11
|
import { isValidDateInteger } from './functions/isValidDateInteger.js';
|
|
11
12
|
import { isValidDateString } from './functions/isValidDateString.js';
|
|
12
13
|
import { isValidTimeInteger } from './functions/isValidTimeInteger.js';
|
|
@@ -38,38 +39,40 @@ export const days = [
|
|
|
38
39
|
'Saturday'
|
|
39
40
|
];
|
|
40
41
|
export { dateIntegerToDate } from './functions/dateIntegerToDate.js';
|
|
42
|
+
export { dateIntegerToString } from './functions/dateIntegerToString.js';
|
|
41
43
|
export { dateStringToDate } from './functions/dateStringToDate.js';
|
|
44
|
+
export { dateStringToInteger } from './functions/dateStringToInteger.js';
|
|
42
45
|
export { dateToInteger } from './functions/dateToInteger.js';
|
|
43
46
|
export { dateToString } from './functions/dateToString.js';
|
|
44
|
-
export { dateIntegerToString } from './functions/dateIntegerToString.js';
|
|
45
|
-
export { dateStringToInteger } from './functions/dateStringToInteger.js';
|
|
46
47
|
export { dateToTimeInteger } from './functions/dateToTimeInteger.js';
|
|
47
|
-
export { dateToTimeString } from './functions/dateToTimeString.js';
|
|
48
48
|
export { dateToTimePeriodString } from './functions/dateToTimePeriodString.js';
|
|
49
|
-
export {
|
|
50
|
-
export {
|
|
51
|
-
export { timeStringToInteger } from './functions/timeStringToInteger.js';
|
|
49
|
+
export { dateToTimeString } from './functions/dateToTimeString.js';
|
|
50
|
+
export { isSameDay } from './functions/isSameDay.js';
|
|
52
51
|
export { isValidDateInteger } from './functions/isValidDateInteger.js';
|
|
53
52
|
export { isValidDateString } from './functions/isValidDateString.js';
|
|
54
53
|
export { isValidTimeInteger } from './functions/isValidTimeInteger.js';
|
|
55
54
|
export { isValidTimeString } from './functions/isValidTimeString.js';
|
|
55
|
+
export { timeIntegerToPeriodString } from './functions/timeIntegerToPeriodString.js';
|
|
56
|
+
export { timeIntegerToString } from './functions/timeIntegerToString.js';
|
|
57
|
+
export { timeStringToInteger } from './functions/timeStringToInteger.js';
|
|
56
58
|
export default {
|
|
57
|
-
months,
|
|
58
|
-
days,
|
|
59
59
|
dateIntegerToDate,
|
|
60
60
|
dateIntegerToString,
|
|
61
61
|
dateStringToDate,
|
|
62
|
+
dateStringToInteger,
|
|
62
63
|
dateToInteger,
|
|
63
64
|
dateToString,
|
|
64
|
-
dateStringToInteger,
|
|
65
65
|
dateToTimeInteger,
|
|
66
|
-
dateToTimeString,
|
|
67
66
|
dateToTimePeriodString,
|
|
67
|
+
dateToTimeString,
|
|
68
|
+
days,
|
|
69
|
+
isSameDay,
|
|
68
70
|
isValidDateInteger,
|
|
69
71
|
isValidDateString,
|
|
70
72
|
isValidTimeInteger,
|
|
71
73
|
isValidTimeString,
|
|
72
|
-
|
|
74
|
+
months,
|
|
73
75
|
timeIntegerToPeriodString,
|
|
76
|
+
timeIntegerToString,
|
|
74
77
|
timeStringToInteger
|
|
75
78
|
};
|
package/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { dateToString } from './functions/dateToString.js'
|
|
|
7
7
|
import { dateToTimeInteger } from './functions/dateToTimeInteger.js'
|
|
8
8
|
import { dateToTimePeriodString } from './functions/dateToTimePeriodString.js'
|
|
9
9
|
import { dateToTimeString } from './functions/dateToTimeString.js'
|
|
10
|
+
import { isSameDay } from './functions/isSameDay.js'
|
|
10
11
|
import { isValidDateInteger } from './functions/isValidDateInteger.js'
|
|
11
12
|
import { isValidDateString } from './functions/isValidDateString.js'
|
|
12
13
|
import { isValidTimeInteger } from './functions/isValidTimeInteger.js'
|
|
@@ -40,68 +41,45 @@ export const days = [
|
|
|
40
41
|
'Saturday'
|
|
41
42
|
]
|
|
42
43
|
|
|
43
|
-
/*
|
|
44
|
-
* Date Functions
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
// To Date Object
|
|
48
44
|
export { dateIntegerToDate } from './functions/dateIntegerToDate.js'
|
|
45
|
+
export { dateIntegerToString } from './functions/dateIntegerToString.js'
|
|
49
46
|
export { dateStringToDate } from './functions/dateStringToDate.js'
|
|
50
|
-
|
|
51
|
-
// From Date Object
|
|
47
|
+
export { dateStringToInteger } from './functions/dateStringToInteger.js'
|
|
52
48
|
export { dateToInteger } from './functions/dateToInteger.js'
|
|
53
49
|
export { dateToString } from './functions/dateToString.js'
|
|
54
|
-
|
|
55
|
-
// Helpers
|
|
56
|
-
export { dateIntegerToString } from './functions/dateIntegerToString.js'
|
|
57
|
-
export { dateStringToInteger } from './functions/dateStringToInteger.js'
|
|
58
|
-
|
|
59
|
-
/*
|
|
60
|
-
* Time Functions
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
// From Date Object
|
|
64
50
|
export { dateToTimeInteger } from './functions/dateToTimeInteger.js'
|
|
65
|
-
export { dateToTimeString } from './functions/dateToTimeString.js'
|
|
66
51
|
export { dateToTimePeriodString } from './functions/dateToTimePeriodString.js'
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export { timeIntegerToString } from './functions/timeIntegerToString.js'
|
|
70
|
-
export { timeIntegerToPeriodString } from './functions/timeIntegerToPeriodString.js'
|
|
71
|
-
|
|
72
|
-
// From Time String
|
|
73
|
-
export { timeStringToInteger } from './functions/timeStringToInteger.js'
|
|
74
|
-
|
|
75
|
-
// Types
|
|
76
|
-
export type {
|
|
77
|
-
DateString,
|
|
78
|
-
TimeString,
|
|
79
|
-
TimePeriodString
|
|
80
|
-
} from './types.js'
|
|
81
|
-
|
|
82
|
-
// Validators
|
|
52
|
+
export { dateToTimeString } from './functions/dateToTimeString.js'
|
|
53
|
+
export { isSameDay } from './functions/isSameDay.js'
|
|
83
54
|
export { isValidDateInteger } from './functions/isValidDateInteger.js'
|
|
84
55
|
export { isValidDateString } from './functions/isValidDateString.js'
|
|
85
56
|
export { isValidTimeInteger } from './functions/isValidTimeInteger.js'
|
|
86
57
|
export { isValidTimeString } from './functions/isValidTimeString.js'
|
|
58
|
+
export { timeIntegerToPeriodString } from './functions/timeIntegerToPeriodString.js'
|
|
59
|
+
export { timeIntegerToString } from './functions/timeIntegerToString.js'
|
|
60
|
+
export { timeStringToInteger } from './functions/timeStringToInteger.js'
|
|
87
61
|
|
|
88
62
|
export default {
|
|
89
|
-
months,
|
|
90
|
-
days,
|
|
91
63
|
dateIntegerToDate,
|
|
92
64
|
dateIntegerToString,
|
|
93
65
|
dateStringToDate,
|
|
66
|
+
dateStringToInteger,
|
|
94
67
|
dateToInteger,
|
|
95
68
|
dateToString,
|
|
96
|
-
dateStringToInteger,
|
|
97
69
|
dateToTimeInteger,
|
|
98
|
-
dateToTimeString,
|
|
99
70
|
dateToTimePeriodString,
|
|
71
|
+
dateToTimeString,
|
|
72
|
+
days,
|
|
73
|
+
isSameDay,
|
|
100
74
|
isValidDateInteger,
|
|
101
75
|
isValidDateString,
|
|
102
76
|
isValidTimeInteger,
|
|
103
77
|
isValidTimeString,
|
|
104
|
-
|
|
78
|
+
months,
|
|
105
79
|
timeIntegerToPeriodString,
|
|
80
|
+
timeIntegerToString,
|
|
106
81
|
timeStringToInteger
|
|
107
82
|
}
|
|
83
|
+
|
|
84
|
+
// Types
|
|
85
|
+
export type { DateString, TimePeriodString, TimeString } from './types.js'
|
package/package.json
CHANGED
|
@@ -1,37 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@cityssm/utils-datetime",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Date time utilities for Node.js applications",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"date",
|
|
7
|
-
"time",
|
|
8
|
-
"format"
|
|
9
|
-
],
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
},
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
"url": "https://github.com/cityssm/node-utils-datetime
|
|
17
|
-
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"exports":
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
}
|
|
37
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@cityssm/utils-datetime",
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "Date time utilities for Node.js applications",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"date",
|
|
7
|
+
"time",
|
|
8
|
+
"format"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/cityssm/node-utils-datetime#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/cityssm/node-utils-datetime/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/cityssm/node-utils-datetime.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "The Corporation of the City of Sault Ste. Marie",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": "./index.js"
|
|
24
|
+
},
|
|
25
|
+
"directories": {
|
|
26
|
+
"test": "test"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"functions/*",
|
|
30
|
+
"index.*",
|
|
31
|
+
"types.*"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"coverage": "c8 --reporter=lcov --reporter=text --reporter=text-summary node --test \"test/test.js\"",
|
|
35
|
+
"test": "node --test \"test/test.js\""
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^26.1.2",
|
|
39
|
+
"eslint-config-cityssm": "^43.0.0",
|
|
40
|
+
"prettier-config-cityssm": "^2.1.3"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/types.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* yyyy-mm-dd
|
|
3
|
+
*/
|
|
1
4
|
export type DateString = `${number}-${number}-${number}`;
|
|
5
|
+
/**
|
|
6
|
+
* hh:mm
|
|
7
|
+
*/
|
|
2
8
|
export type TimeString = `${number}:${number}`;
|
|
9
|
+
/**
|
|
10
|
+
* h:mm a.m. | h:mm p.m.
|
|
11
|
+
*/
|
|
3
12
|
export type TimePeriodString = `${number}:${number} ${'a.m.' | 'p.m.'}`;
|
package/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
-
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
-
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
-
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
-
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
-
identity and orientation.
|
|
11
|
-
|
|
12
|
-
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
-
diverse, inclusive, and healthy community.
|
|
14
|
-
|
|
15
|
-
## Our Standards
|
|
16
|
-
|
|
17
|
-
Examples of behavior that contributes to a positive environment for our
|
|
18
|
-
community include:
|
|
19
|
-
|
|
20
|
-
- Demonstrating empathy and kindness toward other people
|
|
21
|
-
|
|
22
|
-
- Being respectful of differing opinions, viewpoints, and experiences
|
|
23
|
-
|
|
24
|
-
- Giving and gracefully accepting constructive feedback
|
|
25
|
-
|
|
26
|
-
- Accepting responsibility and apologizing to those affected by our mistakes,
|
|
27
|
-
and learning from the experience
|
|
28
|
-
|
|
29
|
-
- Focusing on what is best not just for us as individuals, but for the overall
|
|
30
|
-
community
|
|
31
|
-
|
|
32
|
-
Examples of unacceptable behavior include:
|
|
33
|
-
|
|
34
|
-
- The use of sexualized language or imagery, and sexual attention or advances of
|
|
35
|
-
any kind
|
|
36
|
-
|
|
37
|
-
- Trolling, insulting or derogatory comments, and personal or political attacks
|
|
38
|
-
|
|
39
|
-
- Public or private harassment
|
|
40
|
-
|
|
41
|
-
- Publishing others' private information, such as a physical or email address,
|
|
42
|
-
without their explicit permission
|
|
43
|
-
|
|
44
|
-
- Other conduct which could reasonably be considered inappropriate in a
|
|
45
|
-
professional setting
|
|
46
|
-
|
|
47
|
-
## Enforcement Responsibilities
|
|
48
|
-
|
|
49
|
-
Community leaders are responsible for clarifying and enforcing our standards of
|
|
50
|
-
acceptable behavior and will take appropriate and fair corrective action in
|
|
51
|
-
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
52
|
-
or harmful.
|
|
53
|
-
|
|
54
|
-
Community leaders have the right and responsibility to remove, edit, or reject
|
|
55
|
-
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
56
|
-
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
57
|
-
decisions when appropriate.
|
|
58
|
-
|
|
59
|
-
## Scope
|
|
60
|
-
|
|
61
|
-
This Code of Conduct applies within all community spaces, and also applies when
|
|
62
|
-
an individual is officially representing the community in public spaces.
|
|
63
|
-
Examples of representing our community include using an official e-mail address,
|
|
64
|
-
posting via an official social media account, or acting as an appointed
|
|
65
|
-
representative at an online or offline event.
|
|
66
|
-
|
|
67
|
-
## Enforcement
|
|
68
|
-
|
|
69
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
70
|
-
reported to the community leaders responsible for enforcement at
|
|
71
|
-
**corporateapps@cityssm.on.ca**.
|
|
72
|
-
All complaints will be reviewed and investigated promptly and fairly.
|
|
73
|
-
|
|
74
|
-
All community leaders are obligated to respect the privacy and security of the
|
|
75
|
-
reporter of any incident.
|
|
76
|
-
|
|
77
|
-
## Enforcement Guidelines
|
|
78
|
-
|
|
79
|
-
Community leaders will follow these Community Impact Guidelines in determining
|
|
80
|
-
the consequences for any action they deem in violation of this Code of Conduct:
|
|
81
|
-
|
|
82
|
-
### 1. Correction
|
|
83
|
-
|
|
84
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
85
|
-
unprofessional or unwelcome in the community.
|
|
86
|
-
|
|
87
|
-
**Consequence**: A private, written warning from community leaders, providing
|
|
88
|
-
clarity around the nature of the violation and an explanation of why the
|
|
89
|
-
behavior was inappropriate. A public apology may be requested.
|
|
90
|
-
|
|
91
|
-
### 2. Warning
|
|
92
|
-
|
|
93
|
-
**Community Impact**: A violation through a single incident or series of
|
|
94
|
-
actions.
|
|
95
|
-
|
|
96
|
-
**Consequence**: A warning with consequences for continued behavior. No
|
|
97
|
-
interaction with the people involved, including unsolicited interaction with
|
|
98
|
-
those enforcing the Code of Conduct, for a specified period of time. This
|
|
99
|
-
includes avoiding interactions in community spaces as well as external channels
|
|
100
|
-
like social media. Violating these terms may lead to a temporary or permanent
|
|
101
|
-
ban.
|
|
102
|
-
|
|
103
|
-
### 3. Temporary Ban
|
|
104
|
-
|
|
105
|
-
**Community Impact**: A serious violation of community standards, including
|
|
106
|
-
sustained inappropriate behavior.
|
|
107
|
-
|
|
108
|
-
**Consequence**: A temporary ban from any sort of interaction or public
|
|
109
|
-
communication with the community for a specified period of time. No public or
|
|
110
|
-
private interaction with the people involved, including unsolicited interaction
|
|
111
|
-
with those enforcing the Code of Conduct, is allowed during this period.
|
|
112
|
-
Violating these terms may lead to a permanent ban.
|
|
113
|
-
|
|
114
|
-
### 4. Permanent Ban
|
|
115
|
-
|
|
116
|
-
**Community Impact**: Demonstrating a pattern of violation of community
|
|
117
|
-
standards, including sustained inappropriate behavior, harassment of an
|
|
118
|
-
individual, or aggression toward or disparagement of classes of individuals.
|
|
119
|
-
|
|
120
|
-
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
121
|
-
community.
|
|
122
|
-
|
|
123
|
-
## Attribution
|
|
124
|
-
|
|
125
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
126
|
-
version 2.1, available at
|
|
127
|
-
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
128
|
-
|
|
129
|
-
Community Impact Guidelines were inspired by
|
|
130
|
-
[Mozilla's code of conduct enforcement ladder][mozilla coc].
|
|
131
|
-
|
|
132
|
-
For answers to common questions about this code of conduct, see the FAQ at
|
|
133
|
-
[https://www.contributor-covenant.org/faq][faq]. Translations are available at
|
|
134
|
-
[https://www.contributor-covenant.org/translations][translations].
|
|
135
|
-
|
|
136
|
-
[homepage]: https://www.contributor-covenant.org
|
|
137
|
-
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
138
|
-
[mozilla coc]: https://github.com/mozilla/diversity
|
|
139
|
-
[faq]: https://www.contributor-covenant.org/faq
|
|
140
|
-
[translations]: https://www.contributor-covenant.org/translations
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Thank you for your interest in making the Date Time Utils package better
|
|
2
|
-
|
|
3
|
-
Together, we can build high quality software that meets the needs of municipalities,
|
|
4
|
-
while remaining open and budget conscious.
|
|
5
|
-
|
|
6
|
-
**Thank you for taking the time to read the contributing guidelines.**
|
|
7
|
-
|
|
8
|
-
## All contributions are welcome
|
|
9
|
-
|
|
10
|
-
Being a very small team, contributions are greatly appreciated. How can you contribute?
|
|
11
|
-
|
|
12
|
-
- **Promote this project!**
|
|
13
|
-
- Documentation and tutorials
|
|
14
|
-
- Submit bug reports (or fix them!)
|
|
15
|
-
- Request new features (or build them!)
|
|
16
|
-
|
|
17
|
-
## Please Read the Code of Conduct
|
|
18
|
-
|
|
19
|
-
The [Code of Conduct](CODE_OF_CONDUCT.md) document describes how we should act when working together.
|
|
20
|
-
Be nice! :smile:
|
|
21
|
-
|
|
22
|
-
## How to report a bug or suggest an enhancement
|
|
23
|
-
|
|
24
|
-
**If you find a security vulnerability, do NOT open an issue. Email
|
|
25
|
-
<corporateapps@cityssm.on.ca> instead.**
|
|
26
|
-
|
|
27
|
-
For all other bug reports, feature requests, or enhancements,
|
|
28
|
-
open an issue and use the closest template.
|
|
29
|
-
|
|
30
|
-
## Thanks Again
|
|
31
|
-
|
|
32
|
-
We are a very small team with big aspirations and limited resources.
|
|
33
|
-
Thank you for helping with this project in any way you can!
|
package/SECURITY.md
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# Security Policy
|
|
2
|
-
|
|
3
|
-
**Thank you for your interest in keeping this project safe for everyone.**
|
|
4
|
-
|
|
5
|
-
## Supported Versions
|
|
6
|
-
|
|
7
|
-
Due to limited resources, only the latest version is supported only for security updates.
|
|
8
|
-
|
|
9
|
-
## Reporting a Vulnerability
|
|
10
|
-
|
|
11
|
-
To report a security vulnerability,
|
|
12
|
-
please email <corporateapps@cityssm.on.ca>.
|
|
13
|
-
|
|
14
|
-
Every attempt will be made to resolve confirmed vulnerabilities
|
|
15
|
-
in a timely manner.
|