- 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
|
// &from=2020-09-11&until=2021-05-11
|
||||||
if ("from" in oaiRequest && "until" in oaiRequest) {
|
if ("from" in oaiRequest && "until" in oaiRequest) {
|
||||||
const from = oaiRequest["from"] as string;
|
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;
|
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()) {
|
if (!fromDate.isValid() || !untilDate.isValid()) {
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||||
|
@ -467,6 +467,8 @@ export class OaiController {
|
||||||
OaiErrorCodes.BADARGUMENT,
|
OaiErrorCodes.BADARGUMENT,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
fromDate = dayjs.tz(from, "Europe/Vienna");
|
||||||
|
untilDate = dayjs.tz(until, "Europe/Vienna");
|
||||||
|
|
||||||
if (from.length != until.length) {
|
if (from.length != until.length) {
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
|
@ -496,7 +498,7 @@ export class OaiController {
|
||||||
// });
|
// });
|
||||||
} else if ("from" in oaiRequest && !("until" in oaiRequest)) {
|
} else if ("from" in oaiRequest && !("until" in oaiRequest)) {
|
||||||
const from = oaiRequest["from"] as string;
|
const from = oaiRequest["from"] as string;
|
||||||
let fromDate = dayjs.tz(from, "Europe/Vienna")
|
let fromDate = dayjs(from);
|
||||||
if (!fromDate.isValid()) {
|
if (!fromDate.isValid()) {
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||||
|
@ -504,6 +506,7 @@ export class OaiController {
|
||||||
OaiErrorCodes.BADARGUMENT,
|
OaiErrorCodes.BADARGUMENT,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
fromDate = dayjs.tz(from, "Europe/Vienna")
|
||||||
fromDate.hour() == 0 && (fromDate = fromDate.startOf("day"));
|
fromDate.hour() == 0 && (fromDate = fromDate.startOf("day"));
|
||||||
|
|
||||||
const now = dayjs();
|
const now = dayjs();
|
||||||
|
@ -523,7 +526,7 @@ export class OaiController {
|
||||||
}
|
}
|
||||||
} else if (!("from" in oaiRequest) && "until" in oaiRequest) {
|
} else if (!("from" in oaiRequest) && "until" in oaiRequest) {
|
||||||
const until = oaiRequest["until"] as string;
|
const until = oaiRequest["until"] as string;
|
||||||
let untilDate = dayjs.tz(until, "Europe/Vienna"); //.tz(timeZone);
|
let untilDate = dayjs(until);
|
||||||
if (!untilDate.isValid()) {
|
if (!untilDate.isValid()) {
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||||
|
@ -531,6 +534,7 @@ export class OaiController {
|
||||||
OaiErrorCodes.BADARGUMENT,
|
OaiErrorCodes.BADARGUMENT,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
untilDate = dayjs.tz(until, "Europe/Vienna");
|
||||||
untilDate.hour() == 0 && (untilDate = untilDate.endOf("day"));
|
untilDate.hour() == 0 && (untilDate = untilDate.endOf("day"));
|
||||||
|
|
||||||
const firstPublishedDataset: Dataset = (await Dataset.earliestPublicationDate()) as Dataset;
|
const firstPublishedDataset: Dataset = (await Dataset.earliestPublicationDate()) as Dataset;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user