kopia lustrzana https://github.com/tsileo/little-boxes
Use tz aware timestamp
rodzic
59ee83ee9b
commit
88d7f48e12
|
@ -2,6 +2,7 @@
|
||||||
import logging
|
import logging
|
||||||
import weakref
|
import weakref
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from datetime import timezone
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
@ -69,7 +70,10 @@ def use_backend(backend_instance):
|
||||||
|
|
||||||
|
|
||||||
def format_datetime(dt: datetime) -> str:
|
def format_datetime(dt: datetime) -> str:
|
||||||
return dt.replace(microsecond=0).isoformat() + "Z"
|
if dt.tzinfo is None:
|
||||||
|
raise ValueError("datetime must be tz aware")
|
||||||
|
|
||||||
|
return dt.astimezone(timezone.utc).replace(microsecond=0).isoformat() + "Z"
|
||||||
|
|
||||||
|
|
||||||
class ActivityType(Enum):
|
class ActivityType(Enum):
|
||||||
|
@ -816,7 +820,7 @@ class Create(BaseActivity):
|
||||||
if self.published:
|
if self.published:
|
||||||
self._data["object"]["published"] = self.published
|
self._data["object"]["published"] = self.published
|
||||||
else:
|
else:
|
||||||
now = format_datetime(datetime.utcnow())
|
now = format_datetime(datetime.now().astimezone())
|
||||||
self._data["published"] = now
|
self._data["published"] = now
|
||||||
self._data["object"]["published"] = now
|
self._data["object"]["published"] = now
|
||||||
|
|
||||||
|
@ -889,7 +893,7 @@ class Note(BaseActivity):
|
||||||
object=self.id,
|
object=self.id,
|
||||||
to=[AS_PUBLIC],
|
to=[AS_PUBLIC],
|
||||||
cc=[as_actor.followers, self.attributedTo],
|
cc=[as_actor.followers, self.attributedTo],
|
||||||
published=format_datetime(datetime.utcnow()),
|
published=format_datetime(datetime.now().astimezone()),
|
||||||
)
|
)
|
||||||
|
|
||||||
def has_mention(self, actor_id: str) -> bool:
|
def has_mention(self, actor_id: str) -> bool:
|
||||||
|
|
Ładowanie…
Reference in New Issue