diff --git a/src/main/java/net/rcarz/jiraclient/Field.java b/src/main/java/net/rcarz/jiraclient/Field.java index 2519492..51e6da2 100644 --- a/src/main/java/net/rcarz/jiraclient/Field.java +++ b/src/main/java/net/rcarz/jiraclient/Field.java @@ -146,6 +146,8 @@ public final class Field { public static final String WORKLOG = "worklog"; public static final String TIME_ESTIMATE = "timeestimate"; public static final String TIME_SPENT = "timespent"; + public static final String CREATED_DATE = "created"; + public static final String UPDATED_DATE = "updated"; public static final String DATE_FORMAT = "yyyy-MM-dd"; public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; @@ -237,6 +239,24 @@ public final class Field { return result; } + /** + * Gets a date with a time from the given object. + * + * @param d a string representation of a date + * + * @return a Date instance or null if d isn't a string + */ + public static Date getDateTime(Object d) { + Date result = null; + + if (d instanceof String) { + SimpleDateFormat df = new SimpleDateFormat(DATETIME_FORMAT); + result = df.parse((String)d, new ParsePosition(0)); + } + + return result; + } + /** * Gets an floating-point number from the given object. * diff --git a/src/main/java/net/rcarz/jiraclient/Issue.java b/src/main/java/net/rcarz/jiraclient/Issue.java index 133c835..281675e 100644 --- a/src/main/java/net/rcarz/jiraclient/Issue.java +++ b/src/main/java/net/rcarz/jiraclient/Issue.java @@ -381,6 +381,8 @@ public class Issue extends Resource { private List workLogs = null; private Integer timeEstimate = null; private Integer timeSpent = null; + private Date createdDate = null; + private Date updatedDate = null; /** * Creates an issue from a JSON payload. @@ -431,6 +433,8 @@ public class Issue extends Resource { workLogs = Field.getWorkLogs(fields.get(Field.WORKLOG), restclient); timeEstimate = Field.getInteger(fields.get(Field.TIME_ESTIMATE)); timeSpent = Field.getInteger(fields.get(Field.TIME_SPENT)); + createdDate = Field.getDateTime(fields.get(Field.CREATED_DATE)); + updatedDate = Field.getDateTime(fields.get(Field.UPDATED_DATE)); } private static String getRestUri(String key) { @@ -1197,5 +1201,14 @@ public class Issue extends Resource { public Integer getTimeEstimate() { return timeEstimate; } + + public Date getCreatedDate() { + return createdDate; + } + + public Date getUpdatedDate() { + return updatedDate; + } + } diff --git a/src/test/java/net/rcarz/jiraclient/IssueTest.java b/src/test/java/net/rcarz/jiraclient/IssueTest.java index 760deb1..d6f6d61 100644 --- a/src/test/java/net/rcarz/jiraclient/IssueTest.java +++ b/src/test/java/net/rcarz/jiraclient/IssueTest.java @@ -8,6 +8,8 @@ import static org.junit.Assert.assertNotNull; import java.util.List; import java.util.Map; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; import org.junit.Assert; import org.junit.Test; @@ -121,4 +123,17 @@ public class IssueTest { assertEquals(new Integer(144000), issue.getTimeEstimate()); assertEquals(new Integer(86400), issue.getTimeSpent()); } + + @Test + public void testCreatedDate(){ + Issue issue = new Issue(null,Utils.getTestIssue()); + assertEquals(new DateTime(2013, 9, 29, 20, 16, 19, 854, DateTimeZone.forOffsetHours(1)).toDate(), issue.getCreatedDate()); + } + + @Test + public void testUpdatedDate(){ + Issue issue = new Issue(null,Utils.getTestIssue()); + assertEquals(new DateTime(2013, 10, 9, 22, 24, 55, 961, DateTimeZone.forOffsetHours(1)).toDate(), issue.getUpdatedDate()); + } + }