- 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,
|
||||
},
|
||||
logging: false,
|
||||
timezone: "+02:00", //for writing to database
|
||||
timezone: "Europe/Vienna", //for writing to database
|
||||
});
|
||||
// sequelizeConnection.addModels([Dataset, Abstract]);
|
||||
// sequelizeConnection.addModels([DocumentXmlCache]);
|
||||
|
|
|
@ -17,6 +17,8 @@ import XmlModel from "../library/XmlModel";
|
|||
import Configuration from "../library/oai/OaiConfiguration";
|
||||
import ResumptionToken from "../library/oai/ResumptionToken";
|
||||
import TokenWorker from "../library/oai/TokenWorker";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
|
||||
interface XslTParameter {
|
||||
[key: string]: any;
|
||||
|
@ -53,6 +55,8 @@ export class OaiController {
|
|||
constructor() {
|
||||
this.proc = readFileSync(__dirname + "/datasetxml2oai.sef.json");
|
||||
this.configuration = new Configuration();
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
}
|
||||
|
||||
@Post("")
|
||||
|
@ -81,7 +85,7 @@ export class OaiController {
|
|||
let earliestDateFromDb;
|
||||
const firstPublishedDataset: Dataset | null = await Dataset.earliestPublicationDate();
|
||||
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;
|
||||
|
||||
const oaiRequest: OaiParameter = request.query;
|
||||
|
@ -157,7 +161,7 @@ export class OaiController {
|
|||
|
||||
// Set response time
|
||||
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();
|
||||
|
||||
// set OAI base url
|
||||
|
@ -446,15 +450,16 @@ export class OaiController {
|
|||
};
|
||||
includeArray.push(icncludeFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// const timeZone = "Europe/Vienna"; // Canonical time zone name
|
||||
// &from=2020-09-03&until2020-09-03
|
||||
// &from=2020-09-11&until=2021-05-11
|
||||
if ("from" in oaiRequest && "until" in oaiRequest) {
|
||||
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;
|
||||
let untilDate = dayjs(until);
|
||||
let untilDate = dayjs.tz(until, "Europe/Vienna"); //.tz(timeZone);
|
||||
if (!fromDate.isValid() || !untilDate.isValid()) {
|
||||
throw new OaiModelException(
|
||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||
|
@ -473,18 +478,25 @@ export class OaiController {
|
|||
fromDate.hour() == 0 && (fromDate = fromDate.startOf("day"));
|
||||
untilDate.hour() == 0 && (untilDate = untilDate.endOf("day"));
|
||||
|
||||
// format("YYYY-MM-DDTHH:mm:ss[Z]"));
|
||||
|
||||
andArray.push({
|
||||
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.gte]: fromDate.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)) {
|
||||
const from = oaiRequest["from"] as string;
|
||||
let fromDate = dayjs(from);
|
||||
let fromDate = dayjs.tz(from, "Europe/Vienna")
|
||||
if (!fromDate.isValid()) {
|
||||
throw new OaiModelException(
|
||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||
|
@ -511,7 +523,7 @@ export class OaiController {
|
|||
}
|
||||
} else if (!("from" in oaiRequest) && "until" in oaiRequest) {
|
||||
const until = oaiRequest["until"] as string;
|
||||
let untilDate = dayjs(until);
|
||||
let untilDate = dayjs.tz(until, "Europe/Vienna"); //.tz(timeZone);
|
||||
if (!untilDate.isValid()) {
|
||||
throw new OaiModelException(
|
||||
StatusCodes.INTERNAL_SERVER_ERROR,
|
||||
|
|
Loading…
Reference in New Issue
Block a user