@@ -132,7 +132,7 @@ def test_parameter_ast(self):
132132 },
133133 "init" : {
134134 "type" : "DateTimeLiteral" ,
135- "value" : "2021-03-20T15:59:10.607352Z "
135+ "value" : "2021-03-20T15:59:10.607352000Z "
136136 },
137137 "type" : "VariableAssignment"
138138 },
@@ -150,7 +150,7 @@ def test_parameter_ast(self):
150150 },
151151 "init" : {
152152 "type" : "DateTimeLiteral" ,
153- "value" : "2021-03-20T15:59:10.607352Z "
153+ "value" : "2021-03-20T15:59:10.607352000Z "
154154 },
155155 "type" : "VariableAssignment"
156156 },
@@ -514,6 +514,22 @@ def test_profiler_mock(self):
514514 'available' : 5727718400 , 'free' : 35330048 ,
515515 'used' : 11452150784 })
516516
517+ def test_time_to_ast (self ):
518+ from influxdb_client .extras import pd
519+ import dateutil .parser
520+
521+ literals = [
522+ (pd .Timestamp ('1996-02-25T21:20:00.001001231Z' ), '1996-02-25T21:20:00.001001231Z' ),
523+ (dateutil .parser .parse ('1996-02-25T21:20:00.001001231Z' ), '1996-02-25T21:20:00.001001000Z' ),
524+ (dateutil .parser .parse ('1996-02-25' ), '1996-02-25T00:00:00.000000000Z' ),
525+ (datetime .datetime (2021 , 5 , 24 , 8 , 40 , 44 , 785000 , tzinfo = timezone .utc ), '2021-05-24T08:40:44.785000000Z' ),
526+ ]
527+
528+ for literal in literals :
529+ ast = QueryApi ._build_flux_ast ({'date' : literal [0 ]})
530+ self .assertEqual ('DateTimeLiteral' , ast .body [0 ].assignment .init .type )
531+ self .assertEqual (literal [1 ], ast .body [0 ].assignment .init .value )
532+
517533
518534if __name__ == '__main__' :
519535 unittest .main ()
0 commit comments