Skip to content

Commit

Permalink
Remove deprecation warning of datetime.datetime.utcfromtimestamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
jairhenrique committed Dec 20, 2024
1 parent 3818ad8 commit 100406a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

### Removed
- Remove deprecation warning of `datetime.datetime.utcfromtimestamp`.

## [1.20.0](https://pypi.org/project/model-bakery/1.20.0/)

Expand Down
4 changes: 2 additions & 2 deletions model_bakery/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
def tz_aware(value: datetime) -> datetime:
"""Return an UTC-aware datetime in case of USE_TZ=True."""
if settings.USE_TZ:
value = value.replace(tzinfo=timezone.utc)
return value.replace(tzinfo=timezone.utc)

return value
return value.replace(tzinfo=None)
5 changes: 4 additions & 1 deletion model_bakery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def seq(value, increment_by=1, start=None, suffix=None):
start = (date - epoch_datetime).total_seconds()
increment_by = increment_by.total_seconds()
for n in itertools.count(increment_by, increment_by):
series_date = tz_aware(datetime.datetime.utcfromtimestamp(start + n))
series_date = tz_aware(
datetime.datetime.fromtimestamp(start + n, tz=datetime.timezone.utc)
)

if type(value) is datetime.time:
yield series_date.time()
elif type(value) is datetime.date:
Expand Down

0 comments on commit 100406a

Please sign in to comment.