HyeonJun Jeon

[FIx] Date location UTC to local

......@@ -25,12 +25,10 @@ function process(sche, k, v) {
case "DTSTART":
sche.scheType = "time";
sche.date = getDatestr(v);
k = "startTime";
v = getTimestr(v);
break;
return;
case "DTEND":
k = "endTime";
v = sche.startTime;
v = getTimestr_z(v);
break;
case "DTSTART;VALUE=DATE":
sche.scheType = "date";
......@@ -73,14 +71,29 @@ function insert(str, idxs, char) {
return nstr;
}
/**
* parse DateString
* @param {string} str "YYYYMMDDTHHMMSS"
* @returns {string} "YYYY-MM-DD"
*/
function getDatestr(str) {
const a = str.substring(0, str.indexOf("T"));
return insert(a, [4, 6, 8], "-");
}
function getTimestr(str) {
const b = str.substring(str.indexOf("T") + 1);
return insert(b, [2, 4, 6], ":");
/**
* parse ZDateString
* @param {string} zstr "YYYYMMDDTHHMMSSZ" (UTC)
* @returns {string} "HH:MM:SS" (UTC+9)
*/
function getTimestr_z(zstr) {
const it = zstr.indexOf("T");
const a = zstr.substring(0, it);
const b = zstr.substring(it + 1, zstr.length - 1);
const date = new Date(
insert(a, [4, 6, 8], "-") + "T" + insert(b, [2, 4, 6], ":") + "+00:00"
);
return date.toTimeString().substring(0, 8);
}
// const fdata = fs.readFileSync("C:/Users/teddy/Downloads/data.ics", "utf8");
......