@@ -190,6 +190,15 @@ def test_w_date(self):
190
190
self .assertIsInstance (value_pb , Value )
191
191
self .assertEqual (value_pb .string_value , today .isoformat ())
192
192
193
+ def test_w_date_pre1000ad (self ):
194
+ import datetime
195
+ from google .protobuf .struct_pb2 import Value
196
+
197
+ when = datetime .date (800 , 2 , 25 )
198
+ value_pb = self ._callFUT (when )
199
+ self .assertIsInstance (value_pb , Value )
200
+ self .assertEqual (value_pb .string_value , "0800-02-25" )
201
+
193
202
def test_w_timestamp_w_nanos (self ):
194
203
import datetime
195
204
from google .protobuf .struct_pb2 import Value
@@ -200,7 +209,19 @@ def test_w_timestamp_w_nanos(self):
200
209
)
201
210
value_pb = self ._callFUT (when )
202
211
self .assertIsInstance (value_pb , Value )
203
- self .assertEqual (value_pb .string_value , when .rfc3339 ())
212
+ self .assertEqual (value_pb .string_value , "2016-12-20T21:13:47.123456789Z" )
213
+
214
+ def test_w_timestamp_w_nanos_pre1000ad (self ):
215
+ import datetime
216
+ from google .protobuf .struct_pb2 import Value
217
+ from google .api_core import datetime_helpers
218
+
219
+ when = datetime_helpers .DatetimeWithNanoseconds (
220
+ 850 , 12 , 20 , 21 , 13 , 47 , nanosecond = 123456789 , tzinfo = datetime .timezone .utc
221
+ )
222
+ value_pb = self ._callFUT (when )
223
+ self .assertIsInstance (value_pb , Value )
224
+ self .assertEqual (value_pb .string_value , "0850-12-20T21:13:47.123456789Z" )
204
225
205
226
def test_w_listvalue (self ):
206
227
from google .protobuf .struct_pb2 import Value
@@ -214,12 +235,20 @@ def test_w_listvalue(self):
214
235
def test_w_datetime (self ):
215
236
import datetime
216
237
from google .protobuf .struct_pb2 import Value
217
- from google .api_core import datetime_helpers
218
238
219
- now = datetime .datetime .utcnow ().replace (tzinfo = datetime .timezone .utc )
220
- value_pb = self ._callFUT (now )
239
+ when = datetime .datetime (2021 , 2 , 8 , 0 , 0 , 0 , tzinfo = datetime .timezone .utc )
240
+ value_pb = self ._callFUT (when )
241
+ self .assertIsInstance (value_pb , Value )
242
+ self .assertEqual (value_pb .string_value , "2021-02-08T00:00:00.000000Z" )
243
+
244
+ def test_w_datetime_pre1000ad (self ):
245
+ import datetime
246
+ from google .protobuf .struct_pb2 import Value
247
+
248
+ when = datetime .datetime (916 , 2 , 8 , 0 , 0 , 0 , tzinfo = datetime .timezone .utc )
249
+ value_pb = self ._callFUT (when )
221
250
self .assertIsInstance (value_pb , Value )
222
- self .assertEqual (value_pb .string_value , datetime_helpers . to_rfc3339 ( now ) )
251
+ self .assertEqual (value_pb .string_value , "0916-02-08T00:00:00.000000Z" )
223
252
224
253
def test_w_timestamp_w_tz (self ):
225
254
import datetime
@@ -231,6 +260,16 @@ def test_w_timestamp_w_tz(self):
231
260
self .assertIsInstance (value_pb , Value )
232
261
self .assertEqual (value_pb .string_value , "2021-02-07T23:00:00.000000Z" )
233
262
263
+ def test_w_timestamp_w_tz_pre1000ad (self ):
264
+ import datetime
265
+ from google .protobuf .struct_pb2 import Value
266
+
267
+ zone = datetime .timezone (datetime .timedelta (hours = + 1 ), name = "CET" )
268
+ when = datetime .datetime (721 , 2 , 8 , 0 , 0 , 0 , tzinfo = zone )
269
+ value_pb = self ._callFUT (when )
270
+ self .assertIsInstance (value_pb , Value )
271
+ self .assertEqual (value_pb .string_value , "0721-02-07T23:00:00.000000Z" )
272
+
234
273
def test_w_unknown_type (self ):
235
274
with self .assertRaises (ValueError ):
236
275
self ._callFUT (object ())
0 commit comments