MCPcopy Create free account
hub / github.com/amazon-ion/ion-java / TimestampTest

Class TimestampTest

src/test/java/com/amazon/ion/TimestampTest.java:60–3182  ·  view source on GitHub ↗

Validates Ion date parsing, specified as per W3C but with requiring at least year-month-day. @see the W3C datetime note

Source from the content-addressed store, hash-verified

58 * @see <a href="http://www.w3.org/TR/NOTE-datetime">the W3C datetime note</a>
59 */
60public class TimestampTest
61 extends IonTestCase
62{
63 @Rule
64 public ExpectedException thrown = ExpectedException.none();
65
66 /**
67 * Earliest Ion timestamp possible, that is, "0001-01-01".
68 */
69 private static final Timestamp EARLIEST_ION_TIMESTAMP =
70 Timestamp.valueOf("0001-01-01");
71
72 private static final Timestamp UNIX_EPOCH_TIMESTAMP =
73 Timestamp.valueOf("1970-01-01T00:00:00.000Z");
74
75 /**
76 * PST = -08:00 = -480
77 */
78 private static final int PST_OFFSET = -8 * 60;
79
80
81 public static Calendar makeUtcCalendar()
82 {
83 Calendar cal = Calendar.getInstance(UTC);
84 cal.setTimeInMillis(0); // clear all fields, else they are "now"
85 return cal;
86 }
87
88
89 public IonTimestamp parse(String text)
90 {
91 return (IonTimestamp) oneValue(text);
92 }
93
94
95 @Override
96 public void badValue(String text)
97 {
98 super.badValue(text);
99
100 try {
101 Timestamp.valueOf(text);
102 fail("Expected exception parsing text: " + text);
103 }
104 catch (IllegalArgumentException e) { }
105 }
106
107
108 private void checkTimestamp(Date expected, IonTimestamp actual)
109 {
110 assertSame(IonType.TIMESTAMP, actual.getType());
111 Date found = actual.dateValue();
112 assertNotNull("date is null", found);
113
114 // Ensure that dateValue() returns a new instance each call!
115 assertNotSame(found, actual.dateValue());
116
117 assertEquals(expected, found);

Callers

nothing calls this directly

Calls 1

valueOfMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…