-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for daylight saving time #84 #8687
Conversation
@whipermr5 may not be directly related, but do you still plan to keep both the timezone fields of the feedback session or course? Surely one of them has got to go. |
0c5310e
to
93e131b
Compare
@wkurniawan07 The one in the feedback session will eventually go, but not within this PR. |
@tran-tien-dat @darrenwee Y'all can do an early review first; I'm left with UI tests and new tooltips/warnings to make it more obvious to existing instructors that we've started supporting DST. |
</select> | ||
<input type="button" class="btn btn-primary" id="auto-detect-time-zone" value="Auto-Detect Time Zone"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember correctly, for course there are some texts to explain to the user that the timezone is automatically detected. I think it's good to have here too
$selectElement.val(timeZone); | ||
if (moment.tz.names().indexOf(timeZone) === -1) { | ||
const o = document.createElement('option'); | ||
o.text = `${timeZone} (please select one of the above options)`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, what's the purpose of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For existing sessions that use fixed offset ZoneId
s. The fixed offset ID will be displayed here as the final option, and the user will have to select a proper regional time zone to be able to save the feedback session (fixed offset ZoneId
s are disallowed at the action level by the backend). This will be more obvious once I've added a warning to the user to choose another option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you can add a comment to remind that it's for backward compatibility.
@@ -126,11 +130,30 @@ function formatSessionVisibilityGroup() { | |||
}); | |||
} | |||
|
|||
function initializeTimeZoneOptions() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use this in the course time zone selection as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though the course edit page will have to be modified. I'll try and if the changes are not too extensive, I'll include them in this PR.
} catch (DateTimeException e) { | ||
log.warning("Failed to parse time zone parameter: " + paramTimeZone); | ||
} | ||
Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_TIMEZONE, paramTimeZone); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. From the comments at the beginning of this function: this field can be null
when editting feedback session. Yet another problem: when we create a FeedbackSessionAttributes
it will always have a non-null time zone. So if the user doesn't want to change the timezone, the backend actually resets the timezone to default.
I think FeedbackSessionAttributes
shouldn't be used to transfer data for the edit action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes; ideally the flow should be to get the existing session attributes, then update the changed fields. However I feel this is outside the scope of this PR.
try { | ||
attributes.setTimeZone(ZoneId.of(paramTimeZone)); | ||
} catch (DateTimeException e) { | ||
// Leave the attributes time zone field at its default valid value (i.e. UTC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problematic, as my previous comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the only reason why the POST param would be null or invalid is mischief from the user, so I don't view this refactoring as important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you missed my point in the previous comment. null
POST param is valid when editting feedbacksession. It means do not change this field. But here we are updating the field to UTC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you that from the practical point of view, if the front end always send data with all these fields, then none of these exceptions will happen when the user is using the website. However, from the developer's point of view, this class is problematic because the code is contradicting with the comments (specifically the comments at the start of extractFeedbackSessionData
). This will lead to confusion for future developer who reads the code, as well as some inconsistencies in the code, e.g. why does it only require time zone
to not be null
? How about start time, end time, etc.? So the comment only applies to the times but not the time zone?
One thing that definitely needs to be fixed is that the comments have to match what the code is doing. So I can see 2 choices here:
- Backend assumes frontend will send every fields. Then we can consistently require not-null for all fields and remove many of these
isCreatingNewSession
clauses that make things more complicated. - Keep the code as it is and update in the comments that timezone must always be supplied, but other fields can be null, in which case the field will not be updated.
if (!timeZoneErrorMessage.isEmpty()) { | ||
// Collect other errors before throwing an exception | ||
List<String> errors = new ArrayList<>(); | ||
// When editing an existing session, this will fail as some fields might be validly set to null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or timezone field might be validly set to null and fails the validation as well (i.e. same problems as in extractFeedbackSessionData
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks 👍
- There is no test for a situation with an overlap start time. I don't think it's super necessary, so your discretion.
- There is no test for a situation where the grace period causes responses to be accepted up to a time which is a
GAP
orOVERLAP
- Sometimes timezone rules get changed by governments. It would also lead to either a
GAP
orOVERLAP
situation too, but isn't caused by daylight savings. Should we test this too? The most extreme example I could find is Samoa which switched her standard time fromUTC-11:00
toUTC+13:00
in 2011.
|
||
params[25] = "Europe/Andorra"; | ||
params[5] = "Sun, 25 Mar, 2012"; | ||
params[7] = "2"; // Sun 25 Mar, 2012, 02:00 AM falls in the gap period when clocks sprang forward in Andorra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add context for self-contained doc:
After Sunday, 25 March, 2012 01:59:59 AM, clocks were moved forward to become Sunday, 25 March, 2012 03:00:00 AM
params[5] = "Sun, 25 Mar, 2012"; | ||
params[7] = "2"; // Sun 25 Mar, 2012, 02:00 AM falls in the gap period when clocks sprang forward in Andorra | ||
params[9] = "Sun, 28 Oct, 2012"; | ||
params[11] = "2"; // Sun 28 Oct, 2012, 02:00 AM falls in the overlap period when clocks fell back in Andorra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above:
After Sunday, 28 October, 2012 02:59:59 AM: clocks were moved backward to become Sunday, 28 October, 2012 02:00:00 AM
instructor1ofCourse1.courseId, "Course with DST time zone"); | ||
params[25] = "Asia/Jerusalem"; | ||
params[9] = "Fri, 28 Mar, 2014"; | ||
params[11] = "2"; // Fri 28 Mar, 2014, 02:00 AM falls in the gap period when clocks sprang forward in Israel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add context for self-contained comment:
After Friday, 28 March, 2014 01:59:59 AM: clocks were moved forward to become Friday, 28 March, 2014 03:00:00 AM
instructor1ofCourse1.courseId, longFsName, 1); | ||
params[25] = "Asia/Jerusalem"; | ||
params[21] = "Sun, 25 Oct, 2015"; | ||
params[23] = "1"; // Sun 25 Oct, 2015, 01:00 AM falls in the overlap period when clocks fell back in Israel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add context for self-contained doc:
After Sunday, 25 October, 2015 01:59:59 AM: clocks were moved backward to become Sunday, 25 October, 2015 01:00:00 AM
0b78240
to
30b531f
Compare
// without accounts need to receive the email to be able to respond | ||
feedbackSession.setOpeningEmailEnabled(true); | ||
// This is only for validation to pass; it will be overridden with its existing value at the logic layer | ||
String dummyCreatorEmail = "dummy@example.com"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to not use a dummy value. Can extract the instructor from line 23 and use instructor.email
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instructor may not be the creator (e.g. a co-owner).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Nvm then.
@darrenwee Can explain this more? I don't think it's necessary as end time is an instant and grace period is a duration that is compared with now and the instant to determine whether the session is closed? |
…d edit panels Use input group for neater auto-detect button placement Remove redundant "Select a timezone..." option
Include select element in HTML tests but remove options Useful to check tooltip, selected time zone and disabled attributes
Superclass of NullPostParameterException
Remove isCreatingNewSession flag Throw burden of sanitising name and supplying course ID and creator email to users of the method Assert all relevant post parameters not null using getNonNullRequestParamValue Throw InvalidPostParametersException if any mischief is detected Accept responsibility for setting opening email enabled flag to true Remove unnecessary setting of sent open and published email flags as these are already false by default Always set created time to now since this will be overridden for updating of existing sessions anyway Also remove isCreatingNewSession flag from validateTimeData Remove an unused parameter name constant that was never set in the frontend
…ixed offset modal warning
Use short zone name instead of UTC offset
Temporary workaround to allow sorting to continue as per normal
+ "<span class=\"bold\">From:</span> 2012-01-31T22:00:00Z" | ||
+ "<span class=\"bold\"> to</span> 2014-03-28T00:00:00Z<br>" | ||
+ "<span class=\"bold\">Session visible from:</span> 2011-12-31T22:00:00Z<br>" | ||
+ "<span class=\"bold\">Results visible from:</span> 1970-06-22T00:00:00Z<br><br>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@whipermr5 I was resolving the conflicts in #8447, Wanted to know how you chose these dates. Specially session Visible from
and results visible from
dates. I mean does these particular dates signify something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are defined in Const.java
.
Fixes #84
Outline of Solution
Accept only geographical time zones from the session add/edit actions
New geographical time zone input UI
Update UI to show time zone names instead of UTC offsets
Fixed-offset time zones are still valid from the logic layer downwards so existing sessions continue to work as per normal
Show a modal warning when editing existing sessions, prompting users to re-save the session with the new geographical time zone (auto-detected)
Validate local date times input by the user when adding/editing feedback sessions, checking for ambiguity
java.time
default rulesOther Changes
InvalidPostParametersException
was addedNullPostParameterException
extendsInvalidPostParametersException
InvalidPostParametersException
(and hence redirecting to the instructor home page) if any mischief (custom POST request crafting/ DOM manipulation) is detected (see 32eea36)