Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed a bug where all due dates were being stored in EST

  • Loading branch information...
commit c9b9d3072e447c01aa42c0711f009418052aff12 1 parent 3187b65
@esseguin authored
View
7 app/models/Task.java
@@ -5,7 +5,6 @@
import java.util.UUID;
import play.data.validation.Constraints.Required;
-import siena.DateTime;
import siena.Entity;
import siena.Generator;
import siena.Id;
@@ -38,13 +37,11 @@
* The date that the task was added.
*/
@Required
- @DateTime @NotNull
- public Date addedDate = new Date();
+ public String addedDate = String.valueOf(new Date().getTime());
/**
- * Optional - The date that the task is due.
+ * Optional - The date that the task is due. This is stored as milliseconds since epoch
*/
- @DateTime
public String dueDate;
/**
View
15 app/models/TextMessageActor.java
@@ -1,7 +1,6 @@
package models;
import java.text.DateFormat;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
@@ -56,6 +55,7 @@ private void sendSMS(String toNumber, String fromNumber, String message) throws
@Override
public void onReceive(Object message) throws Exception {
if (message instanceof String && message.equals("tick")) {
+ System.out.println("tick");
sendNotifications();
} else {
unhandled(message);
@@ -73,13 +73,12 @@ private void sendNotifications() {
// Only send an SMS message if the task has a due date and phone number and we haven't
// sent a message yet.
if (!task.notificationSent && !task.dueDate.equals("") && !task.phone.equals("")) {
- DateFormat df = new SimpleDateFormat("M/d/y k:m");
- long addedSeconds = task.addedDate.getTime();
try {
- Date dueDate = df.parse(task.dueDate);
- long dueSeconds = dueDate.getTime();
- double cutoffSeconds = (dueSeconds - addedSeconds) * 0.2;
- double secondsLeft = dueSeconds - new Date().getTime();
+ Long dueMs = Long.parseLong(task.dueDate);
+ Long addedMs = Long.parseLong(task.addedDate);
+ Date dueDate = new Date(dueMs);
+ double cutoffSeconds = (dueMs - addedMs) * 0.2;
+ double secondsLeft = dueMs - new Date().getTime();
// If more than 80% of the total time has elapsed, send the SMS.
if (secondsLeft < cutoffSeconds) {
@@ -95,8 +94,6 @@ private void sendNotifications() {
task.notificationSent = true;
Task.update(task);
}
- } catch (ParseException e) {
- System.out.println("Error parsing date " + task.dueDate);
} catch (TwilioRestException e) {
System.out.println("Error Sending Text Message to number " + task.phone);
e.printStackTrace();
View
23 app/views/index.scala.html
@@ -5,7 +5,21 @@
@main("Todo List") {
<script>
$(function() {
- $('#dueDate').datetimepicker();
+ $('#dueDateStr').datetimepicker();
+ var dateVar = new Date();
+ var timezone = dateVar.getTimezoneOffset()/60 * (-1);
+ //alert(timezone);
+
+ $("#newTaskForm").submit(function() {
+ if ($("#dueDateStr").val()) {
+ var date = new Date($("#dueDateStr").val())
+ $("#dueDate").val(date.getTime())
+ } else {
+ $("#dueDate").val("")
+ }
+ //alert(date)
+ //return false;
+ })
});
</script>
@@ -26,9 +40,8 @@
task.dueDate match {
case "" =>
case _ => {
- val origFormat = new java.text.SimpleDateFormat("M/d/y k:m")
val goalFormat = new java.text.SimpleDateFormat("M/d 'at' h:mm a")
- val dueDate = origFormat.parse(task.dueDate)
+ val dueDate = new java.util.Date(java.lang.Long.parseLong(task.dueDate))
"due on " + goalFormat.format(dueDate)
}
}
@@ -73,10 +86,12 @@
<label for="dueDate">Due Date</label>
</dt>
<dd>
- <input type="text" name="dueDate" id="dueDate" value placeholder="Optional">
+ <input type="text" name="dueDateStr" id="dueDateStr" value placeholder="Optional">
</dd>
</dl>
+ <input type="hidden" name="dueDate" id="dueDate" />
+
@inputText(
field = taskForm("phone"),
args = '_label -> "Phone Number", 'placeholder -> "Optional"
View
1  app/views/main.scala.html
@@ -11,7 +11,6 @@
<script src="@routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@routes.Assets.at("javascripts/jquery-ui-1.8.18.custom.min.js")" type="text/javascript"></script>
<script src="@routes.Assets.at("javascripts/jquery-ui-timepicker.js")" type="text/javascript"></script>
- <script src="@routes.Assets.at("javascripts/tooltip.js")" type="text/javascript"></script>
</head>
<body>
<header>
Please sign in to comment.
Something went wrong with that request. Please try again.