-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix date parsing to correctly handle RFC3339 timezone format (#693)
- Loading branch information
Matt Willer
authored
Apr 6, 2019
1 parent
a9e940f
commit 391171a
Showing
7 changed files
with
96 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.box.sdk; | ||
|
||
import java.text.ParseException; | ||
import java.util.Date; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
public class BoxDateFormatTest { | ||
|
||
@Test | ||
@Category(UnitTest.class) | ||
public void testParseWorksWithOffsetTimezone() throws ParseException { | ||
|
||
Date date = BoxDateFormat.parse("2019-04-06T15:57:01-07:00"); | ||
Date expectedDate = new Date(1554591421000L); | ||
Assert.assertEquals(expectedDate, date); | ||
} | ||
|
||
@Test | ||
@Category(UnitTest.class) | ||
public void testParseWorksWithZuluTimezone() throws ParseException { | ||
|
||
Date date = BoxDateFormat.parse("2019-04-06T22:58:49Z"); | ||
Date expectedDate = new Date(1554591529000L); | ||
Assert.assertEquals(expectedDate, date); | ||
} | ||
|
||
@Test | ||
@Category(UnitTest.class) | ||
public void testParseWorksWithZeroOffsetTimezone() throws ParseException { | ||
|
||
Date date = BoxDateFormat.parse("2019-04-06T22:58:49+00:00"); | ||
Date expectedDate = new Date(1554591529000L); | ||
Assert.assertEquals(expectedDate, date); | ||
} | ||
|
||
@Test | ||
@Category(UnitTest.class) | ||
public void testParseWorksWithMinusZeroOffsetTimezone() throws ParseException { | ||
|
||
Date date = BoxDateFormat.parse("2019-04-06T22:58:49-00:00"); | ||
Date expectedDate = new Date(1554591529000L); | ||
Assert.assertEquals(expectedDate, date); | ||
} | ||
|
||
@Test | ||
@Category(UnitTest.class) | ||
public void testParseWorksWithRFC822ZeroOffsetTimezone() throws ParseException { | ||
|
||
Date date = BoxDateFormat.parse("2019-04-06T22:58:49+0000"); | ||
Date expectedDate = new Date(1554591529000L); | ||
Assert.assertEquals(expectedDate, date); | ||
} | ||
|
||
@Test | ||
@Category(UnitTest.class) | ||
public void testFormatOutputsZuluTimezone() { | ||
Date date = new Date(1554591421000L); | ||
String expectedString = "2019-04-06T22:57:01Z"; | ||
Assert.assertEquals(expectedString, BoxDateFormat.format(date)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters