-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
194 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import assert from 'node:assert'; | ||
import { formatDateTimeFiltersParameters } from '../utilities.js'; | ||
describe('node-green-button-subscriber/helpers', () => { | ||
it('Formats Dates and ISO strings properly', () => { | ||
const isoDate = '2023-01-02T12:34:56Z'; | ||
const dateTimeFilters = { | ||
publishedMin: isoDate, | ||
publishedMax: new Date(isoDate) | ||
}; | ||
const parameters = formatDateTimeFiltersParameters(dateTimeFilters); | ||
assert.strictEqual(parameters['published-min'], isoDate); | ||
assert.strictEqual(parameters['published-max'], isoDate); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import assert from 'node:assert' | ||
|
||
import type { DateTimeFilters, IsoDateString } from '../types.js' | ||
import { formatDateTimeFiltersParameters } from '../utilities.js' | ||
|
||
describe('node-green-button-subscriber/helpers', () => { | ||
it('Formats Dates and ISO strings properly', () => { | ||
const isoDate: IsoDateString = '2023-01-02T12:34:56Z' | ||
|
||
const dateTimeFilters: DateTimeFilters = { | ||
publishedMin: isoDate, | ||
publishedMax: new Date(isoDate) | ||
} | ||
|
||
const parameters = formatDateTimeFiltersParameters(dateTimeFilters) | ||
|
||
assert.strictEqual(parameters['published-min'], isoDate) | ||
assert.strictEqual(parameters['published-max'], isoDate) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export type IsoDateString = `${string}-${string}-${string}T${string}:${string}:${string}Z`; | ||
export type DateOrIsoDateString = Date | IsoDateString; | ||
export interface DateTimeFilters { | ||
publishedMin?: DateOrIsoDateString; | ||
publishedMax?: DateOrIsoDateString; | ||
updatedMin?: DateOrIsoDateString; | ||
updatedMax?: DateOrIsoDateString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type IsoDateString = | ||
`${string}-${string}-${string}T${string}:${string}:${string}Z` | ||
|
||
export type DateOrIsoDateString = Date | IsoDateString | ||
|
||
export interface DateTimeFilters { | ||
publishedMin?: DateOrIsoDateString | ||
publishedMax?: DateOrIsoDateString | ||
updatedMin?: DateOrIsoDateString | ||
updatedMax?: DateOrIsoDateString | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { DateOrIsoDateString, DateTimeFilters, IsoDateString } from './types.js'; | ||
export declare function formatDateTime(dateOrIsoDateString: DateOrIsoDateString): IsoDateString; | ||
export declare function formatDateTimeFiltersParameters(dateTimeFilters?: DateTimeFilters): Record<string, string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export function formatDateTime(dateOrIsoDateString) { | ||
if (typeof dateOrIsoDateString === 'string') { | ||
return dateOrIsoDateString; | ||
} | ||
const isoDateString = dateOrIsoDateString.toISOString(); | ||
if (isoDateString.length === 24) { | ||
return (isoDateString.slice(0, -5) + 'Z'); | ||
} | ||
return isoDateString; | ||
} | ||
export function formatDateTimeFiltersParameters(dateTimeFilters = {}) { | ||
const parameters = {}; | ||
if (dateTimeFilters.publishedMin !== undefined) { | ||
parameters['published-min'] = formatDateTime(dateTimeFilters.publishedMin); | ||
} | ||
if (dateTimeFilters.publishedMax !== undefined) { | ||
parameters['published-max'] = formatDateTime(dateTimeFilters.publishedMax); | ||
} | ||
if (dateTimeFilters.updatedMin !== undefined) { | ||
parameters['updated-min'] = formatDateTime(dateTimeFilters.updatedMin); | ||
} | ||
if (dateTimeFilters.updatedMax !== undefined) { | ||
parameters['updated-max'] = formatDateTime(dateTimeFilters.updatedMax); | ||
} | ||
return parameters; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { | ||
DateOrIsoDateString, | ||
DateTimeFilters, | ||
IsoDateString | ||
} from './types.js' | ||
|
||
export function formatDateTime( | ||
dateOrIsoDateString: DateOrIsoDateString | ||
): IsoDateString { | ||
if (typeof dateOrIsoDateString === 'string') { | ||
return dateOrIsoDateString | ||
} | ||
|
||
const isoDateString = dateOrIsoDateString.toISOString() | ||
|
||
if (isoDateString.length === 24) { | ||
return (isoDateString.slice(0, -5) + 'Z') as IsoDateString | ||
} | ||
|
||
return isoDateString as IsoDateString | ||
} | ||
|
||
export function formatDateTimeFiltersParameters( | ||
dateTimeFilters: DateTimeFilters = {} | ||
): Record<string, string> { | ||
const parameters = {} | ||
|
||
if (dateTimeFilters.publishedMin !== undefined) { | ||
parameters['published-min'] = formatDateTime(dateTimeFilters.publishedMin) | ||
} | ||
|
||
if (dateTimeFilters.publishedMax !== undefined) { | ||
parameters['published-max'] = formatDateTime(dateTimeFilters.publishedMax) | ||
} | ||
|
||
if (dateTimeFilters.updatedMin !== undefined) { | ||
parameters['updated-min'] = formatDateTime(dateTimeFilters.updatedMin) | ||
} | ||
|
||
if (dateTimeFilters.updatedMax !== undefined) { | ||
parameters['updated-max'] = formatDateTime(dateTimeFilters.updatedMax) | ||
} | ||
|
||
return parameters | ||
} |