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

Migrate feedback session timeZone field to ZoneId #8638 #8639

Merged
merged 9 commits into from
Mar 15, 2018

Conversation

whipermr5
Copy link
Member

@whipermr5 whipermr5 commented Mar 14, 2018

Fixes #8638

Based on #8637. Commits start from 9b921d0.

Script used to migrate JSON data:

import json
import os, io
from collections import OrderedDict

def to_utc_format(offset):
    if offset == 0:
        return 'UTC'
    hours = int(offset)
    minutes = int(abs(offset - hours) * 60)
    return 'UTC%+03d:%02d' % (hours, minutes)

filenames = [f for f in os.listdir('.') if os.path.isfile(f) and f.endswith('.json')]

for filename in filenames:
    print(filename)
    with open(filename) as file:
        data = json.loads(file.read(), object_pairs_hook=OrderedDict)

    try:
        if not data.get('feedbackSessions'):
            continue
    except:
        continue

    for fsKey, fs in data.get('feedbackSessions').iteritems():
        for key, val in fs.iteritems():
            if key in ['timeZone']:
                fs[key] = to_utc_format(fs[key])

    with io.open(filename, 'w', encoding='utf8') as file:
        file.write(json.dumps(data, indent=2, separators=(',', ': '), ensure_ascii=False) + '\n')

@whipermr5 whipermr5 added the s.Ongoing The PR is being worked on by the author(s) label Mar 14, 2018
@whipermr5 whipermr5 force-pushed the 8638-migrate-fs-timeZone-field branch 3 times, most recently from 3ca7cf9 to 411ddae Compare March 14, 2018 11:55
@whipermr5 whipermr5 added s.ToReview The PR is waiting for review(s) and removed s.Ongoing The PR is being worked on by the author(s) labels Mar 14, 2018
@whipermr5 whipermr5 force-pushed the 8638-migrate-fs-timeZone-field branch from 411ddae to dff2968 Compare March 14, 2018 15:15
Copy link
Contributor

@tran-tien-dat tran-tien-dat left a comment

Choose a reason for hiding this comment

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

Most of my comments are about this one thing: I think we should use something like ZoneId.of("+08:00") in instead of TimeHelper.convertToZoneId, as the later should be removed eventually once we finished migrating our UI and Database to ZoneId eventually.

@@ -170,7 +168,7 @@ private void setTimeZoneFromOffsetIfRequired() {
} else {
offset = Double.valueOf(timeZone);
}
timeZone = convertOffsetToZoneId(offset);
timeZone = TimeHelper.convertToZoneId(offset).getId();
Copy link
Contributor

Choose a reason for hiding this comment

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

Are isTimeStoredInUtc and timeZoneDouble ready to be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not yet; still pending a migration script (#8448) but it's not that high priority.

email = new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForStudent(session, student1, time);
subject = String.format(EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject(), course.getName(),
session.getFeedbackSessionName());
verifyEmail(email, student1.email, subject, "/sessionSubmissionConfirmationEmailPositiveTimeZone.html");

setTimeZoneButMaintainLocalDate(session, -9.5);
setTimeZoneButMaintainLocalDate(session, TimeHelper.convertToZoneId(-9.5));
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 should generate a ZoneId directly, i.e. something like "-09:30". convertToZoneId is just a temporary method, eventually we want to remove all instances of double timezones

@@ -50,7 +51,7 @@ protected void prepareTestData() {
.withInstructions(new Text("Please fill in the new feedback session."))
.withSentOpenEmail(false)
.withSentPublishedEmail(false)
.withTimeZone(8.0)
.withTimeZone(TimeHelper.convertToZoneId(8))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use something like ZoneId.of("+08:00")? convertToZoneId should be removed eventually.

@@ -295,7 +296,7 @@ private void testAddAction() throws Exception {

newSession.setFeedbackSessionName("Allow Early Viewing Session #");
newSession.setCourseId("CFeedbackUiT.CS1101");
newSession.setTimeZone(-4.5);
newSession.setTimeZone(TimeHelper.convertToZoneId(-4.5));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use something like ZoneId.of("-04:30")? convertToZoneId should be removed eventually.

@@ -342,7 +343,7 @@ private void testAddAction() throws Exception {
newSession.setResultsVisibleFromTime(Const.TIME_REPRESENTS_NEVER);
newSession.setGracePeriod(25);
newSession.setInstructions(instructions);
newSession.setTimeZone(-2);
newSession.setTimeZone(TimeHelper.convertToZoneId(-2));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use something like ZoneId.of("-02:00")? convertToZoneId should be removed eventually.

@@ -946,7 +947,7 @@ private void testValidationReload() throws Exception {
TimeHelper.parseLocalDateTime("01/04/2035", "10", "00"),
TimeHelper.parseLocalDateTime("30/04/2035", "22", "00"),
null, null,
newSession.getInstructions(), newSession.getGracePeriod(), -2.0);
newSession.getInstructions(), newSession.getGracePeriod(), TimeHelper.convertToZoneId(-2));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use something like ZoneId.of("-02:00")? convertToZoneId should be removed eventually.

@@ -42,7 +41,8 @@ protected void prepareTestData() {
FeedbackSessionAttributes gracedFeedbackSession =
BackDoor.getFeedbackSession("SHomeUiT.CS2104", "Graced Feedback Session");
// TODO: change to actual now once HTML time zone detection is fixed
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you document it somewhere, e.g. issues in case we forget this later?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just did - #8640.

@@ -72,7 +72,8 @@ public void testBuilderCopy() {
.withEndTime(TimeHelperExtension.getInstantHoursOffsetFromNow(5))
.withSessionVisibleFromTime(TimeHelperExtension.getInstantHoursOffsetFromNow(1))
.withResultsVisibleFromTime(TimeHelperExtension.getInstantHoursOffsetFromNow(6))
.withTimeZone(8).withGracePeriod(0).withFeedbackSessionType(FeedbackSessionType.PRIVATE)
.withTimeZone(TimeHelper.convertToZoneId(8)).withGracePeriod(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use something like ZoneId.of("+08:00")? convertToZoneId should be removed eventually.

@@ -680,7 +681,7 @@ private void testEnrollStudents() throws Exception {
.withEndTime(TimeHelperExtension.getInstantHoursOffsetFromNow(5))
.withSessionVisibleFromTime(TimeHelperExtension.getInstantHoursOffsetFromNow(1))
.withResultsVisibleFromTime(TimeHelperExtension.getInstantHoursOffsetFromNow(6))
.withTimeZone(8)
.withTimeZone(TimeHelper.convertToZoneId(8))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use something like ZoneId.of("+08:00")? convertToZoneId should be removed eventually.

addFeedbackSessionWithTimeZone(
feedbackSessionName, courseId, startTime, endTime, visibleTime, publishTime, instructions, gracePeriod, 8.0);
addFeedbackSessionWithTimeZone(feedbackSessionName, courseId, startTime, endTime, visibleTime, publishTime,
instructions, gracePeriod, TimeHelper.convertToZoneId(8));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use something like ZoneId.of("+08:00")? convertToZoneId should be removed eventually.

@tran-tien-dat
Copy link
Contributor

Lol my comments point to error pages because of rebase.

@whipermr5
Copy link
Member Author

whipermr5 commented Mar 14, 2018

I think we should use something like ZoneId.of("+08:00") in instead of TimeHelper.convertToZoneId, as the later should be removed eventually once we finished migrating our UI and Database to ZoneId eventually.

@tran-tien-dat I did think of that, but decided that we'll want to relook all of the test time zone data when we eventually support geographical region ZoneIds - it should have a good mix of both fixed offset zones and regional zones that undergo DST. Hence, I used convertToZoneId as a way to mark all the test data where a fixed zone is hardcoded in test code.

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.

👍 Just a query, otherwise all good from me.

@@ -52,6 +53,8 @@
respondingInstructorList = new HashSet<>();
respondingStudentList = new HashSet<>();

timeZone = ZoneId.of("UTC");
Copy link
Member

Choose a reason for hiding this comment

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

Should this be extracted to Const as something like DEFAULT_TIME_ZONE? A similar fall back is used in CoursesDb.

@whipermr5 whipermr5 force-pushed the 8638-migrate-fs-timeZone-field branch from dff2968 to 5f6b959 Compare March 14, 2018 15:48
@tran-tien-dat
Copy link
Contributor

I did think of that, but decided that we'll want to relook all of the test time zone data when we eventually support geographical region ZoneIds - it should have a good mix of both fixed offset zones and regional zones that undergo DST. Hence, I used convertToZoneId as a way to mark all the test data where a fixed zone is hardcoded in test code.

I don't think that's necessary. I took a look and most of these fixed time zones come from the page ui tests. When we migrate the UI front-end to use geographical timezones, these tests will necessarily need to be updated to pick the geographical timezones. Hence, the current hardcoded double timezones are just temporary until we finish migration as well. Well that also means the changes I'm suggesting will also be modified eventually, so just keep it like what you did is fine.

@tran-tien-dat
Copy link
Contributor

tran-tien-dat commented Mar 14, 2018

Hmm, but for the 3 occurences of hardcoded timezones in the logic tests StudentsLogicTest.java, FeedbackSessionAttributesTest.java, EmailGeneratorTest.java, time zones don't play much of any significant roles. They are just "check whether things have been copied correctly" kind of tests, so any time zones would be fine. You can just use geographical timezones here as well.

Furthermore, UTC time zones are currently hardcoded without the convertToZoneId anyway. So beside the reasons above, for consistency's sake, I revert back to my opinion that we should remove convertToZoneId from hard-coded timezones. Things that may get screwed up by DST time zones should have new tests for them.

EDIT: time zone does play a role in EmailGeneratorTest.java, but the test is explicitly testing for negative time zone, i.e. offset-based rather than geographical, so there's no point to mark this as potential place to change to using DST time zones. Instead, new tests should be written for DST geographical time zone here.

Copy link
Contributor

@tran-tien-dat tran-tien-dat left a comment

Choose a reason for hiding this comment

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

LGTM

@whipermr5 whipermr5 added s.FinalReview The PR is ready for final review and removed s.ToReview The PR is waiting for review(s) labels Mar 14, 2018
@whipermr5 whipermr5 requested a review from damithc March 14, 2018 16:12
@tran-tien-dat
Copy link
Contributor

@whipermr5 Travis is failing due to unused import 😛

@damithc damithc 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 Mar 15, 2018
@whipermr5 whipermr5 merged commit 6573c90 into TEAMMATES:master Mar 15, 2018
@whipermr5 whipermr5 deleted the 8638-migrate-fs-timeZone-field branch March 15, 2018 01:30
@whipermr5 whipermr5 added the c.Task Other non-user-facing works, e.g. refactoring, adding tests label Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c.Task Other non-user-facing works, e.g. refactoring, adding tests 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.

4 participants