@@ -608,7 +608,7 @@ public void testDateTimeMismatch() throws Exception {
608
608
TableFieldSchema .newBuilder ()
609
609
.setName ("datetime" )
610
610
.setType (TableFieldSchema .Type .DATETIME )
611
- .setMode (TableFieldSchema .Mode .REPEATED )
611
+ .setMode (TableFieldSchema .Mode .NULLABLE )
612
612
.build ();
613
613
TableSchema tableSchema = TableSchema .newBuilder ().addFields (field ).build ();
614
614
JSONObject json = new JSONObject ();
@@ -623,6 +623,34 @@ public void testDateTimeMismatch() throws Exception {
623
623
}
624
624
}
625
625
626
+ private void dateTimeMatch_Internal (String jsonVal , Long expectedVal ) throws Exception {
627
+ TableFieldSchema field =
628
+ TableFieldSchema .newBuilder ()
629
+ .setName ("datetime" )
630
+ .setType (TableFieldSchema .Type .DATETIME )
631
+ .setMode (TableFieldSchema .Mode .NULLABLE )
632
+ .build ();
633
+ TableSchema tableSchema = TableSchema .newBuilder ().addFields (field ).build ();
634
+ TestDatetime expectedProto = TestDatetime .newBuilder ().setDatetime (expectedVal ).build ();
635
+ JSONObject json = new JSONObject ();
636
+ json .put ("datetime" , jsonVal );
637
+ DynamicMessage protoMsg =
638
+ JsonToProtoMessage .INSTANCE .convertToProtoMessage (
639
+ TestDatetime .getDescriptor (), tableSchema , json );
640
+ assertEquals (expectedProto , protoMsg );
641
+ }
642
+
643
+ @ Test
644
+ public void testDateTimeMatch () throws Exception {
645
+ dateTimeMatch_Internal ("2021-09-27T20:51:10.752" , 142258614586538368L );
646
+ dateTimeMatch_Internal ("2021-09-27t20:51:10.752" , 142258614586538368L );
647
+ dateTimeMatch_Internal ("2021-09-27 20:51:10.752" , 142258614586538368L );
648
+ dateTimeMatch_Internal ("2021-9-27T20:51:10.752" , 142258614586538368L );
649
+ dateTimeMatch_Internal ("2021-09-27T00:00:00" , 142258525253402624L );
650
+ dateTimeMatch_Internal ("2021-09-27T00:0:00" , 142258525253402624L );
651
+ dateTimeMatch_Internal ("2021-09-27" , 142258525253402624L );
652
+ }
653
+
626
654
@ Test
627
655
public void testTimeMismatch () throws Exception {
628
656
TableFieldSchema field =
@@ -952,6 +980,9 @@ public void testStructComplex() throws Exception {
952
980
.setTestDate (1 )
953
981
.setTestDatetime (1 )
954
982
.addTestDatetimeStr (142258614586538368L )
983
+ .addTestDatetimeStr (142258614586538368L )
984
+ .addTestDatetimeStr (142258614586538368L )
985
+ .addTestDatetimeStr (142258525253402624L )
955
986
.addTestDatetimeStr (142258525253402624L )
956
987
.setComplexLvl1 (
957
988
ComplexLvl1 .newBuilder ()
@@ -1020,7 +1051,14 @@ public void testStructComplex() throws Exception {
1020
1051
json .put ("test_datetime" , 1 );
1021
1052
json .put (
1022
1053
"test_datetime_str" ,
1023
- new JSONArray (new String [] {"2021-09-27T20:51:10.752" , "2021-09-27T00:00:00" }));
1054
+ new JSONArray (
1055
+ new String [] {
1056
+ "2021-09-27T20:51:10.752" ,
1057
+ "2021-09-27t20:51:10.752" ,
1058
+ "2021-09-27 20:51:10.752" ,
1059
+ "2021-09-27T00:00:00" ,
1060
+ "2021-09-27"
1061
+ }));
1024
1062
json .put ("complex_lvl1" , complex_lvl1 );
1025
1063
json .put ("complex_lvl2" , complex_lvl2 );
1026
1064
json .put (
0 commit comments