-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.ts
45 lines (35 loc) · 1.15 KB
/
utilities.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
}