def test_datetime(self):
    self.round_trip({'date': datetime.datetime(2009, 12, 9, 15, 49, 45, 191000, utc)})
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000+0000"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000000+0000"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000+00:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000000+00:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000000+00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000Z"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000000Z"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00Z"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000000"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000-0800"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000000-0800"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000-08:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000000-08:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000000-08"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000+0100"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000000+0100"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000+01:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000000+01:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000000+01"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    dtm = datetime.datetime(1, 1, 1, 1, 1, 1, 0, utc)
    jsn = '{"dt": {"$date": -62135593139000}}'
    self.assertEqual(dtm, json_util.loads(jsn)['dt'])
    jsn = '{"dt": {"$date": {"$numberLong": "-62135593139000"}}}'
    self.assertEqual(dtm, json_util.loads(jsn)['dt'])
    pre_epoch = {'dt': datetime.datetime(1, 1, 1, 1, 1, 1, 10000, utc)}
    post_epoch = {'dt': datetime.datetime(1972, 1, 1, 1, 1, 1, 10000, utc)}
    self.assertEqual('{"dt": {"$date": -62135593138990}}', json_util.dumps(pre_epoch))
    self.assertEqual('{"dt": {"$date": 63075661010}}', json_util.dumps(post_epoch))
    self.assertEqual('{"dt": {"$date": {"$numberLong": "-62135593138990"}}}', json_util.dumps(pre_epoch, json_options=STRICT_JSON_OPTIONS))
    self.assertEqual('{"dt": {"$date": "1972-01-01T01:01:01.010Z"}}', json_util.dumps(post_epoch, json_options=STRICT_JSON_OPTIONS))
    number_long_options = json_util.JSONOptions(datetime_representation=DatetimeRepresentation.NUMBERLONG)
    self.assertEqual('{"dt": {"$date": {"$numberLong": "63075661010"}}}', json_util.dumps(post_epoch, json_options=number_long_options))
    self.assertEqual('{"dt": {"$date": {"$numberLong": "-62135593138990"}}}', json_util.dumps(pre_epoch, json_options=number_long_options))
    pre_epoch_naive = {'dt': datetime.datetime(1, 1, 1, 1, 1, 1, 10000)}
    post_epoch_naive = {'dt': datetime.datetime(1972, 1, 1, 1, 1, 1, 10000)}
    self.assertEqual('{"dt": {"$date": {"$numberLong": "-62135593138990"}}}', json_util.dumps(pre_epoch_naive, json_options=STRICT_JSON_OPTIONS))
    self.assertEqual('{"dt": {"$date": "1972-01-01T01:01:01.010Z"}}', json_util.dumps(post_epoch_naive, json_options=STRICT_JSON_OPTIONS))
    self.assertEqual(datetime.datetime(1972, 1, 1, 1, 1, 1, 10000, utc), json_util.loads('{"dt": {"$date": "1972-01-01T01:01:01.010+0000"}}')['dt'])
    self.assertEqual(datetime.datetime(1972, 1, 1, 1, 1, 1, 10000, utc), json_util.loads('{"dt": {"$date": "1972-01-01T01:01:01.010+0000"}}', json_options=json_util.JSONOptions(tz_aware=True, tzinfo=utc))['dt'])
    self.assertEqual(datetime.datetime(1972, 1, 1, 1, 1, 1, 10000), json_util.loads('{"dt": {"$date": "1972-01-01T01:01:01.010+0000"}}', json_options=json_util.JSONOptions(tz_aware=False))['dt'])
    self.round_trip(pre_epoch_naive, json_options=json_util.JSONOptions(tz_aware=False))
    pacific = FixedOffset(((- 8) * 60), 'US/Pacific')
    aware_datetime = {'dt': datetime.datetime(2002, 10, 27, 6, 0, 0, 10000, pacific)}
    self.assertEqual('{"dt": {"$date": "2002-10-27T06:00:00.010-0800"}}', json_util.dumps(aware_datetime, json_options=STRICT_JSON_OPTIONS))
    self.round_trip(aware_datetime, json_options=json_util.JSONOptions(tz_aware=True, tzinfo=pacific))
    self.round_trip(aware_datetime, json_options=json_util.JSONOptions(datetime_representation=DatetimeRepresentation.ISO8601, tz_aware=True, tzinfo=pacific))
def test_datetime(self):
    self.round_trip({'date': datetime.datetime(2009, 12, 9, 15, 49, 45, 191000, utc)})
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000+0000"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000000+0000"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000+00:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000000+00:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000000+00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000Z"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000000Z"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00Z"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T00:00:00.000000"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000-0800"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000000-0800"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000-08:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000000-08:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1969-12-31T16:00:00.000000-08"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000+0100"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000000+0100"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000+01:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000000+01:00"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    jsn = '{"dt": { "$date" : "1970-01-01T01:00:00.000000+01"}}'
    self.assertEqual(EPOCH_AWARE, json_util.loads(jsn)['dt'])
    dtm = datetime.datetime(1, 1, 1, 1, 1, 1, 0, utc)
    jsn = '{"dt": {"$date": -62135593139000}}'
    self.assertEqual(dtm, json_util.loads(jsn)['dt'])
    jsn = '{"dt": {"$date": {"$numberLong": "-62135593139000"}}}'
    self.assertEqual(dtm, json_util.loads(jsn)['dt'])
    pre_epoch = {'dt': datetime.datetime(1, 1, 1, 1, 1, 1, 10000, utc)}
    post_epoch = {'dt': datetime.datetime(1972, 1, 1, 1, 1, 1, 10000, utc)}
    self.assertEqual('{"dt": {"$date": -62135593138990}}', json_util.dumps(pre_epoch))
    self.assertEqual('{"dt": {"$date": 63075661010}}', json_util.dumps(post_epoch))
    self.assertEqual('{"dt": {"$date": {"$numberLong": "-62135593138990"}}}', json_util.dumps(pre_epoch, json_options=STRICT_JSON_OPTIONS))
    self.assertEqual('{"dt": {"$date": "1972-01-01T01:01:01.010Z"}}', json_util.dumps(post_epoch, json_options=STRICT_JSON_OPTIONS))
    number_long_options = json_util.JSONOptions(datetime_representation=DatetimeRepresentation.NUMBERLONG)
    self.assertEqual('{"dt": {"$date": {"$numberLong": "63075661010"}}}', json_util.dumps(post_epoch, json_options=number_long_options))
    self.assertEqual('{"dt": {"$date": {"$numberLong": "-62135593138990"}}}', json_util.dumps(pre_epoch, json_options=number_long_options))
    pre_epoch_naive = {'dt': datetime.datetime(1, 1, 1, 1, 1, 1, 10000)}
    post_epoch_naive = {'dt': datetime.datetime(1972, 1, 1, 1, 1, 1, 10000)}
    self.assertEqual('{"dt": {"$date": {"$numberLong": "-62135593138990"}}}', json_util.dumps(pre_epoch_naive, json_options=STRICT_JSON_OPTIONS))
    self.assertEqual('{"dt": {"$date": "1972-01-01T01:01:01.010Z"}}', json_util.dumps(post_epoch_naive, json_options=STRICT_JSON_OPTIONS))
    self.assertEqual(datetime.datetime(1972, 1, 1, 1, 1, 1, 10000, utc), json_util.loads('{"dt": {"$date": "1972-01-01T01:01:01.010+0000"}}')['dt'])
    self.assertEqual(datetime.datetime(1972, 1, 1, 1, 1, 1, 10000, utc), json_util.loads('{"dt": {"$date": "1972-01-01T01:01:01.010+0000"}}', json_options=json_util.JSONOptions(tz_aware=True, tzinfo=utc))['dt'])
    self.assertEqual(datetime.datetime(1972, 1, 1, 1, 1, 1, 10000), json_util.loads('{"dt": {"$date": "1972-01-01T01:01:01.010+0000"}}', json_options=json_util.JSONOptions(tz_aware=False))['dt'])
    self.round_trip(pre_epoch_naive, json_options=json_util.JSONOptions(tz_aware=False))
    pacific = FixedOffset(((- 8) * 60), 'US/Pacific')
    aware_datetime = {'dt': datetime.datetime(2002, 10, 27, 6, 0, 0, 10000, pacific)}
    self.assertEqual('{"dt": {"$date": "2002-10-27T06:00:00.010-0800"}}', json_util.dumps(aware_datetime, json_options=STRICT_JSON_OPTIONS))
    self.round_trip(aware_datetime, json_options=json_util.JSONOptions(tz_aware=True, tzinfo=pacific))
    self.round_trip(aware_datetime, json_options=json_util.JSONOptions(datetime_representation=DatetimeRepresentation.ISO8601, tz_aware=True, tzinfo=pacific))