- parse any date automatically with timezone 'Europe/Vienna'
This commit is contained in:
parent
9eef31fbd8
commit
4b0478fe62
|
@ -40,7 +40,7 @@ const sequelizeConnection = new Sequelize(dbName, dbUser, dbPassword, {
|
||||||
idle: 10000,
|
idle: 10000,
|
||||||
},
|
},
|
||||||
logging: false,
|
logging: false,
|
||||||
timezone: "+02:00", //for writing to database
|
timezone: "Europe/Vienna", //for writing to database
|
||||||
});
|
});
|
||||||
// sequelizeConnection.addModels([Dataset, Abstract]);
|
// sequelizeConnection.addModels([Dataset, Abstract]);
|
||||||
// sequelizeConnection.addModels([DocumentXmlCache]);
|
// sequelizeConnection.addModels([DocumentXmlCache]);
|
||||||
|
|
|
@ -17,6 +17,8 @@ import XmlModel from "../library/XmlModel";
|
||||||
import Configuration from "../library/oai/OaiConfiguration";
|
import Configuration from "../library/oai/OaiConfiguration";
|
||||||
import ResumptionToken from "../library/oai/ResumptionToken";
|
import ResumptionToken from "../library/oai/ResumptionToken";
|
||||||
import TokenWorker from "../library/oai/TokenWorker";
|
import TokenWorker from "../library/oai/TokenWorker";
|
||||||
|
import utc from "dayjs/plugin/utc";
|
||||||
|
import timezone from "dayjs/plugin/timezone";
|
||||||
|
|
||||||
interface XslTParameter {
|
interface XslTParameter {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
|
@ -53,6 +55,8 @@ export class OaiController {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.proc = readFileSync(__dirname + "/datasetxml2oai.sef.json");
|
this.proc = readFileSync(__dirname + "/datasetxml2oai.sef.json");
|
||||||
this.configuration = new Configuration();
|
this.configuration = new Configuration();
|
||||||
|
dayjs.extend(utc);
|
||||||
|
dayjs.extend(timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("")
|
@Post("")
|
||||||
|
@ -81,7 +85,7 @@ export class OaiController {
|
||||||
let earliestDateFromDb;
|
let earliestDateFromDb;
|
||||||
const firstPublishedDataset: Dataset | null = await Dataset.earliestPublicationDate();
|
const firstPublishedDataset: Dataset | null = await Dataset.earliestPublicationDate();
|
||||||
firstPublishedDataset != null &&
|
firstPublishedDataset != null &&
|
||||||
(earliestDateFromDb = dayjs(firstPublishedDataset.server_date_published).format("YYYY-MM-DDThh:mm:ss[Z]"));
|
(earliestDateFromDb = dayjs(firstPublishedDataset.server_date_published).format("YYYY-MM-DDTHH:mm:ss[Z]"));
|
||||||
this.xsltParameter["earliestDatestamp"] = earliestDateFromDb;
|
this.xsltParameter["earliestDatestamp"] = earliestDateFromDb;
|
||||||
|
|
||||||
const oaiRequest: OaiParameter = request.query;
|
const oaiRequest: OaiParameter = request.query;
|
||||||
|
@ -157,7 +161,7 @@ export class OaiController {
|
||||||
|
|
||||||
// Set response time
|
// Set response time
|
||||||
const now: Dayjs = dayjs();
|
const now: Dayjs = dayjs();
|
||||||
this.xsltParameter["responseDate"] = now.format("YYYY-MM-DDThh:mm:ss[Z]");
|
this.xsltParameter["responseDate"] = now.format("YYYY-MM-DDTHH:mm:ss[Z]");
|
||||||
this.xsltParameter["unixTimestamp"] = now.unix();
|
this.xsltParameter["unixTimestamp"] = now.unix();
|
||||||
|
|
||||||
// set OAI base url
|
// set OAI base url
|
||||||
|
@ -448,13 +452,14 @@ export class OaiController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const timeZone = "Europe/Vienna"; // Canonical time zone name
|
||||||
// &from=2020-09-03&until2020-09-03
|
// &from=2020-09-03&until2020-09-03
|
||||||
// &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(from);
|
let fromDate = dayjs.tz(from, "Europe/Vienna"); //.tz(timeZone);
|
||||||
const until = oaiRequest["until"] as string;
|
const until = oaiRequest["until"] as string;
|
||||||
let untilDate = dayjs(until);
|
let untilDate = dayjs.tz(until, "Europe/Vienna"); //.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,
|
||||||
|
@ -473,18 +478,25 @@ export class OaiController {
|
||||||
fromDate.hour() == 0 && (fromDate = fromDate.startOf("day"));
|
fromDate.hour() == 0 && (fromDate = fromDate.startOf("day"));
|
||||||
untilDate.hour() == 0 && (untilDate = untilDate.endOf("day"));
|
untilDate.hour() == 0 && (untilDate = untilDate.endOf("day"));
|
||||||
|
|
||||||
|
// format("YYYY-MM-DDTHH:mm:ss[Z]"));
|
||||||
|
|
||||||
andArray.push({
|
andArray.push({
|
||||||
server_date_published: {
|
server_date_published: {
|
||||||
// [Sequelize.Op.between]: [fromDate, untilDate]
|
// [Sequelize.Op.between]: [fromDate.format("YYYY-MM-DD HH:mm:ss"), untilDate.format("YYYY-MM-DD HH:mm:ss")]
|
||||||
[Sequelize.Op.and]: {
|
[Sequelize.Op.and]: {
|
||||||
[Sequelize.Op.gte]: fromDate.format("YYYY-MM-DD HH:mm:ss"),
|
[Sequelize.Op.gte]: fromDate.format("YYYY-MM-DD HH:mm:ss"),
|
||||||
[Sequelize.Op.lte]: untilDate.format("YYYY-MM-DD HH:mm:ss"),
|
[Sequelize.Op.lte]: untilDate.format("YYYY-MM-DD HH:mm:ss"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
// andArray.push({
|
||||||
|
// server_date_published: {
|
||||||
|
// [Sequelize.Op.lte]: untilDate.format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
// },
|
||||||
|
// });
|
||||||
} 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(from);
|
let fromDate = dayjs.tz(from, "Europe/Vienna")
|
||||||
if (!fromDate.isValid()) {
|
if (!fromDate.isValid()) {
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||||
|
@ -511,7 +523,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(until);
|
let untilDate = dayjs.tz(until, "Europe/Vienna"); //.tz(timeZone);
|
||||||
if (!untilDate.isValid()) {
|
if (!untilDate.isValid()) {
|
||||||
throw new OaiModelException(
|
throw new OaiModelException(
|
||||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user