@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.
Files changed (75) hide show
  1. package/README.md +0 -1
  2. package/{dateIntegerToDate.d.ts → functions/dateIntegerToDate.d.ts} +0 -1
  3. package/{dateIntegerToDate.js → functions/dateIntegerToDate.js} +5 -0
  4. package/{dateIntegerToDate.ts → functions/dateIntegerToDate.ts} +0 -5
  5. package/functions/dateIntegerToString.d.ts +3 -0
  6. package/{dateIntegerToString.js → functions/dateIntegerToString.js} +5 -0
  7. package/{dateIntegerToString.ts → functions/dateIntegerToString.ts} +3 -6
  8. package/functions/dateStringToDate.d.ts +7 -0
  9. package/{dateStringToDate.js → functions/dateStringToDate.js} +6 -0
  10. package/functions/dateStringToInteger.d.ts +2 -0
  11. package/{dateStringToInteger.js → functions/dateStringToInteger.js} +7 -0
  12. package/{dateStringToInteger.ts → functions/dateStringToInteger.ts} +7 -1
  13. package/{dateToInteger.d.ts → functions/dateToInteger.d.ts} +0 -1
  14. package/{dateToInteger.js → functions/dateToInteger.js} +5 -0
  15. package/{dateToInteger.ts → functions/dateToInteger.ts} +0 -2
  16. package/functions/dateToString.d.ts +3 -0
  17. package/{dateToString.js → functions/dateToString.js} +5 -0
  18. package/{dateToString.ts → functions/dateToString.ts} +1 -5
  19. package/{dateToTimeInteger.js → functions/dateToTimeInteger.js} +5 -0
  20. package/functions/dateToTimePeriodString.d.ts +3 -0
  21. package/{dateToTimePeriodString.js → functions/dateToTimePeriodString.js} +5 -0
  22. package/{dateToTimePeriodString.ts → functions/dateToTimePeriodString.ts} +1 -5
  23. package/functions/dateToTimeString.d.ts +3 -0
  24. package/{dateToTimeString.js → functions/dateToTimeString.js} +5 -0
  25. package/{dateToTimeString.ts → functions/dateToTimeString.ts} +1 -5
  26. package/functions/isSameDay.d.ts +7 -0
  27. package/functions/isSameDay.js +11 -0
  28. package/functions/isSameDay.ts +13 -0
  29. package/functions/isValidDateInteger.d.ts +6 -0
  30. package/{isValidDateInteger.js → functions/isValidDateInteger.js} +5 -0
  31. package/functions/isValidDateString.d.ts +7 -0
  32. package/{isValidDateString.js → functions/isValidDateString.js} +5 -0
  33. package/{isValidDateString.ts → functions/isValidDateString.ts} +1 -1
  34. package/functions/isValidTimeInteger.d.ts +6 -0
  35. package/{isValidTimeInteger.js → functions/isValidTimeInteger.js} +5 -0
  36. package/functions/isValidTimeString.d.ts +7 -0
  37. package/{isValidTimeString.js → functions/isValidTimeString.js} +5 -0
  38. package/{isValidTimeString.ts → functions/isValidTimeString.ts} +1 -1
  39. package/{timeIntegerToPeriodString.d.ts → functions/timeIntegerToPeriodString.d.ts} +1 -1
  40. package/{timeIntegerToPeriodString.js → functions/timeIntegerToPeriodString.js} +6 -0
  41. package/{timeIntegerToPeriodString.ts → functions/timeIntegerToPeriodString.ts} +3 -2
  42. package/functions/timeIntegerToString.d.ts +7 -0
  43. package/{timeIntegerToString.js → functions/timeIntegerToString.js} +5 -0
  44. package/{timeIntegerToString.ts → functions/timeIntegerToString.ts} +1 -1
  45. package/functions/timeStringToInteger.d.ts +2 -0
  46. package/functions/timeStringToInteger.js +17 -0
  47. package/{timeStringToInteger.ts → functions/timeStringToInteger.ts} +10 -0
  48. package/index.d.ts +41 -38
  49. package/index.js +40 -37
  50. package/index.ts +43 -65
  51. package/package.json +42 -38
  52. package/{dateTimeTypes.d.ts → types.d.ts} +9 -0
  53. package/CODE_OF_CONDUCT.md +0 -140
  54. package/CONTRIBUTING.md +0 -33
  55. package/SECURITY.md +0 -15
  56. package/dateIntegerToString.d.ts +0 -4
  57. package/dateStringToDate.d.ts +0 -1
  58. package/dateStringToInteger.d.ts +0 -1
  59. package/dateToString.d.ts +0 -4
  60. package/dateToTimePeriodString.d.ts +0 -4
  61. package/dateToTimeString.d.ts +0 -4
  62. package/isValidDateInteger.d.ts +0 -1
  63. package/isValidDateString.d.ts +0 -2
  64. package/isValidTimeInteger.d.ts +0 -1
  65. package/isValidTimeString.d.ts +0 -2
  66. package/timeIntegerToString.d.ts +0 -2
  67. package/timeStringToInteger.d.ts +0 -1
  68. package/timeStringToInteger.js +0 -7
  69. /package/{dateStringToDate.ts → functions/dateStringToDate.ts} +0 -0
  70. /package/{dateToTimeInteger.d.ts → functions/dateToTimeInteger.d.ts} +0 -0
  71. /package/{dateToTimeInteger.ts → functions/dateToTimeInteger.ts} +0 -0
  72. /package/{isValidDateInteger.ts → functions/isValidDateInteger.ts} +0 -0
  73. /package/{isValidTimeInteger.ts → functions/isValidTimeInteger.ts} +0 -0
  74. /package/{dateTimeTypes.js → types.js} +0 -0
  75. /package/{dateTimeTypes.ts → types.ts} +0 -0
package/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![npm (scoped)](https://img.shields.io/npm/v/@cityssm/utils-datetime)](https://www.npmjs.com/package/@cityssm/utils-datetime)
4
4
  [![DeepSource](https://app.deepsource.com/gh/cityssm/node-utils-datetime.svg/?label=active+issues&show_trend=true&token=Qxl72G0xqdKZdqcKOm8Jg-Dt)](https://app.deepsource.com/gh/cityssm/node-utils-datetime/)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/6f6f8ed35487ab5f36a5/maintainability)](https://codeclimate.com/github/cityssm/node-utils-datetime/maintainability)
6
5
  [![codecov](https://codecov.io/gh/cityssm/node-utils-datetime/branch/main/graph/badge.svg?token=3E8VHNL34S)](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
@@ -0,0 +1,3 @@
1
+ import type { DateString } from '../types.js';
2
+ export declare function dateIntegerToString(dateInteger: number): DateString | '';
3
+ export declare function dateIntegerToString(dateInteger: null | undefined | 0): '';
@@ -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;
@@ -0,0 +1,2 @@
1
+ import type { DateString } from '../types.js';
2
+ export declare function dateStringToInteger(dateString: DateString): number;
@@ -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
- return dateToInteger(dateStringToDate(dateString))
20
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
21
+ return dateToInteger(dateStringToDate(dateString) as Date)
16
22
  }
@@ -1,3 +1,2 @@
1
- export declare function dateToInteger<T extends Date | undefined>(dateObject: T): number | undefined;
2
1
  export declare function dateToInteger(dateObject: Date): number;
3
2
  export declare function dateToInteger(dateObject: undefined): undefined;
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Formats a JavaScript Date object as a number.
3
+ * @param dateObject - A JavaScript Date object.
4
+ * @returns - A number representing the date.
5
+ */
1
6
  export function dateToInteger(dateObject) {
2
7
  if (dateObject === undefined) {
3
8
  return undefined;
@@ -1,5 +1,3 @@
1
- export function dateToInteger<T extends Date | undefined>(dateObject: T): number | undefined
2
-
3
1
  export function dateToInteger(dateObject: Date): number
4
2
  export function dateToInteger(dateObject: undefined): undefined
5
3
 
@@ -0,0 +1,3 @@
1
+ import type { DateString } from '../types.js';
2
+ export declare function dateToString(dateObject: Date): DateString;
3
+ export declare function dateToString(dateObject: undefined): '';
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Formats a JavaScript Date object as a date string.
3
+ * @param dateObject - A JavaScript Date object
4
+ * @returns - A date string.
5
+ */
1
6
  export function dateToString(dateObject) {
2
7
  if (dateObject === undefined) {
3
8
  return '';
@@ -1,8 +1,4 @@
1
- import type { DateString } from './dateTimeTypes.js'
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 the time in a JavaScript Date as a number.
3
+ * @param dateObject - A JavaScript Date object.
4
+ * @returns - A number representing a time.
5
+ */
1
6
  export function dateToTimeInteger(dateObject) {
2
7
  if (dateObject === undefined) {
3
8
  return undefined;
@@ -0,0 +1,3 @@
1
+ import type { TimePeriodString } from '../types.js';
2
+ export declare function dateToTimePeriodString(dateObject: Date): TimePeriodString;
3
+ export declare function dateToTimePeriodString(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 './dateTimeTypes.js'
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): ''
@@ -0,0 +1,3 @@
1
+ import type { TimeString } from '../types.js';
2
+ export declare function dateToTimeString(dateObject: Date): TimeString;
3
+ export declare function dateToTimeString(dateObject: undefined): '';
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Formats a JavaScript Date object as a time string.
3
+ * @param dateObject - A JavaScript Date object.
4
+ * @returns - A string representing the time.
5
+ */
1
6
  export function dateToTimeString(dateObject) {
2
7
  if (dateObject === undefined) {
3
8
  return '';
@@ -1,8 +1,4 @@
1
- import type { TimeString } from './dateTimeTypes.js'
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 &&
@@ -1,4 +1,4 @@
1
- import type { DateString } from './dateTimeTypes.js'
1
+ import type { DateString } from '../types.js'
2
2
 
3
3
  const dateStringRegex = /^\d{4}-[01]\d-[0-3]\d$/
4
4
 
@@ -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,4 +1,4 @@
1
- import type { TimeString } from './dateTimeTypes.js'
1
+ import type { TimeString } from '../types.js'
2
2
 
3
3
  const timeStringRegex = /^[01]\d:[0-5]\d$/
4
4
 
@@ -1,3 +1,3 @@
1
- import type { TimePeriodString } from './dateTimeTypes.js';
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)}`;
@@ -1,4 +1,4 @@
1
- import type { TimeString } from './dateTimeTypes.js'
1
+ import type { TimeString } from '../types.js'
2
2
 
3
3
  /**
4
4
  * Formats a number representing a time as a string.
@@ -0,0 +1,2 @@
1
+ import type { TimeString } from '../types.js';
2
+ export declare function timeStringToInteger(timeString: TimeString): number;
@@ -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 { isValidDateInteger } from './isValidDateInteger.js';
11
- import { isValidDateString } from './isValidDateString.js';
12
- import { isValidTimeInteger } from './isValidTimeInteger.js';
13
- import { isValidTimeString } from './isValidTimeString.js';
14
- import { timeIntegerToPeriodString } from './timeIntegerToPeriodString.js';
15
- import { timeIntegerToString } from './timeIntegerToString.js';
16
- import { timeStringToInteger } from './timeStringToInteger.js';
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 { dateStringToDate } from './dateStringToDate.js';
21
- export { dateToInteger } from './dateToInteger.js';
22
- export { dateToString } from './dateToString.js';
23
- export { dateIntegerToString } from './dateIntegerToString.js';
24
- export { dateStringToInteger } from './dateStringToInteger.js';
25
- export { dateToTimeInteger } from './dateToTimeInteger.js';
26
- export { dateToTimeString } from './dateToTimeString.js';
27
- export { dateToTimePeriodString } from './dateToTimePeriodString.js';
28
- export { timeIntegerToString } from './timeIntegerToString.js';
29
- export { timeIntegerToPeriodString } from './timeIntegerToPeriodString.js';
30
- export { timeStringToInteger } from './timeStringToInteger.js';
31
- export type { DateString, TimeString, TimePeriodString } from './dateTimeTypes.js';
32
- export { isValidDateInteger } from './isValidDateInteger.js';
33
- export { isValidDateString } from './isValidDateString.js';
34
- export { isValidTimeInteger } from './isValidTimeInteger.js';
35
- export { isValidTimeString } from './isValidTimeString.js';
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
- timeIntegerToString: typeof timeIntegerToString;
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';