|
33 | 33 | const reduced_rule = document.getElementById(`${name}.reduced_scoring_date_id`);
|
34 | 34 | if (reduced_rule) groupRules.splice(1, 0, [reduced_rule]);
|
35 | 35 |
|
36 |
| - // Compute the time difference between the current browser timezone and the course timezone. |
| 36 | + // Compute the time difference between a time in the browser timezone and the same time in the course timezone. |
37 | 37 | // flatpickr gives the time in the browser's timezone, and this is used to adjust to the course timezone.
|
38 |
| - // Note that this is in seconds. |
39 |
| - const timezoneAdjustment = |
40 |
| - new Date(new Date().toLocaleString('en-US')).getTime() - |
41 |
| - new Date( |
42 |
| - new Date().toLocaleString('en-US', { timeZone: open_rule.dataset.timezone ?? 'America/New_York' }) |
43 |
| - ).getTime(); |
| 38 | + // Note that the input time is in seconds and output times is in milliseconds. |
| 39 | + const timezoneAdjustment = (time) => { |
| 40 | + const dateTime = new Date(0); |
| 41 | + dateTime.setUTCSeconds(time); |
| 42 | + return ( |
| 43 | + new Date(dateTime.toLocaleString('en-US')).getTime() - |
| 44 | + new Date( |
| 45 | + dateTime.toLocaleString('en-US', { timeZone: open_rule.dataset.timezone ?? 'America/New_York' }) |
| 46 | + ).getTime() |
| 47 | + ); |
| 48 | + }; |
44 | 49 |
|
45 | 50 | for (const rule of groupRules) {
|
46 | 51 | const classValue = document.getElementsByName(`${rule[0].name}.class_value`)[0]?.dataset.classValue;
|
47 | 52 | const value = rule[0].value || classValue;
|
48 |
| - rule.push(value ? parseInt(value) * 1000 - timezoneAdjustment : 0); |
49 |
| - if (classValue) rule.push(parseInt(classValue) * 1000 - timezoneAdjustment); |
| 53 | + rule.push(value ? parseInt(value) * 1000 - timezoneAdjustment(parseInt(value)) : 0); |
| 54 | + if (classValue) rule.push(parseInt(classValue) * 1000 - timezoneAdjustment(parseInt(classValue))); |
50 | 55 | }
|
51 | 56 |
|
52 | 57 | const update = (input) => {
|
|
156 | 161 | parseDate(datestr, format) {
|
157 | 162 | // Deal with the case of a unix timestamp. The timezone needs to be adjusted back as this is for
|
158 | 163 | // the unix timestamp stored in the hidden input whose value will be sent to the server.
|
159 |
| - if (format === 'U') return new Date(parseInt(datestr) * 1000 - timezoneAdjustment); |
| 164 | + if (format === 'U') |
| 165 | + return new Date(parseInt(datestr) * 1000 - timezoneAdjustment(parseInt(datestr))); |
160 | 166 |
|
161 | 167 | // Next attempt to parse the datestr with the current format. This should not be adjusted. It is
|
162 | 168 | // for display only.
|
|
171 | 177 | formatDate(date, format) {
|
172 | 178 | // In this case the date provided is in the browser's time zone. So it needs to be adjusted to the
|
173 | 179 | // timezone of the course.
|
174 |
| - if (format === 'U') return (date.getTime() + timezoneAdjustment) / 1000; |
| 180 | + if (format === 'U') return (date.getTime() + timezoneAdjustment(date.getTime() / 1000)) / 1000; |
175 | 181 |
|
176 | 182 | return luxon.DateTime.fromMillis(date.getTime()).toFormat(
|
177 | 183 | datetimeFormats[luxon.Settings.defaultLocale]
|
|
0 commit comments