@@ -185,13 +185,14 @@ def test_DateTimeFormatting(self):
185
185
self .assertTrue ("." not in lineProtocol )
186
186
187
187
def test_DateTimeUtc (self ):
188
- dateTime = datetime (2015 , 10 , 15 , 8 , 20 , 15 )
188
+ date_time = datetime (2015 , 10 , 15 , 8 , 20 , 15 )
189
189
190
190
point = Point .measurement ("h2o" ) \
191
191
.tag ("location" , "europe" ) \
192
- .field ("level" , 2 )
192
+ .field ("level" , 2 ) \
193
+ .time (date_time )
193
194
194
- # Assert.Throws < ArgumentException > (() = > point.time(dateTime, WritePrecision.Ms ))
195
+ self . assertEqual ( "h2o,location=europe level=2i 1444897215000000000" , point .to_line_protocol ( ))
195
196
196
197
def test_InstantFormatting (self ):
197
198
instant = "1970-01-01T00:00:45.999999999Z"
@@ -288,6 +289,21 @@ def test_only_infinity_values(self):
288
289
289
290
self .assertEqual ("" , _point .to_line_protocol ())
290
291
292
+ def test_timezone (self ):
293
+ """Test timezone in TestLineProtocol object."""
294
+ dt = datetime (2009 , 11 , 10 , 23 , 0 , 0 , 123456 )
295
+ utc = UTC .localize (dt )
296
+ berlin = timezone ('Europe/Berlin' ).localize (dt )
297
+ eastern = berlin .astimezone (timezone ('US/Eastern' ))
298
+
299
+ self .assertEqual ("h2o val=1i 0" , Point .measurement ("h2o" ).field ("val" , 1 ).time (0 ).to_line_protocol ())
300
+ self .assertEqual ("h2o val=1i 1257894000123456000" , Point .measurement ("h2o" ).field ("val" , 1 ).time ("2009-11-10T23:00:00.123456Z" ).to_line_protocol ())
301
+ self .assertEqual ("h2o val=1i 1257894000123456000" , Point .measurement ("h2o" ).field ("val" , 1 ).time (utc ).to_line_protocol ())
302
+ self .assertEqual ("h2o val=1i 1257894000123456000" , Point .measurement ("h2o" ).field ("val" , 1 ).time (dt ).to_line_protocol ())
303
+ self .assertEqual ("h2o val=1i 1257894000123456000" , Point .measurement ("h2o" ).field ("val" , 1 ).time (1257894000123456000 , write_precision = WritePrecision .NS ).to_line_protocol ())
304
+ self .assertEqual ("h2o val=1i 1257890400123456000" , Point .measurement ("h2o" ).field ("val" , 1 ).time (eastern ).to_line_protocol ())
305
+ self .assertEqual ("h2o val=1i 1257890400123456000" , Point .measurement ("h2o" ).field ("val" , 1 ).time (berlin ).to_line_protocol ())
306
+
291
307
292
308
if __name__ == '__main__' :
293
309
unittest .main ()
0 commit comments