1
0
Fork 0
Nikita Salnikov-Tarnovski 2014-12-22 08:10:50 +02:00
parent 3811b12e65
commit 0bf3969296
3 changed files with 48 additions and 0 deletions

View File

@ -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.
*

View File

@ -381,6 +381,8 @@ public class Issue extends Resource {
private List<WorkLog> 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;
}
}

View File

@ -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());
}
}