fix some DeprecationWarnings in python3.12
...\electrum\electrum\logging.py:137: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). ...\electrum\electrum\x509.py:310: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
This commit is contained in:
@@ -26,7 +26,7 @@ import os, sys, re, json
|
||||
from collections import defaultdict, OrderedDict
|
||||
from typing import (NamedTuple, Union, TYPE_CHECKING, Tuple, Optional, Callable, Any,
|
||||
Sequence, Dict, Generic, TypeVar, List, Iterable, Set, Awaitable)
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
import decimal
|
||||
from decimal import Decimal
|
||||
import traceback
|
||||
@@ -808,10 +808,13 @@ def quantize_feerate(fee) -> Union[None, Decimal, int]:
|
||||
return Decimal(fee).quantize(_feerate_quanta, rounding=decimal.ROUND_HALF_DOWN)
|
||||
|
||||
|
||||
def timestamp_to_datetime(timestamp: Union[int, float, None]) -> Optional[datetime]:
|
||||
def timestamp_to_datetime(timestamp: Union[int, float, None], *, utc: bool = False) -> Optional[datetime]:
|
||||
if timestamp is None:
|
||||
return None
|
||||
return datetime.fromtimestamp(timestamp)
|
||||
tz = None
|
||||
if utc:
|
||||
tz = timezone.utc
|
||||
return datetime.fromtimestamp(timestamp, tz=tz)
|
||||
|
||||
|
||||
def format_time(timestamp: Union[int, float, None]) -> str:
|
||||
|
||||
Reference in New Issue
Block a user