Showing
1 changed file
with
20 additions
and
7 deletions
| ... | @@ -25,12 +25,10 @@ function process(sche, k, v) { | ... | @@ -25,12 +25,10 @@ function process(sche, k, v) { |
| 25 | case "DTSTART": | 25 | case "DTSTART": |
| 26 | sche.scheType = "time"; | 26 | sche.scheType = "time"; |
| 27 | sche.date = getDatestr(v); | 27 | sche.date = getDatestr(v); |
| 28 | - k = "startTime"; | 28 | + return; |
| 29 | - v = getTimestr(v); | ||
| 30 | - break; | ||
| 31 | case "DTEND": | 29 | case "DTEND": |
| 32 | k = "endTime"; | 30 | k = "endTime"; |
| 33 | - v = sche.startTime; | 31 | + v = getTimestr_z(v); |
| 34 | break; | 32 | break; |
| 35 | case "DTSTART;VALUE=DATE": | 33 | case "DTSTART;VALUE=DATE": |
| 36 | sche.scheType = "date"; | 34 | sche.scheType = "date"; |
| ... | @@ -73,14 +71,29 @@ function insert(str, idxs, char) { | ... | @@ -73,14 +71,29 @@ function insert(str, idxs, char) { |
| 73 | return nstr; | 71 | return nstr; |
| 74 | } | 72 | } |
| 75 | 73 | ||
| 74 | +/** | ||
| 75 | + * parse DateString | ||
| 76 | + * @param {string} str "YYYYMMDDTHHMMSS" | ||
| 77 | + * @returns {string} "YYYY-MM-DD" | ||
| 78 | + */ | ||
| 76 | function getDatestr(str) { | 79 | function getDatestr(str) { |
| 77 | const a = str.substring(0, str.indexOf("T")); | 80 | const a = str.substring(0, str.indexOf("T")); |
| 78 | return insert(a, [4, 6, 8], "-"); | 81 | return insert(a, [4, 6, 8], "-"); |
| 79 | } | 82 | } |
| 80 | 83 | ||
| 81 | -function getTimestr(str) { | 84 | +/** |
| 82 | - const b = str.substring(str.indexOf("T") + 1); | 85 | + * parse ZDateString |
| 83 | - return insert(b, [2, 4, 6], ":"); | 86 | + * @param {string} zstr "YYYYMMDDTHHMMSSZ" (UTC) |
| 87 | + * @returns {string} "HH:MM:SS" (UTC+9) | ||
| 88 | + */ | ||
| 89 | +function getTimestr_z(zstr) { | ||
| 90 | + const it = zstr.indexOf("T"); | ||
| 91 | + const a = zstr.substring(0, it); | ||
| 92 | + const b = zstr.substring(it + 1, zstr.length - 1); | ||
| 93 | + const date = new Date( | ||
| 94 | + insert(a, [4, 6, 8], "-") + "T" + insert(b, [2, 4, 6], ":") + "+00:00" | ||
| 95 | + ); | ||
| 96 | + return date.toTimeString().substring(0, 8); | ||
| 84 | } | 97 | } |
| 85 | 98 | ||
| 86 | // const fdata = fs.readFileSync("C:/Users/teddy/Downloads/data.ics", "utf8"); | 99 | // const fdata = fs.readFileSync("C:/Users/teddy/Downloads/data.ics", "utf8"); | ... | ... |
-
Please register or login to post a comment