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

Display comment time in the session's time zone #4488 #7616

Conversation

Mynk96
Copy link
Contributor

@Mynk96 Mynk96 commented Jun 27, 2017

Fixes #4488

@Mynk96
Copy link
Contributor Author

Mynk96 commented Jun 27, 2017

Ready For Review!

@leeyimin leeyimin added the s.ToReview The PR is waiting for review(s) label Jun 27, 2017
@whipermr5 whipermr5 requested a review from leeyimin June 27, 2017 11:01
Copy link
Contributor

@leeyimin leeyimin left a comment

Choose a reason for hiding this comment

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

Some issues to be solved before I can give a more detailed review!

@@ -300,6 +300,7 @@ public static FeedbackResponseCommentSearchResultBundle fromResults(
frcDb.deleteDocument(comment);
continue;
}
bundle.sessionTimeZone = session.getTimeZone();
Copy link
Contributor

Choose a reason for hiding this comment

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

The time zone of the bundle would be the time zone of the session of the last document in the filtered results. If there are multiple sessions in the filtered result, the time zone of certain comment rows may be wrong.

mapDoubleToId("12.0", "Pacific/Auckland");
mapDoubleToId("12.75", "Pacific/Chatham");
mapDoubleToId("13.0", "Pacific/Tongatapu");
mapDoubleToId("14.0", "Pacific/Kiritimati");
Copy link
Contributor

Choose a reason for hiding this comment

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

This may not be the best way to translate the double to a TimeZone object. I tested with some of the time zones which corresponded to the US cities in the list and DST was taken in account (eg. UTC -0800 shows up as -0700), which may be unexpected for users.

https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html
Using the custom time zone ID may be more appropriate here, and it can be generated by code as well.

@leeyimin leeyimin added s.Ongoing The PR is being worked on by the author(s) and removed s.ToReview The PR is waiting for review(s) labels Jun 29, 2017
@Mynk96
Copy link
Contributor Author

Mynk96 commented Jun 29, 2017

@leeyimin Can you please have a look at the build error!

public Map<String, String> responseGiverTable = new HashMap<String, String>();
public Map<String, String> responseRecipientTable = new HashMap<String, String>();
public Set<String> instructorEmails = new HashSet<String>();
public Map<String, String> instructorEmailNameTable = new HashMap<String, String>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all these changes necessary?

@@ -300,9 +300,11 @@ public static FeedbackResponseCommentSearchResultBundle fromResults(
frcDb.deleteDocument(comment);
continue;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Revert the added new line.

if (minutes != 0) {
offset = Integer.toString(hours) + ":" + Integer.toString(minutes);
}
String timeZone = TimeZone.getTimeZone("GMT" + sign + 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.

Should extract this part as a separate method.

@@ -358,7 +358,7 @@
<li class="list-group-item list-group-item-warning" id="responseCommentRow-0-1-0-1-1">
<div id="commentBar-0-1-0-1-1">
<span class="text-muted">
From: Teammates Test [${datetime.now}]
From: Teammates Test [Fri, 30 Jun 2017, 05:24 AM +0800]
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to update the replaceUnpredictableValuesWithPlaceholders method in HtmlHelper. As the time zone of the comment time has changed, the HtmlHelper is unable to replace occurrences of current time correctly. One solution I can think of now is to loop through all possible time zones and replace all possible current time representations with the placeholder. Would be good if you can find a better solution 😂

Copy link
Member

Choose a reason for hiding this comment

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

Ideal case: detect the time zone and replace with ${datetime.now.utc+8}

@leeyimin leeyimin 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 Jul 4, 2017
@Mynk96
Copy link
Contributor Author

Mynk96 commented Jul 4, 2017

@leeyimin Still working please don't review it now!

@@ -385,6 +389,8 @@ private static String suppressVariationsInInjectedValues(String content) {
private static String replaceUnpredictableValuesWithPlaceholders(String content) {
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy, ");
//A page can have only one time zone as we cannot have session with two different time zones.
Copy link
Contributor

Choose a reason for hiding this comment

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

A page can have two time zones since instructor comments can show comments from different courses and sessions. You may want to correct your comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

You should only mention that the time zone of expected dateTimeNow is taken from the content.

Matcher matcher = pattern.matcher(content);
//set default timezone offset.
String timeZoneOffset = "+0000";
while (matcher.find()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is while used here?

@@ -36,9 +39,10 @@
private static final String REGEX_BLOB_KEY = "(encoded_gs_key:)?[a-zA-Z0-9-_]{10,}";
private static final String REGEX_QUESTION_ID = "[a-zA-Z0-9-_]{40,}";
private static final String REGEX_COMMENT_ID = "[0-9]{16}";
private static final String REGEX_DISPLAY_TIME = "(0[0-9]|1[0-2]):[0-5][0-9] [AP]M( UTC)?";
private static final String REGEX_DISPLAY_TIME = "(0[0-9]|1[0-2]):[0-5][0-9] [AP]M?|NOON";
Copy link
Contributor

Choose a reason for hiding this comment

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

The regex should be improved, it matches "12:00 A", "NOON" but not "12:00 NOON".

Pattern pattern = Pattern.compile(REGEX_TIMEZONE_OFFSET);
Matcher matcher = pattern.matcher(content);
//set default timezone offset.
//set default time zone offset.
String timeZoneOffset = "+0000";
while (matcher.find()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the content will have comments from single time zone, I am finding the last word with Pattern 'UTC+XXXX` and extracting time zone offset from it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the last word with UTC+XXXX used, not the first one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because using pattern +xxxx it also matches string such as responseCommentRow-1234567812345678 in the content file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you can simply use the first word of UTC+XXXX. Is there any reason you must use the last one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can also use the first one.

@@ -385,6 +389,8 @@ private static String suppressVariationsInInjectedValues(String content) {
private static String replaceUnpredictableValuesWithPlaceholders(String content) {
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy, ");
//Get session's time zone from content.
Copy link
Contributor

@leeyimin leeyimin Jul 18, 2017

Choose a reason for hiding this comment

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

You should mention in the comment that this assumes that the page only shows one timezone as it is possible for a page to show multiple time zones (eg. InstructorSearchPage) and this method may not work for such a page.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a space after // and use lower case for get.

}

private static TimeZone getTimeZone(String content) {
//Searches for last String of pattern "UTC+0800" in the content.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment does not seem relevant. You should not be searching for "UTC+8000" in particular.

@@ -36,9 +39,10 @@
private static final String REGEX_BLOB_KEY = "(encoded_gs_key:)?[a-zA-Z0-9-_]{10,}";
private static final String REGEX_QUESTION_ID = "[a-zA-Z0-9-_]{40,}";
private static final String REGEX_COMMENT_ID = "[0-9]{16}";
private static final String REGEX_DISPLAY_TIME = "(0[0-9]|1[0-2]):[0-5][0-9] [AP]M( UTC)?";
private static final String REGEX_DISPLAY_TIME = "(0[0-9]|1[0-2]):[0-5][0-9] ([AP]M?|NOON)";
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the ? after M is unnecessary?

}

private static String removeUtc(String timeZoneOffset) {
return timeZoneOffset.substring(0, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

The method can be improved, it should still work for time zones which are not integer offsets (eg. +0330).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is just converting string from UTC+xxxx to xxxx.

Copy link
Contributor

@leeyimin leeyimin Jul 18, 2017

Choose a reason for hiding this comment

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

I believe you are taking the first 2 characters of timeZoneOffset, which means it does not even work for time zones other than +0000.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I am searching for the last string with a pattern as UTC+xxxx and then extracting +xxxx from it.For example, timeZoneOffset is UTC-0330 then this will return -0330.

Copy link
Contributor

Choose a reason for hiding this comment

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

By matching group 1, and not group 0, you are already extracting +xxxx. Please read up on methods you use as well, String.substring(int beginIndex, int endIndex) returns the first 2 characters. It does not remove the first three characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies. I have improved the method.

@Mynk96
Copy link
Contributor Author

Mynk96 commented Jul 18, 2017

@leeyimin Please Review!

}

private static TimeZone getTimeZone(String content) {
// searches for last String of pattern "UTC+xxxx" in the content.
Copy link
Contributor

Choose a reason for hiding this comment

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

Update your comment.

@@ -385,6 +389,8 @@ private static String suppressVariationsInInjectedValues(String content) {
private static String replaceUnpredictableValuesWithPlaceholders(String content) {
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy, ");
// get session's time zone from content.
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention that this assumes only the page only shows time in one time zones, there are pages which can show multiple time zones (eg. InstructorSearchPage) and this method may not work on such pages.

// searches for last String of pattern "UTC+xxxx" in the content.
Pattern pattern = Pattern.compile(REGEX_TIMEZONE_OFFSET);
Matcher matcher = pattern.matcher(content);
//set default time zone offset.
Copy link
Contributor

Choose a reason for hiding this comment

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

space after //.

@@ -385,6 +389,9 @@ private static String suppressVariationsInInjectedValues(String content) {
private static String replaceUnpredictableValuesWithPlaceholders(String content) {
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy, ");
// get session's time zone from content (content here includes pages only with one 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.

content here includes pages only with one time zone is not accurate. Remove this part?

Copy link
Contributor Author

@Mynk96 Mynk96 Jul 18, 2017

Choose a reason for hiding this comment

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

Should I replace it with something or // get session's time zone from content. is fine?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that would be fine.

Copy link
Contributor

@leeyimin leeyimin left a comment

Choose a reason for hiding this comment

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

LGTM!

@leeyimin leeyimin added s.FinalReview The PR is ready for final review and removed s.Ongoing The PR is being worked on by the author(s) labels Jul 18, 2017
@leeyimin leeyimin requested a review from damithc July 18, 2017 07:05
@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 Jul 18, 2017
@whipermr5 whipermr5 added this to the V5.110 milestone Jul 18, 2017
@leeyimin leeyimin added the e.4 label Jul 18, 2017
public static TimeZone getTimeZoneFromDoubleOffset(double sessionTimeZone) {
int hours = (int) sessionTimeZone;
int minutes = (int) ((Math.abs(sessionTimeZone) - Math.floor(Math.abs(sessionTimeZone))) * 60);
return TimeZone.getTimeZone(String.format("GMT%+03d:%02d", hours, minutes));
Copy link
Member

@HirdayGupta HirdayGupta Jul 18, 2017

Choose a reason for hiding this comment

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

Could you maybe change from GMT to UTC? As UTC is the time standard used in TEAMMATES and it is unaffected by Daylight savings.

Copy link
Member

@whipermr5 whipermr5 Jul 18, 2017

Choose a reason for hiding this comment

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

The Java TimeZone object only accepts GMT. Note that this method returns a TimeZone, not a string.

Copy link
Member

Choose a reason for hiding this comment

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

Ohh I see. Its okay then I guess. :)

@whipermr5 whipermr5 merged commit 4257d89 into TEAMMATES:master Jul 18, 2017
HirdayGupta added a commit to HirdayGupta/teammates that referenced this pull request Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Display comment time in the session's time zone
5 participants