Skip to content

Commit e5d88d8

Browse files
committed
[Issue 583] Use DateValue objects for "date" values.
http://codereview.appspot.com/6457089/
1 parent 1fe80ab commit e5d88d8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

google-http-client/src/main/java/com/google/api/client/util/DateTime.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ public DateTime(boolean dateOnly, long value, Integer tzShift) {
8181
this.tzShift = tzShift;
8282
}
8383

84+
/**
85+
* Instantiates {@link DateTime} from an <a href='http://tools.ietf.org/html/rfc3339'>RFC 3339</a>
86+
* date/time value.
87+
*
88+
* @since 1.11
89+
*/
90+
public DateTime(String value) {
91+
// TODO(rmistry): Move the implementation of parseRfc3339 into this constructor. Implementation
92+
// of parseRfc3339 can then do "return new DateTime(str);".
93+
DateTime dateTime = parseRfc3339(value);
94+
this.dateOnly = dateTime.dateOnly;
95+
this.value = dateTime.value;
96+
this.tzShift = dateTime.tzShift;
97+
}
98+
8499
/**
85100
* Returns the date/time value expressed as the number of milliseconds since the Unix epoch.
86101
*

google-http-client/src/test/java/com/google/api/client/util/DateTimeTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void testEquals() {
4646
"Check not equal with Date.", new DateTime(1234567890L).equals(new Date(9876543210L)));
4747
}
4848

49-
public void testParseDateTime() {
49+
public void testParseRfc3339() {
5050
expectExceptionForParseRfc3339("");
5151
expectExceptionForParseRfc3339("abc");
5252
DateTime value = DateTime.parseRfc3339("2007-06-01");
@@ -55,6 +55,13 @@ public void testParseDateTime() {
5555
assertFalse(value.isDateOnly());
5656
value = DateTime.parseRfc3339("2007-06-01T10:11:30Z");
5757
assertEquals(0, value.getValue() % 100);
58+
59+
value = new DateTime("2007-06-01");
60+
assertTrue(value.isDateOnly());
61+
value = new DateTime("2007-06-01T10:11:30.057");
62+
assertFalse(value.isDateOnly());
63+
value = new DateTime("2007-06-01T10:11:30Z");
64+
assertEquals(0, value.getValue() % 100);
5865
}
5966

6067
private void expectExceptionForParseRfc3339(String input) {

0 commit comments

Comments
 (0)