@@ -248,6 +248,24 @@ public void testFromUnixTimeWithTimeZone()
248
248
assertFunction (format ("from_unixtime(7200, '%s')" , zoneId ), TIMESTAMP_WITH_TIME_ZONE , toTimestampWithTimeZone (expected ));
249
249
}
250
250
251
+ @ Test
252
+ public void testFromUnixTimeWithTimeZoneOverflow ()
253
+ {
254
+ String zoneId = "Asia/Shanghai" ;
255
+
256
+ // Test the largest possible valid value.
257
+ DateTime expected = new DateTime (73326 , 9 , 12 , 4 , 14 , 45 , DateTimeZone .forID (zoneId ));
258
+ assertFunction (format ("from_unixtime(2251799813685, '%s')" , zoneId ), TIMESTAMP_WITH_TIME_ZONE , toTimestampWithTimeZone (expected ));
259
+
260
+ // Test the smallest possible valid value.
261
+ expected = new DateTime (-69387 , 4 , 22 , 11 , 50 , 58 , DateTimeZone .forID (zoneId ));
262
+ assertFunction (format ("from_unixtime(-2251799813685, '%s')" , zoneId ), TIMESTAMP_WITH_TIME_ZONE , toTimestampWithTimeZone (expected ));
263
+
264
+ // Test the values just outside the range of valid values.
265
+ assertNumericOverflow (format ("from_unixtime(2251799813686, '%s')" , zoneId ), "TimestampWithTimeZone overflow: 2251799813686000 ms" );
266
+ assertNumericOverflow (format ("from_unixtime(-2251799813686, '%s')" , zoneId ), "TimestampWithTimeZone overflow: -2251799813686000 ms" );
267
+ }
268
+
251
269
@ Test
252
270
public void testToUnixTime ()
253
271
{
@@ -271,6 +289,24 @@ public void testFromISO8601()
271
289
assertFunction ("from_iso8601_date('" + DATE_ISO8601_STRING + "')" , DateType .DATE , toDate (DATE ));
272
290
}
273
291
292
+ @ Test
293
+ public void testFromISO8601Overflow ()
294
+ {
295
+ String zoneId = "Z" ;
296
+
297
+ // Test the largest possible valid value.
298
+ DateTime expected = new DateTime (73326 , 9 , 11 , 20 , 14 , 45 , 247 , DateTimeZone .forID (zoneId ));
299
+ assertFunction (format ("from_iso8601_timestamp('73326-09-11T20:14:45.247%s')" , zoneId ), TIMESTAMP_WITH_TIME_ZONE , toTimestampWithTimeZone (expected ));
300
+
301
+ // Test the smallest possible valid value.
302
+ expected = new DateTime (-69387 , 12 , 31 , 23 , 59 , 59 , 999 , DateTimeZone .forID (zoneId ));
303
+ assertFunction (format ("from_iso8601_timestamp('-69387-12-31T23:59:59.999%s')" , zoneId ), TIMESTAMP_WITH_TIME_ZONE , toTimestampWithTimeZone (expected ));
304
+
305
+ // Test the values just outside the range of valid values.
306
+ assertNumericOverflow (format ("from_iso8601_timestamp('73326-09-11T20:14:45.248%s')" , zoneId ), "TimestampWithTimeZone overflow: 2251799813685248 ms" );
307
+ assertNumericOverflow (format ("from_iso8601_timestamp('-69388-01-01T00:00:00.000%s')" , zoneId ), "TimestampWithTimeZone overflow: -2251841040000000 ms" );
308
+ }
309
+
274
310
@ Test
275
311
public void testToIso8601 ()
276
312
{
@@ -764,6 +800,25 @@ public void testParseDatetime()
764
800
toTimestampWithTimeZone (new DateTime (1960 , 1 , 22 , 3 , 4 , 0 , 0 , DateTimeZone .forOffsetHours (5 ))));
765
801
}
766
802
803
+ @ Test
804
+ public void testParseDatetimeOverflow ()
805
+ {
806
+ String zoneId = "Z" ;
807
+ String pattern = "yyyy/MM/dd HH:mm:ss.SSS Z" ;
808
+
809
+ // Test the largest possible valid value.
810
+ DateTime expected = new DateTime (73326 , 9 , 11 , 20 , 14 , 45 , 247 , DateTimeZone .forID (zoneId ));
811
+ assertFunction (format ("parse_datetime('73326/09/11 20:14:45.247 %s', '%s')" , zoneId , pattern ), TIMESTAMP_WITH_TIME_ZONE , toTimestampWithTimeZone (expected ));
812
+
813
+ // Test the smallest possible valid value.
814
+ expected = new DateTime (-69387 , 12 , 31 , 23 , 59 , 59 , 999 , DateTimeZone .forID (zoneId ));
815
+ assertFunction (format ("parse_datetime('-69387/12/31 23:59:59.999 %s', '%s')" , zoneId , pattern ), TIMESTAMP_WITH_TIME_ZONE , toTimestampWithTimeZone (expected ));
816
+
817
+ // Test the values just outside the range of valid values.
818
+ assertNumericOverflow (format ("parse_datetime('73326/09/11 20:14:45.248 %s', '%s')" , zoneId , pattern ), "TimestampWithTimeZone overflow: 2251799813685248 ms" );
819
+ assertNumericOverflow (format ("parse_datetime('-69388/01/01 00:00:00.000 %s', '%s')" , zoneId , pattern ), "TimestampWithTimeZone overflow: -2251841040000000 ms" );
820
+ }
821
+
767
822
@ Test
768
823
public void testFormatDatetime ()
769
824
{
0 commit comments