Commit 071b4267 authored by Tobinsk's avatar Tobinsk
Browse files

Merge branch '6-wrong-topic' into 'master'

Resolve "Wrong topic"

Closes #6

See merge request histhub/wikidata-normalizer!14
parents 16b96555 e1d1df30
......@@ -126,20 +126,27 @@ class WikiNormalizer extends Transform {
* @param {string} calendar
* @returns {number}
*/
private convertTimestamp(time: string, calendar: string) {
private convertTimestamp(time: string | null, calendar: string) {
if (time !== null) {
// build timestamp
let date: Date = toDateObject(time);
// wikidata uses julian and gregorian calendar. We need to transform the dates into a common timestamp
// more info: https://www.wikidata.org/wiki/Help:Dates
// Q1985727 = gregorianCalendar
// Q1985786 == julian calendar
let date: Date = toDateObject(time);
if (calendar.indexOf('Q1985786') > -1) {
date = new Date(converter.fromJulianToGregorian(date.getFullYear(), date.getMonth() - 1, date.getDate()));
// if the precision of the date is year the day is 0. but we need a value from 1-31.
let day = date.getDate();
if (day === 0) {
day = 1;
}
date = new Date(converter.fromJulianToGregorian(date.getFullYear(), date.getMonth() + 1, day));
}
// get timestamp (seconds from start)
return date.getTime() / 1000;
}
return null;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment