-
Notifications
You must be signed in to change notification settings - Fork 463
fix millisecond parsing errors #895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
package com.google.api.client.util; | ||
|
||
import com.google.api.client.util.DateTime.SecondsAndNanos; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
import java.util.Date; | ||
import java.util.TimeZone; | ||
import junit.framework.TestCase; | ||
|
@@ -28,12 +29,6 @@ public class DateTimeTest extends TestCase { | |
|
||
private TimeZone originalTimeZone; | ||
|
||
public DateTimeTest() {} | ||
|
||
public DateTimeTest(String testName) { | ||
super(testName); | ||
} | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
originalTimeZone = TimeZone.getDefault(); | ||
|
@@ -225,8 +220,18 @@ public void testParseRfc3339ToSecondsAndNanos() { | |
assertParsedRfc3339( | ||
"2018-03-01T10:11:12.1000Z", SecondsAndNanos.ofSecondsAndNanos(1519899072L, 100000000)); | ||
} | ||
|
||
public void testEpoch() { | ||
assertParsedRfc3339( | ||
"1970-01-01T00:00:00.000Z", SecondsAndNanos.ofSecondsAndNanos(0, 0)); | ||
} | ||
|
||
public void testOneSecondBeforeEpoch() { | ||
assertParsedRfc3339( | ||
"1969-12-31T23:59:59.000Z", SecondsAndNanos.ofSecondsAndNanos(-1, 0)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great test. |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you add the following test too?
(not 100% sure about the value of nanosecond part to represent As per Beam's PubsubClientTest, date 1582-10-15 is an important date when Gregorian Calendar was adopted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't verify that this value is correct, so I don't want to add it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will try to add this in a separate PR then. |
||
|
||
private void assertParsedRfc3339(String input, SecondsAndNanos expected) { | ||
private static void assertParsedRfc3339(String input, SecondsAndNanos expected) { | ||
SecondsAndNanos actual = DateTime.parseRfc3339ToSecondsAndNanos(input); | ||
assertEquals( | ||
"Seconds for " + input + " do not match", expected.getSeconds(), actual.getSeconds()); | ||
|
@@ -249,7 +254,7 @@ public void testParseAndFormatRfc3339() { | |
assertEquals(expected, output); | ||
} | ||
|
||
private void expectExceptionForParseRfc3339(String input) { | ||
private static void expectExceptionForParseRfc3339(String input) { | ||
try { | ||
DateTime.parseRfc3339(input); | ||
fail("expected NumberFormatException"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. NumberFormatException is a RuntimeException and thus no need to explicitly mark it.
https://docs.oracle.com/javase/8/docs/api/java/lang/NumberFormatException.html