Skip to content
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

Merged
merged 36 commits into from
Apr 1, 2018
Merged

Conversation

whipermr5
Copy link
Member

@whipermr5 whipermr5 commented Mar 20, 2018

Fixes #84

Outline of Solution

  • Accept only geographical time zones from the session add/edit actions

  • New geographical time zone input UI

    • Sessions form
      screen shot 2018-03-23 at 10 51 28 pm
    • Add course panel
      screen shot 2018-03-23 at 10 49 22 pm
    • Edit course panel
      screen shot 2018-03-23 at 10 49 50 pm
  • Update UI to show time zone names instead of UTC offsets

    • Emails
      screen shot 2018-03-30 at 11 19 43 pm
    • Submission: session details panel screen shot 2018-03-30 at 5 36 36 pm
    • Results: session details panel (previously did not even show time zone)
      screen shot 2018-03-30 at 5 54 21 pm
    • Comment timestamps
      screen shot 2018-03-30 at 5 42 12 pm
    • Instructor home page not updated yet as this would make the sort by date even more broken than it already is; will fix after Instructor: home page: fix sort by date #7919
  • 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)

    • Close-up
      screen shot 2018-03-23 at 11 27 05 pm
    • Animation
      mar-23-2018 23-24-43
  • Validate local date times input by the user when adding/editing feedback sessions, checking for ambiguity

    • Resolve ambiguous date times using java.time default rules
    • Show a warning for each detected ambiguous date time
      screen shot 2018-03-22 at 2 51 23 am

Other Changes

  • A new exception type InvalidPostParametersException was added
    • NullPostParameterException extends InvalidPostParametersException
  • Feedback session add and edit actions now strictly validate POST parameters for cleaner code, throwing InvalidPostParametersException (and hence redirecting to the instructor home page) if any mischief (custom POST request crafting/ DOM manipulation) is detected (see 32eea36)

@whipermr5 whipermr5 added the s.Ongoing The PR is being worked on by the author(s) label Mar 20, 2018
@wkurniawan07
Copy link
Member

wkurniawan07 commented Mar 20, 2018

@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.

@whipermr5 whipermr5 force-pushed the 84-dst branch 9 times, most recently from 0c5310e to 93e131b Compare March 22, 2018 04:33
@whipermr5
Copy link
Member Author

@wkurniawan07 The one in the feedback session will eventually go, but not within this PR.

@whipermr5
Copy link
Member Author

@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">
Copy link
Contributor

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)`;
Copy link
Contributor

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?

Copy link
Member Author

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 ZoneIds. 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 ZoneIds 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.

Copy link
Contributor

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() {
Copy link
Contributor

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?

Copy link
Member Author

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);
Copy link
Contributor

@tran-tien-dat tran-tien-dat Mar 22, 2018

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.

Copy link
Member Author

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)
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@tran-tien-dat tran-tien-dat Mar 22, 2018

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:

  1. 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.
  2. 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
Copy link
Contributor

@tran-tien-dat tran-tien-dat Mar 22, 2018

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)

Copy link
Member

@darrenwee darrenwee left a 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 or OVERLAP
  • Sometimes timezone rules get changed by governments. It would also lead to either a GAP or OVERLAP 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 from UTC-11:00 to UTC+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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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

// 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";
Copy link
Contributor

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

Copy link
Member Author

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).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Nvm then.

@whipermr5
Copy link
Member Author

whipermr5 commented Mar 23, 2018

There is no test for a situation where the grace period causes responses to be accepted up to a time which is a GAP or OVERLAP

@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
Use short zone name instead of UTC offset
Temporary workaround to allow sorting to continue as per normal
@whipermr5 whipermr5 added s.ToMerge The PR is approved by all reviewers including final reviewer; ready for merging and removed s.FinalReview The PR is ready for final review labels Apr 1, 2018
@whipermr5 whipermr5 merged commit 76ab9a0 into TEAMMATES:master Apr 1, 2018
@whipermr5 whipermr5 deleted the 84-dst branch April 1, 2018 16:40
+ "<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>"
Copy link
Member

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?

Copy link
Member Author

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.

@whipermr5 whipermr5 added the c.Feature User-facing feature; can be new feature or enhancement to existing feature label Apr 14, 2018
jacoblipech pushed a commit to jacoblipech/teammates that referenced this pull request May 14, 2018
jacoblipech pushed a commit to jacoblipech/teammates that referenced this pull request Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c.Feature User-facing feature; can be new feature or enhancement to existing feature s.ToMerge The PR is approved by all reviewers including final reviewer; ready for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for daylight saving time
6 participants