2022-05-17 22:47:58 +02:00
|
|
|
const debug=require('debug')('utils');
|
|
|
|
|
|
|
|
function findSubStr(str, start, end) {
|
|
|
|
var index = str.slice(start, end);
|
2022-05-18 12:42:16 +02:00
|
|
|
//debug('index: '+index);
|
2022-05-17 22:47:58 +02:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
function gtfsDate2NodeDate(date){
|
|
|
|
let start = 0;
|
|
|
|
let end = 4;
|
|
|
|
let year=findSubStr(date, start, end);
|
2022-05-18 12:42:16 +02:00
|
|
|
//debug('year: '+year);
|
2022-05-17 22:47:58 +02:00
|
|
|
start=4;
|
|
|
|
end=6;
|
|
|
|
let month=findSubStr(date, start, end);
|
2022-05-18 12:42:16 +02:00
|
|
|
//debug('month: '+month);
|
2022-05-17 22:47:58 +02:00
|
|
|
start=6;
|
|
|
|
end=8;
|
|
|
|
let day=findSubStr(date, start, end);
|
2022-05-18 12:42:16 +02:00
|
|
|
//debug('day: '+day);
|
2022-05-17 22:47:58 +02:00
|
|
|
let nodeDate = new Date(year, month - 1, day);
|
2022-05-18 12:42:16 +02:00
|
|
|
//debug('nodeDate: '+nodeDate);
|
2022-05-17 22:47:58 +02:00
|
|
|
return nodeDate;
|
|
|
|
}
|
|
|
|
|
2022-05-18 12:42:16 +02:00
|
|
|
const dateWeekday={
|
|
|
|
sunday:0,
|
|
|
|
monday:1,
|
|
|
|
tuesday:2,
|
|
|
|
wednesday:3,
|
|
|
|
thursday:4,
|
|
|
|
friday:5,
|
|
|
|
saturday:6
|
|
|
|
}
|
|
|
|
|
|
|
|
function nextDay(epoch){
|
|
|
|
debug('epoch: '+epoch);
|
|
|
|
let epochNext=epoch + (24 * 60 * 60 * 1000) // 1 day in millisecond
|
|
|
|
debug('epochNext: '+epochNext);
|
|
|
|
return epochNext;
|
|
|
|
}
|
|
|
|
|
2022-05-17 22:47:58 +02:00
|
|
|
module.exports={
|
2022-05-18 12:42:16 +02:00
|
|
|
gtfsDate2NodeDate,
|
|
|
|
nextDay,
|
|
|
|
dateWeekday
|
2022-05-17 22:47:58 +02:00
|
|
|
};
|