김창근 2014-07-30
move expandDueDate to JodaDateUtil
@9daf1fdcd8895d4236d516ea8b9f2d6da133e2d9
app/controllers/IssueApp.java
--- app/controllers/IssueApp.java
+++ app/controllers/IssueApp.java
@@ -353,8 +353,7 @@
             }
 
             if (issueMassUpdate.isDueDateChanged) {
-                issue.dueDate = issueMassUpdate.dueDate;
-                issue.expandDueDate();
+                issue.dueDate = JodaDateUtil.lastSecondOfDay(issueMassUpdate.dueDate);
             }
 
             issue.updatedDate = JodaDateUtil.now();
@@ -413,7 +412,7 @@
         addLabels(newIssue, request());
         setMilestone(issueForm, newIssue);
 
-        newIssue.expandDueDate();
+        newIssue.dueDate = JodaDateUtil.lastSecondOfDay(newIssue.dueDate);
         newIssue.save();
 
         attachUploadFilesToPost(newIssue.asResource());
@@ -503,7 +502,7 @@
         final Issue issue = issueForm.get();
         removeAnonymousAssignee(issue);
         setMilestone(issueForm, issue);
-        issue.expandDueDate();
+        issue.dueDate = JodaDateUtil.lastSecondOfDay(issue.dueDate);
 
         final Issue originalIssue = Issue.findByNumber(project, number);
 
app/models/Issue.java
--- app/models/Issue.java
+++ app/models/Issue.java
@@ -157,14 +157,6 @@
         }
     }
 
-    public void expandDueDate() {
-        if (dueDate != null) {
-            dueDate = DateUtils.setHours(dueDate, 23);
-            dueDate = DateUtils.setMinutes(dueDate, 59);
-            dueDate = DateUtils.setSeconds(dueDate, 59);
-        }
-    }
-
     /**
      * @see #updateAssignee()
      */
app/utils/JodaDateUtil.java
--- app/utils/JodaDateUtil.java
+++ app/utils/JodaDateUtil.java
@@ -86,4 +86,17 @@
     public static int localDaysBetween(Date from, Date to) {
         return Days.daysBetween(new DateTime(from).toLocalDate(), new DateTime(to).toLocalDate()).getDays();
     }
+
+    /**
+     * Force update HH:mm:ss -> 23:59:59
+     */
+    public static Date lastSecondOfDay(Date date) {
+        if (date == null) {
+            return null;
+        }
+        DateTime dateTime = new DateTime(date);
+        return dateTime.withField(DateTimeFieldType.hourOfDay(), 23)
+                .withField(DateTimeFieldType.minuteOfHour(), 59)
+                .withField(DateTimeFieldType.secondOfMinute(), 59).toDate();
+    }
 }
Add a comment
List