- validate junk dates before using timezones
This commit is contained in:
parent
4b0478fe62
commit
05e9273823
|
@ -457,9 +457,9 @@ export class OaiController {
|
|||
// &from=2020-09-11&until=2021-05-11
|
||||
if ("from" in oaiRequest && "until" in oaiRequest) {
|
||||
const from = oaiRequest["from"] as string;
|
||||
let fromDate = dayjs.tz(from, "Europe/Vienna"); //.tz(timeZone);
|
||||
let fromDate = dayjs(from); //.tz(timeZone);
|
||||
const until = oaiRequest["until"] as string;
|
||||
let untilDate = dayjs.tz(until, "Europe/Vienna"); //.tz(timeZone);
|
||||
let untilDate = dayjs(until); //.tz(timeZone);
|
||||
if (!fromDate.isValid() || !untilDate.isValid()) {
|
||||
throw new OaiModelException(
|
||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||
|
@ -467,6 +467,8 @@ export class OaiController {
|
|||
OaiErrorCodes.BADARGUMENT,
|
||||
);
|
||||
}
|
||||
fromDate = dayjs.tz(from, "Europe/Vienna");
|
||||
untilDate = dayjs.tz(until, "Europe/Vienna");
|
||||
|
||||
if (from.length != until.length) {
|
||||
throw new OaiModelException(
|
||||
|
@ -496,7 +498,7 @@ export class OaiController {
|
|||
// });
|
||||
} else if ("from" in oaiRequest && !("until" in oaiRequest)) {
|
||||
const from = oaiRequest["from"] as string;
|
||||
let fromDate = dayjs.tz(from, "Europe/Vienna")
|
||||
let fromDate = dayjs(from);
|
||||
if (!fromDate.isValid()) {
|
||||
throw new OaiModelException(
|
||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||
|
@ -504,6 +506,7 @@ export class OaiController {
|
|||
OaiErrorCodes.BADARGUMENT,
|
||||
);
|
||||
}
|
||||
fromDate = dayjs.tz(from, "Europe/Vienna")
|
||||
fromDate.hour() == 0 && (fromDate = fromDate.startOf("day"));
|
||||
|
||||
const now = dayjs();
|
||||
|
@ -523,7 +526,7 @@ export class OaiController {
|
|||
}
|
||||
} else if (!("from" in oaiRequest) && "until" in oaiRequest) {
|
||||
const until = oaiRequest["until"] as string;
|
||||
let untilDate = dayjs.tz(until, "Europe/Vienna"); //.tz(timeZone);
|
||||
let untilDate = dayjs(until);
|
||||
if (!untilDate.isValid()) {
|
||||
throw new OaiModelException(
|
||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||
|
@ -531,6 +534,7 @@ export class OaiController {
|
|||
OaiErrorCodes.BADARGUMENT,
|
||||
);
|
||||
}
|
||||
untilDate = dayjs.tz(until, "Europe/Vienna");
|
||||
untilDate.hour() == 0 && (untilDate = untilDate.endOf("day"));
|
||||
|
||||
const firstPublishedDataset: Dataset = (await Dataset.earliestPublicationDate()) as Dataset;
|
||||
|
|
Loading…
Reference in New Issue
Block a user