Mercurial > personal > weather-server
comparison weather_server/common.py @ 39:b77c8e7d2742
Use zoneinfo rather than pytz.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Tue, 01 Apr 2025 15:54:21 -0400 |
| parents | 52ef21607b31 |
| children |
comparison
equal
deleted
inserted
replaced
| 38:d5a18ecebf47 | 39:b77c8e7d2742 |
|---|---|
| 1 import datetime | 1 import datetime |
| 2 import json | 2 import json |
| 3 import typing as t | 3 import typing as t |
| 4 | 4 |
| 5 import bson | 5 import bson |
| 6 import pytz | |
| 7 | 6 |
| 8 BSON_OPTIONS = bson.DEFAULT_CODEC_OPTIONS.with_options( | 7 BSON_OPTIONS = bson.DEFAULT_CODEC_OPTIONS.with_options( |
| 9 tz_aware=True, tzinfo=pytz.UTC) | 8 tz_aware=True, tzinfo=datetime.UTC) |
| 10 | 9 |
| 11 | 10 |
| 12 def bson_encode(data: t.Dict[str, t.Any]) -> bytes: | 11 def bson_encode(data: t.Dict[str, t.Any]) -> bytes: |
| 13 return bson.BSON.encode(data, codec_options=BSON_OPTIONS) | 12 return bson.BSON.encode(data, codec_options=BSON_OPTIONS) |
| 14 | 13 |
| 27 def json_dumps(data: t.Any) -> str: | 26 def json_dumps(data: t.Any) -> str: |
| 28 return JSON_ENCODER.encode(data) | 27 return JSON_ENCODER.encode(data) |
| 29 | 28 |
| 30 | 29 |
| 31 def utc_now(): | 30 def utc_now(): |
| 32 return datetime.datetime.utcnow().replace(tzinfo=pytz.UTC) | 31 return datetime.datetime.now(datetime.UTC) |
