Skip to content

Commit

Permalink
Remove deprecation warning of datetime.datetime.utcfromtimestamp (#510
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jairhenrique authored Jan 5, 2025
1 parent 6407755 commit aa2ab44
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 @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fix `Recipe.prepare` without _quantity (on one-to-one relation)

### 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 aa2ab44

Please sign in to comment.