-
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
Display comment time in the session's time zone #4488 #7616
Display comment time in the session's time zone #4488 #7616
Conversation
Ready For Review! |
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.
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(); |
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 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"); |
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.
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.
…ttps://github.com/Mynk96/teammates into 4488-Display-comment-time-in-the-session-time-zone
@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>(); |
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.
Are all these changes necessary?
@@ -300,9 +300,11 @@ public static FeedbackResponseCommentSearchResultBundle fromResults( | |||
frcDb.deleteDocument(comment); | |||
continue; | |||
} | |||
|
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.
Revert the added new line.
if (minutes != 0) { | ||
offset = Integer.toString(hours) + ":" + Integer.toString(minutes); | ||
} | ||
String timeZone = TimeZone.getTimeZone("GMT" + sign + offset).getID(); |
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 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] |
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.
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 😂
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.
Ideal case: detect the time zone and replace with ${datetime.now.utc+8}
@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. |
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.
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.
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.
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()) { |
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.
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"; |
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 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()) { |
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.
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.
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.
Why is the last word with UTC+XXXX
used, not the first one?
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.
because using pattern +xxxx
it also matches string such as responseCommentRow-1234
567812345678 in the content file.
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 believe you can simply use the first word of UTC+XXXX
. Is there any reason you must use the last one?
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, 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. |
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.
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.
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 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. |
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.
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)"; |
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 believe the ?
after M
is unnecessary?
} | ||
|
||
private static String removeUtc(String timeZoneOffset) { | ||
return timeZoneOffset.substring(0, 2); |
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 method can be improved, it should still work for time zones which are not integer offsets (eg. +0330).
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.
This method is just converting string from UTC+xxxx
to xxxx
.
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 believe you are taking the first 2 characters of timeZoneOffset
, which means it does not even work for time zones other than +0000.
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.
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
.
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.
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.
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.
Apologies. I have improved the method.
@leeyimin Please Review! |
} | ||
|
||
private static TimeZone getTimeZone(String content) { | ||
// searches for last String of pattern "UTC+xxxx" in the content. |
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.
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. |
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.
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. |
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.
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). |
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.
content here includes pages only with one time zone
is not accurate. Remove this part?
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 I replace it with something or // get session's time zone from content.
is fine?
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, that would be fine.
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.
LGTM!
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)); |
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.
Could you maybe change from GMT to UTC? As UTC is the time standard used in TEAMMATES and it is unaffected by Daylight savings.
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 Java TimeZone
object only accepts GMT
. Note that this method returns a TimeZone
, not a string.
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.
Ohh I see. Its okay then I guess. :)
…ffset Using the method added by @Mynk96 in TEAMMATES#7616
Fixes #4488