Permalink
Browse files

Manual dates parsing.

  • Loading branch information...
Andrew Kirilenko
Andrew Kirilenko committed Apr 12, 2012
1 parent bd9d43d commit d64ac5d6d3f79cbc902445158e5e6785876841aa
@@ -0,0 +1,24 @@
+package io.iron.ironworker.client.entities;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class BaseEntity {
+ public Date parseDate(String s) {
+ try {
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+ return format.parse(s);
+ } catch (ParseException ignored) {
+ }
+
+ try {
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ return format.parse(s);
+ } catch (ParseException ignored) {
+ }
+
+ return null;
+ }
+}
@@ -4,7 +4,7 @@
import java.util.Date;
-public class CodeEntity {
+public class CodeEntity extends BaseEntity {
@SerializedName("id")
String id;
@SerializedName("project_id")
@@ -20,11 +20,11 @@
@SerializedName("latest_checksum")
String latestChecksum;
@SerializedName("latest_change")
- Date latestChange;
+ String latestChange;
@SerializedName("created_at")
- Date createdAt;
+ String createdAt;
@SerializedName("updated_at")
- Date updatedAt;
+ String updatedAt;
protected CodeEntity() {
}
@@ -58,14 +58,14 @@ public String getLatestChecksum() {
}
public Date getLatestChange() {
- return latestChange;
+ return parseDate(latestChange);
}
public Date getCreatedAt() {
- return createdAt;
+ return parseDate(createdAt);
}
public Date getUpdatedAt() {
- return updatedAt;
+ return parseDate(updatedAt);
}
}
@@ -4,7 +4,7 @@
import java.util.Date;
-public class CodeRevisionEntity {
+public class CodeRevisionEntity extends BaseEntity {
@SerializedName("id")
String id;
@SerializedName("project_id")
@@ -20,9 +20,9 @@
@SerializedName("rev")
int revision;
@SerializedName("created_at")
- Date createdAt;
+ String createdAt;
@SerializedName("updated_at")
- Date updatedAt;
+ String updatedAt;
protected CodeRevisionEntity() {
}
@@ -56,10 +56,10 @@ public int getRevision() {
}
public Date getCreatedAt() {
- return createdAt;
+ return parseDate(createdAt);
}
public Date getUpdatedAt() {
- return updatedAt;
+ return parseDate(updatedAt);
}
}
@@ -4,7 +4,7 @@
import java.util.Date;
-public class ScheduleEntity {
+public class ScheduleEntity extends BaseEntity {
@SerializedName("id")
String id;
@SerializedName("project_id")
@@ -14,31 +14,31 @@
@SerializedName("priority")
int priority;
@SerializedName("start_at")
- Date startAt;
+ String startAt;
@SerializedName("end_at")
- Date endAt;
+ String endAt;
@SerializedName("delay")
int delay;
@SerializedName("run_every")
int runEvery;
@SerializedName("run_times")
int runTimes;
@SerializedName("next_start")
- Date nextStart;
+ String nextStart;
@SerializedName("status")
String status;
@SerializedName("last_run_time")
- Date lastRunTime;
+ String lastRunTime;
@SerializedName("run_count")
int runCount;
@SerializedName("payload")
String payload;
@SerializedName("msg")
String msg;
@SerializedName("created_at")
- Date createdAt;
+ String createdAt;
@SerializedName("updated_at")
- Date updatedAt;
+ String updatedAt;
protected ScheduleEntity() {
}
@@ -60,11 +60,11 @@ public int getPriority() {
}
public Date getStartAt() {
- return startAt;
+ return parseDate(startAt);
}
public Date getEndAt() {
- return endAt;
+ return parseDate(endAt);
}
public int getDelay() {
@@ -80,15 +80,15 @@ public int getRunTimes() {
}
public Date getNextStart() {
- return nextStart;
+ return parseDate(nextStart);
}
public String getStatus() {
return status;
}
public Date getLastRunTime() {
- return lastRunTime;
+ return parseDate(lastRunTime);
}
public int getRunCount() {
@@ -104,10 +104,10 @@ public String getMsg() {
}
public Date getCreatedAt() {
- return createdAt;
+ return parseDate(createdAt);
}
public Date getUpdatedAt() {
- return updatedAt;
+ return parseDate(updatedAt);
}
}
@@ -4,7 +4,7 @@
import java.util.Date;
-public class TaskEntity {
+public class TaskEntity extends BaseEntity {
@SerializedName("id")
String id;
@SerializedName("project_id")
@@ -20,9 +20,9 @@
@SerializedName("status")
String status;
@SerializedName("start_time")
- Date startTime;
+ String startTime;
@SerializedName("end_time")
- Date endTime;
+ String endTime;
@SerializedName("duration")
int duration;
@SerializedName("run_times")
@@ -34,9 +34,9 @@
@SerializedName("msg")
String msg;
@SerializedName("created_at")
- Date createdAt;
+ String createdAt;
@SerializedName("updated_at")
- Date updatedAt;
+ String updatedAt;
protected TaskEntity() {
}
@@ -70,11 +70,11 @@ public String getStatus() {
}
public Date getStartTime() {
- return startTime;
+ return parseDate(startTime);
}
public Date getEndTime() {
- return endTime;
+ return parseDate(endTime);
}
public int getDuration() {
@@ -98,10 +98,10 @@ public String getMsg() {
}
public Date getCreatedAt() {
- return createdAt;
+ return parseDate(createdAt);
}
public Date getUpdatedAt() {
- return updatedAt;
+ return parseDate(updatedAt);
}
}

0 comments on commit d64ac5d

Please sign in to comment.