-
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
Migrate FeedbackSessionAttributes time fields from Date to Instant #8628 #8629
Migrate FeedbackSessionAttributes time fields from Date to Instant #8628 #8629
Conversation
2c0d62e
to
1b103eb
Compare
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.
Most of it looks great to me 👍 Not sure if you wanna add javadocs for the boolean methods in FeedbackSessionAttributes
because I think some of their behavior is not super intuitive.
|
||
return now.after(startTime) && differenceBetweenDeadlineAndNow < hours; | ||
public boolean isClosedAfter(long hours) { | ||
return Instant.now().plus(Duration.ofHours(hours)).isAfter(endTime); | ||
} | ||
|
||
public boolean isClosingWithinTimeLimit(int hours) { |
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.
Change param type from int
to long
@@ -354,7 +333,7 @@ public boolean isPublished() { | |||
} else if (publishTime.equals(Const.TIME_REPRESENTS_NOW)) { | |||
return true; | |||
} else { | |||
return publishTime.before(now); | |||
return now.isAfter(publishTime) || now.equals(publishTime); |
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.
Use early returns instead for these if/elses?
@@ -1126,7 +1128,8 @@ protected void testAccessControl() throws Exception { | |||
|
|||
private void testGracePeriodAccessControlForStudents() { | |||
FeedbackSessionAttributes fs = typicalBundle.feedbackSessions.get("gracePeriodSession"); | |||
fs.setEndTime(TimeHelper.convertLocalDateToUtc(TimeHelper.getDateOffsetToCurrentTime(0), fs.getTimeZone())); | |||
fs.setEndTime(TimeHelper.convertLocalDateTimeToInstant( | |||
TimeHelperExtension.now(), TimeHelper.convertToZoneId(fs.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.
This logic seems long winded, probably a result of the fact that these times used to be in local time instead of UTC. Just fs.setEndTime(Instant.now())
would be sufficient here. Personally, I find TimeHelperExtension.now
very awkward, i.e. it shouldn't be there. Wherever it's used, I feel like it's because of the long-winded logic such as 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.
You're right; just tried and realised it isn't necessary for this test. However it's still needed in StudentHomePageUiTest
due to a problem with the test itself. In that test, the end time of Graced Feedback Session
is set to x
hours before the current time where x
is the zone offset for the session, such that when displayed in the user's time zone, it is printed as the current time in UTC. This is necessary for the test to pass due to broken time zone detection in HtmlHelper
, where it searches for the string UTC+xxxx
to detect the time zone. However, that particular page has no such string, so the zone is detected as UTC, and the search and replace for datetime.now
only matches the current time in UTC. Since this is a problem with the test, I will explicitly set it as such, and it can be fixed in a future PR. Will remove TimeHelperExtension#now
.
TIME_REPRESENTS_NOW = TimeHelper.parseInstant("1970-02-14 12:00 AM +0000"); | ||
TIME_REPRESENTS_DEFAULT_TIMESTAMP = TimeHelper.parseInstant("2011-01-01 12:00 AM +0000"); | ||
|
||
TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE = TimeHelper.convertInstantToDate(TIME_REPRESENTS_DEFAULT_TIMESTAMP); |
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.
Mark @Deprecated
?
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 field is marked deprecated a few lines up, during declaration.
e9a5a69
to
5a8931e
Compare
…f new method getInstantHoursOffsetFromNow
Deprecate TimeHelper.isSpecialTime(Date) in favour of new method isSpecialTime(Instant)
Remove now unused method isTimeWithinPeriod
AdminInstructorAccountAddAction: remove "update feedback session time" replace as it was not working anyway (no such string "2013-04-01 11:59 PM UTC" in the template InstructorSampleData.json)
Add TimeHelperExtension.now() utility method
Update TimeHelperExtension methods: Remove getInstantMillisOffsetFromNow in favour of new method getInstantMinutesOffsetFromNow Remove now unused convertToOptionValueInTimeDropDown(Date)
…ursOffsetToCurrentTime
…IMESTAMP_DATE and deprecate
5a8931e
to
3c4eb3a
Compare
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 😺
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
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.
Just a question.
+ "<span class=\"bold\">From:</span> 2012-01-31T16:00:00Z" | ||
+ "<span class=\"bold\"> to</span> 2014-12-31T16:00:00Z<br>" | ||
+ "<span class=\"bold\">Session visible from:</span> 2011-12-31T16:00:00Z<br>" | ||
+ "<span class=\"bold\">Results visible from:</span> 1970-06-22T00:00:00Z<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.
I remember a recent PR changed our date display format to a 'universally understood' format. Are we reversing that here?
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; this is just the admin logging system. It uses toString
on the timestamps. The default toString
implementation for Instant
results in this format.
teammates/src/main/java/teammates/ui/controller/InstructorFeedbackAddAction.java
Lines 69 to 76 in 4d8b090
statusToAdmin = | |
"New Feedback Session <span class=\"bold\">(" + fs.getFeedbackSessionName() + ")</span> for Course " | |
+ "<span class=\"bold\">[" + fs.getCourseId() + "]</span> created.<br>" | |
+ "<span class=\"bold\">From:</span> " + fs.getStartTime() | |
+ "<span class=\"bold\"> to</span> " + fs.getEndTime() + "<br>" | |
+ "<span class=\"bold\">Session visible from:</span> " + fs.getSessionVisibleFromTime() + "<br>" | |
+ "<span class=\"bold\">Results visible from:</span> " + fs.getResultsVisibleFromTime() + "<br><br>" | |
+ "<span class=\"bold\">Instructions:</span> " + fs.getInstructions(); |
Fixes #8628
Script used to migrate timestamps in JSON data: