Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local timezone and timezone related conversions #2

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions freezegun/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import inspect

from dateutil import parser
from dateutil.tz import tzlocal

try:
from maya import MayaDT
Expand Down Expand Up @@ -87,6 +86,8 @@
_GLOBAL_MODULES_CACHE = {}


_tzlocal = real_datetime.now(datetime.UTC).astimezone().tzinfo

def _get_module_attributes(module):
result = []
try:
Expand Down Expand Up @@ -366,8 +367,9 @@ def __sub__(self, other):

def astimezone(self, tz=None):
if tz is None:
tz = tzlocal()
return datetime_to_fakedatetime(real_datetime.astimezone(self, tz))
tz = _tzlocal

return self.replace(tzinfo=tz) if self.tzinfo is None else datetime_to_fakedatetime(real_datetime.astimezone(self, tz))

@classmethod
def fromtimestamp(cls, t, tz=None):
Expand All @@ -385,10 +387,11 @@ def timestamp(self):
@classmethod
def now(cls, tz=None):
now = cls._time_to_freeze() or real_datetime.now()
if tz:
if tz is not None:
result = tz.fromutc(now.replace(tzinfo=tz))
else:
result = now + cls._tz_offset()

return datetime_to_fakedatetime(result)

def date(self):
Expand Down Expand Up @@ -647,7 +650,7 @@ def start(self):

is_already_started = len(freeze_factories) > 0
freeze_factories.append(freeze_factory)
tz_offsets.append(self.tz_offset)
tz_offsets.append(self.tz_offset or _tzlocal)
ignore_lists.append(self.ignore)
tick_flags.append(self.tick)

Expand Down