Skip to content

Commit e83a112

Browse files
committed
Ensure that portfolio snapshots are created with utc timezone
1 parent 8f41ba1 commit e83a112

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from dateutil import parser
2+
from datetime import timezone
23
from investing_algorithm_framework.domain.models.base_model import BaseModel
34
from investing_algorithm_framework.domain.constants import \
45
DEFAULT_DATETIME_FORMAT
@@ -39,6 +40,9 @@ def __init__(
3940
else:
4041
self.created_at = created_at
4142

43+
# Make sure that created_at is a timezone aware datetime object
44+
self.created_at.replace(tzinfo=timezone.utc)
45+
4246
if position_snapshots is None:
4347
position_snapshots = []
4448

@@ -143,7 +147,6 @@ def to_dict(self, datetime_format=None):
143147
Returns:
144148
dict: A dictionary representation of the portfolio snapshot object.
145149
"""
146-
147150
if datetime_format is not None:
148151
created_at = self.created_at.strftime(datetime_format) \
149152
if self.created_at else None

0 commit comments

Comments
 (0)