-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.js
26 lines (26 loc) · 1020 Bytes
/
utilities.js
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
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;
}