Skip to content

Commit

Permalink
[#8636] Migrate *Attributes time fields from Date to Instant (#8637)
Browse files Browse the repository at this point in the history
  • Loading branch information
whipermr5 committed Mar 14, 2018
1 parent 30f0012 commit dbca7a2
Show file tree
Hide file tree
Showing 53 changed files with 303 additions and 297 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package teammates.common.datatransfer.attributes;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import teammates.common.util.Assumption;
Expand All @@ -24,7 +24,7 @@ public class AccountAttributes extends EntityAttributes<Account> {
public boolean isInstructor;
public String email;
public String institute;
public Date createdAt;
public Instant createdAt;
public StudentProfileAttributes studentProfile;

AccountAttributes() {
Expand Down Expand Up @@ -57,7 +57,7 @@ public Builder() {
accountAttributes = new AccountAttributes();
}

public Builder withCreatedAt(Date createdAt) {
public Builder withCreatedAt(Instant createdAt) {
accountAttributes.createdAt = createdAt;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package teammates.common.datatransfer.attributes;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.google.appengine.api.datastore.Text;
Expand All @@ -23,13 +22,13 @@ public class AdminEmailAttributes extends EntityAttributes<AdminEmail> {
public Text content;

// Optional fields
public Date sendDate;
public Date createDate;
public Instant sendDate;
public Instant createDate;
public String emailId;
public boolean isInTrashBin;

AdminEmailAttributes() {
createDate = Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE;
createDate = Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP;
emailId = Const.ParamsNames.ADMIN_EMAIL_ID;
}

Expand Down Expand Up @@ -118,11 +117,11 @@ public String getSubject() {
return this.subject;
}

public Date getSendDate() {
public Instant getSendDate() {
return this.sendDate;
}

public Date getCreateDate() {
public Instant getCreateDate() {
return this.createDate;
}

Expand All @@ -138,20 +137,13 @@ public String getSendDateForDisplay() {
if (this.sendDate == null) {
return "Draft";
}

Calendar cal = Calendar.getInstance();
cal.setTime(this.sendDate);
cal = TimeHelper.convertToUserTimeZone(cal, Const.SystemParams.ADMIN_TIME_ZONE_DOUBLE);

return TimeHelper.formatTime12H(cal.getTime());
return TimeHelper.formatTime12H(TimeHelper.convertInstantToLocalDateTime(
this.sendDate, Const.SystemParams.ADMIN_TIME_ZONE_ID));
}

public String getCreateDateForDisplay() {
Calendar cal = Calendar.getInstance();
cal.setTime(this.createDate);
cal = TimeHelper.convertToUserTimeZone(cal, Const.SystemParams.ADMIN_TIME_ZONE_DOUBLE);

return TimeHelper.formatTime12H(cal.getTime());
return TimeHelper.formatTime12H(TimeHelper.convertInstantToLocalDateTime(
this.createDate, Const.SystemParams.ADMIN_TIME_ZONE_ID));
}

public String getFirstAddressReceiver() {
Expand Down Expand Up @@ -179,14 +171,14 @@ public Builder(String subject, List<String> addressReceiver, List<String> groupR
adminEmailAttributes.content = content;
}

public Builder withSendDate(Date sendDate) {
public Builder withSendDate(Instant sendDate) {
if (sendDate != null) {
adminEmailAttributes.sendDate = sendDate;
}
return this;
}

public Builder withCreateDate(Date createDate) {
public Builder withCreateDate(Instant createDate) {
if (createDate != null) {
adminEmailAttributes.createDate = createDate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package teammates.common.datatransfer.attributes;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.json.JSONException;
Expand Down Expand Up @@ -40,8 +40,8 @@ public class FeedbackQuestionAttributes extends EntityAttributes<FeedbackQuestio
public List<FeedbackParticipantType> showResponsesTo;
public List<FeedbackParticipantType> showGiverNameTo;
public List<FeedbackParticipantType> showRecipientNameTo;
protected transient Date createdAt;
protected transient Date updatedAt;
protected transient Instant createdAt;
protected transient Instant updatedAt;
private String feedbackQuestionId;

public FeedbackQuestionAttributes() {
Expand Down Expand Up @@ -95,12 +95,12 @@ public FeedbackQuestionAttributes getCopy() {
return new FeedbackQuestionAttributes(this);
}

public Date getCreatedAt() {
return createdAt == null ? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE : createdAt;
public Instant getCreatedAt() {
return createdAt == null ? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP : createdAt;
}

public Date getUpdatedAt() {
return updatedAt == null ? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE : updatedAt;
public Instant getUpdatedAt() {
return updatedAt == null ? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP : updatedAt;
}

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package teammates.common.datatransfer.attributes;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import com.google.appengine.api.datastore.Text;
Expand Down Expand Up @@ -40,8 +40,8 @@ public class FeedbackResponseAttributes extends EntityAttributes<FeedbackRespons
public Text responseMetaData;
public String giverSection;
public String recipientSection;
protected transient Date createdAt;
protected transient Date updatedAt;
protected transient Instant createdAt;
protected transient Instant updatedAt;
private String feedbackResponseId;

public FeedbackResponseAttributes() {
Expand Down Expand Up @@ -101,12 +101,12 @@ public void setId(String feedbackResponseId) {
this.feedbackResponseId = feedbackResponseId;
}

public Date getCreatedAt() {
return createdAt == null ? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE : createdAt;
public Instant getCreatedAt() {
return createdAt == null ? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP : createdAt;
}

public Date getUpdatedAt() {
return updatedAt == null ? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE : updatedAt;
public Instant getUpdatedAt() {
return updatedAt == null ? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP : updatedAt;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package teammates.common.datatransfer.attributes;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -32,9 +32,9 @@ public class FeedbackResponseCommentAttributes extends EntityAttributes<Feedback
public List<FeedbackParticipantType> showCommentTo;
public List<FeedbackParticipantType> showGiverNameTo;
public boolean isVisibilityFollowingFeedbackQuestion;
public Date createdAt;
public Instant createdAt;
public String lastEditorEmail;
public Date lastEditedAt;
public Instant lastEditedAt;
public Long feedbackResponseCommentId;
public String giverSection;
public String receiverSection;
Expand All @@ -45,7 +45,7 @@ public class FeedbackResponseCommentAttributes extends EntityAttributes<Feedback
showCommentTo = new ArrayList<>();
showGiverNameTo = new ArrayList<>();
isVisibilityFollowingFeedbackQuestion = true;
createdAt = new Date();
createdAt = Instant.now();
}

public static FeedbackResponseCommentAttributes valueOf(FeedbackResponseComment comment) {
Expand Down Expand Up @@ -215,7 +215,7 @@ public Builder withVisibilityFollowingFeedbackQuestion(Boolean visibilityFollowi
return this;
}

public Builder withCreatedAt(Date createdAt) {
public Builder withCreatedAt(Instant createdAt) {
if (createdAt != null) {
frca.createdAt = createdAt;
}
Expand All @@ -230,7 +230,7 @@ public Builder withLastEditorEmail(String lastEditorEmail) {
return this;
}

public Builder withLastEditedAt(Date lastEditedAt) {
public Builder withLastEditedAt(Instant lastEditedAt) {
frca.lastEditedAt = lastEditedAt == null
? frca.createdAt
: lastEditedAt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package teammates.common.datatransfer.attributes;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import com.google.common.base.Strings;
Expand Down Expand Up @@ -37,15 +37,15 @@ public class StudentAttributes extends EntityAttributes<CourseStudent> {
* Creation and update time stamps.
* Updated automatically in Student.java, jdoPreStore()
*/
private transient Date createdAt;
private transient Date updatedAt;
private transient Instant createdAt;
private transient Instant updatedAt;

StudentAttributes() {
googleId = "";
section = Const.DEFAULT_SECTION;
updateStatus = StudentUpdateStatus.UNKNOWN;
createdAt = Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE;
updatedAt = Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE;
createdAt = Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP;
updatedAt = Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP;
}

public static StudentAttributes valueOf(CourseStudent student) {
Expand Down Expand Up @@ -279,19 +279,19 @@ public String getStudentStatus() {
return Const.STUDENT_COURSE_STATUS_YET_TO_JOIN;
}

public Date getCreatedAt() {
public Instant getCreatedAt() {
return createdAt;
}

public Date getUpdatedAt() {
public Instant getUpdatedAt() {
return updatedAt;
}

public void setCreatedAt(Date createdAt) {
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}

public void setUpdatedAt(Date updatedAt) {
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}

Expand Down Expand Up @@ -392,17 +392,17 @@ public Builder withUpdateStatus(StudentUpdateStatus updateStatus) {
return this;
}

public Builder withCreatedAt(Date createdAt) {
Date dateToAdd = createdAt == null
? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE
public Builder withCreatedAt(Instant createdAt) {
Instant dateToAdd = createdAt == null
? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP
: createdAt;
studentAttributes.setCreatedAt(dateToAdd);
return this;
}

public Builder withUpdatedAt(Date updatedAt) {
Date dateToAdd = updatedAt == null
? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE
public Builder withUpdatedAt(Instant updatedAt) {
Instant dateToAdd = updatedAt == null
? Const.TIME_REPRESENTS_DEFAULT_TIMESTAMP
: updatedAt;
studentAttributes.setUpdatedAt(dateToAdd);
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package teammates.common.datatransfer.attributes;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.google.appengine.api.blobstore.BlobKey;
Expand Down Expand Up @@ -31,7 +31,7 @@ public class StudentProfileAttributes extends EntityAttributes<StudentProfile> {
public String gender; // only accepts "male", "female" or "other"
public String moreInfo;
public String pictureKey;
public Date modifiedDate;
public Instant modifiedDate;

StudentProfileAttributes(String googleId) {
this.googleId = googleId;
Expand All @@ -42,7 +42,7 @@ public class StudentProfileAttributes extends EntityAttributes<StudentProfile> {
this.gender = "other";
this.moreInfo = "";
this.pictureKey = "";
this.modifiedDate = new Date();
this.modifiedDate = Instant.now();
}

public static StudentProfileAttributes valueOf(StudentProfile sp) {
Expand Down Expand Up @@ -233,8 +233,8 @@ public Builder withPictureKey(String pictureKey) {
return this;
}

public Builder withModifiedDate(Date modifiedDate) {
profileAttributes.modifiedDate = modifiedDate == null ? new Date() : modifiedDate;
public Builder withModifiedDate(Instant modifiedDate) {
profileAttributes.modifiedDate = modifiedDate == null ? Instant.now() : modifiedDate;
return this;
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/teammates/common/util/Const.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package teammates.common.util;

import java.time.Instant;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -98,9 +98,6 @@ public final class Const {
public static final Instant TIME_REPRESENTS_NOW;
public static final Instant TIME_REPRESENTS_DEFAULT_TIMESTAMP;

@Deprecated
public static final Date TIME_REPRESENTS_DEFAULT_TIMESTAMP_DATE;

public static final String ERROR_FEEDBACK_EMAIL_SUBJECT = "User-submitted Error Report";

static {
Expand All @@ -110,8 +107,6 @@ public final class Const {
TIME_REPRESENTS_LATER = TimeHelper.parseInstant("1970-01-01 12:00 AM +0000");
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);
}

/*
Expand Down Expand Up @@ -143,7 +138,12 @@ public static class SystemParams {
/* Field sizes and error messages for invalid fields can be found
* in the FieldValidator class.
*/
public static final String ADMIN_TIME_ZONE = "Asia/Singapore";

// TODO: rename back to ADMIN_TIME_ZONE once the String version has been deleted
public static final ZoneId ADMIN_TIME_ZONE_ID = ZoneId.of("Asia/Singapore");
@Deprecated // use ZoneId version
public static final String ADMIN_TIME_ZONE = ADMIN_TIME_ZONE_ID.getId();
@Deprecated // use ZoneId version
public static final double ADMIN_TIME_ZONE_DOUBLE = 8.0;

public static final TimeZone TIME_ZONE = TimeZone.getTimeZone("UTC");
Expand Down
Loading

0 comments on commit dbca7a2

Please sign in to comment.