Skip to content

Commit ed157c1

Browse files
committed
add mechanism to prepend (next day) if converted time goes to the next day
1 parent 45a1505 commit ed157c1

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

_includes/timezone_converter.html

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,35 @@
99
}
1010
if (fromTimezone !== toTimezone) {
1111
const timeText = elem.innerHTML;
12+
let fromDateText = elem.dataset.date;
13+
if (!fromDateText)
14+
fromDateText = "2020-04-13";
15+
/* conversion */
1216
const [validFromTimezone, utcOffset] = getValidTimezone(fromTimezone);
13-
const dateTimeString = "2020-04-13T" + reformatTimeString(timeText) + utcOffset;
17+
const dateTimeString = reformatTimeString(timeText, fromDateText) + utcOffset;
1418
const [validToTimezone,offset] = getValidTimezone(toTimezone);
1519
const converted = new Date(dateTimeString).toLocaleString("en-GB", {timeZone: validToTimezone});
20+
/* check date of converted time and add (next day) string to result if +1 day */
21+
const convertedDateOnly = new Date(dateTimeString).toLocaleString("en-GB", {timeZone: validToTimezone, year:'numeric', month:'2-digit', day:'2-digit'});
22+
let toDateText = convertedDateOnly.split('/');
23+
toDateText = [toDateText[2], toDateText[1], toDateText[0]].join('-');
1624
const newTimeArray = converted.split(" ")[1].split(":");
17-
const newTime = newTimeArray[0] + ":" + newTimeArray[1];
25+
let newTime = newTimeArray[0] + ":" + newTimeArray[1];
26+
if (toDateText > fromDateText)
27+
newTime += " (next day)";
28+
/* set new value */
1829
elem.innerHTML = newTime;
1930
elem.dataset.timezone = toTimezone;
31+
elem.dataset.date = toDateText;
2032
}
2133
}
2234
}
23-
function reformatTimeString(timeString) {
24-
const re = /(\d?\d:\d\d)(am|pm|AM|PM)?/;
35+
36+
/*
37+
Convert date time string into a format accepted by Date object
38+
*/
39+
function reformatTimeString(timeString, dateString) {
40+
const re = /(\d?\d:\d\d)(am|pm|AM|PM)?( \(next day\))?/;
2541
const parsed = timeString.match(re);
2642
if (parsed) {
2743
const hourMinArray = parsed[1].split(":");
@@ -33,7 +49,10 @@
3349
}
3450
}
3551
const hourString = hour.toString().padStart(2, '0');
36-
return hourString + ":" + hourMinArray[1];
52+
if (dateString)
53+
return dateString + "T" + hourString + ":" + hourMinArray[1];
54+
else
55+
return "2020-04-13T" + hourString + ":" + hourMinArray[1];
3756
}
3857
else
3958
return null

workshops/EEGLAB_2021_UCSD.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Below is a still-provisional program for the 2021 Virtual EEGLAB Workshop (sugge
109109
110110
## WEDNESDAY, June 16th (paid registration required)
111111

112-
- <span style="color: black">7:00am7:45 – **ICA decomposition PRACTICUM** (Johanna Wagner)</span>
112+
- <span style="color: black"><span class="time" data-timezone="PDT">7:00am</span>–<span class="time" data-timezone="PDT">7:45</span>**ICA decomposition PRACTICUM** (Johanna Wagner)</span>
113113

114114
- <span style="color: black"><span class="time" data-timezone="PDT">8:00am</span>–<span class="time" data-timezone="PDT">9:00</span> – **Forward &amp; inverse head modeling** (Zeynep Aakalin Acar)</span>
115115

@@ -137,7 +137,7 @@ Below is a still-provisional program for the 2021 Virtual EEGLAB Workshop (sugge
137137
138138
## THURSDAY, June 17th (paid registration required)
139139

140-
- <span style="color: black">7:00am7:45 – **ICA clustering PRACTICUM** (Julie Onton)</span>
140+
- <span style="color: black"><span class="time" data-timezone="PDT">7:00am</span>–<span class="time" data-timezone="PDT">7:45</span>**ICA clustering PRACTICUM** (Julie Onton)</span>
141141

142142
- <span style="color: black"><span class="time" data-timezone="PDT">8:00am</span>-<span class="time" data-timezone="PDT">9:00</span> – **EEGLAB group analysis** (Arnaud Delorme)</span>
143143

0 commit comments

Comments
 (0)