@@ -237,24 +237,75 @@ void parseTimestampWithoutTimeZoneOffset() {
237237
238238 @ Test
239239 void parseTimestampWithTimeZoneOffset () {
240+ // Max values
240241 assertThat (Timestamp .parseTimestampDuration ("0001-01-01T00:00:00-00:00" ))
241242 .isEqualTo (Timestamp .MIN_VALUE );
242243 assertThat (Timestamp .parseTimestampDuration ("9999-12-31T23:59:59.999999999-00:00" ))
243244 .isEqualTo (Timestamp .MAX_VALUE );
245+ // Extreme values (close to min/max)
246+ assertThat (Timestamp .parseTimestampDuration ("0001-01-01T00:00:00.000000001Z" ))
247+ .isEqualTo (Timestamp .ofTimeSecondsAndNanos (Timestamp .MIN_VALUE .getSeconds (), 1 ));
248+ assertThat (Timestamp .parseTimestampDuration ("9999-12-31T23:59:59.999999998Z" ))
249+ .isEqualTo (Timestamp .ofTimeSecondsAndNanos (Timestamp .MAX_VALUE .getSeconds (), 999999998 ));
250+ // Common use cases
244251 assertThat (Timestamp .parseTimestampDuration ("2020-07-10T14:03:00-07:00" ))
245252 .isEqualTo (Timestamp .ofTimeSecondsAndNanos (1594414980 , 0 ));
246253 assertThat (Timestamp .parseTimestampDuration ("2020-12-06T19:21:12.123+05:30" ))
247254 .isEqualTo (Timestamp .ofTimeSecondsAndNanos (1607262672 , 123000000 ));
248- // we also confirm that parsing a timestamp with nano precision will behave the same as the
255+ // We also confirm that parsing a timestamp with nano precision will behave the same as the
249256 // threeten counterpart
250257 assertThat (Timestamp .parseTimestampDuration ("2020-12-06T19:21:12.123+05:30" ))
251258 .isEqualTo (Timestamp .parseTimestamp ("2020-12-06T19:21:12.123+05:30" ));
259+ // Timestamps with fractional seconds at nanosecond level
260+ assertThat (Timestamp .parseTimestampDuration ("2020-12-06T19:21:12.123456789+05:30" ))
261+ .isEqualTo (Timestamp .ofTimeSecondsAndNanos (1607262672 , 123456789 ));
262+ // Fractional seconds beyond nanos should throw an exception
263+ assertThrows (
264+ org .threeten .bp .format .DateTimeParseException .class ,
265+ // DateTimeParseException.class,
266+ () -> Timestamp .parseTimestampDuration ("2020-12-06T19:21:12.123456789321+05:30" ));
267+ // Missing components (should throw exceptions)
268+ assertThrows (
269+ // DateTimeParseException.class,
270+ org .threeten .bp .format .DateTimeParseException .class ,
271+ () -> Timestamp .parseTimestampDuration ("2020-12-06" ));
272+ // Whitespace should not be supported
273+ assertThrows (
274+ // DateTimeParseException.class,
275+ org .threeten .bp .format .DateTimeParseException .class ,
276+ () -> Timestamp .parseTimestampDuration (" 2020-12-06T19:21:12.123+05:30 " ));
277+ // It should be case-insensitive
278+ assertThat (Timestamp .parseTimestampDuration ("2020-07-10t14:03:00-07:00" ))
279+ .isEqualTo (Timestamp .ofTimeSecondsAndNanos (1594414980 , 0 ));
280+ // Invalid time zone offsets
281+ assertThrows (
282+ // DateTimeParseException.class,
283+ org .threeten .bp .format .DateTimeParseException .class ,
284+ () -> Timestamp .parseTimestampDuration ("2020-12-06T19:21:12.123+25:00" ));
285+ assertThrows (
286+ // DateTimeParseException.class,
287+ org .threeten .bp .format .DateTimeParseException .class ,
288+ () -> Timestamp .parseTimestampDuration ("2020-12-06T19:21:12.123-25:00" ));
289+ // Int values for SecondOfMinute should be between 0 and 59
290+ assertThrows (
291+ // DateTimeParseException.class,
292+ org .threeten .bp .format .DateTimeParseException .class ,
293+ () -> Timestamp .parseTimestampDuration ("2016-12-31T23:59:60Z" ));
252294 }
253295
254296 @ Test
255297 void parseTimestampWithZoneString () {
298+ // Valid RFC 3339 timestamps with time zone names
256299 assertThat (Timestamp .parseTimestampDuration ("2020-12-06T08:51:12.123America/Toronto" ))
257300 .isEqualTo (Timestamp .ofTimeSecondsAndNanos (1607262672 , 123000000 ));
301+ assertThat (Timestamp .parseTimestampDuration ("2023-04-10T22:42:10.123456789Europe/London" ))
302+ .isEqualTo (Timestamp .ofTimeSecondsAndNanos (1681162930 , 123456789 ));
303+
304+ // Invalid time zone names
305+ assertThrows (
306+ org .threeten .bp .format .DateTimeParseException .class ,
307+ // DateTimeParseException.class,
308+ () -> Timestamp .parseTimestampDuration ("2020-12-06T19:21:12.123Invalid/TimeZone" ));
258309 }
259310
260311 @ Test
0 commit comments