Skip to content

Commit

Permalink
use tz in filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Grennan committed Aug 2, 2023
1 parent 3c4fa19 commit 2bf6698
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions be/ocpp/management/commands/run_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ocpp.models import Transaction

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

DATETIME_FORMAT = "'%Y-%m-%d %H:%M:%S"

Expand All @@ -22,8 +23,8 @@ def add_arguments(self, parser):

def handle(self, *args, **options):
tz = pytz.timezone(options["tz"])
options["start"] = options["start"].replace(tzinfo=datetime.timezone.utc)
options["end"] = options["end"].replace(tzinfo=datetime.timezone.utc)
options["start"] = tz.localize(options["start"])
options["end"] = tz.localize(options["end"])
if options["report_type"] == "transaction":
transactions = Transaction.objects.filter(
stopped_at__gte=options["start"], stopped_at__lt=options["end"]
Expand All @@ -44,8 +45,8 @@ def handle(self, *args, **options):
[
tx.id,
tx.charge_point,
(tx.started_at).astimezone(tz).strftime(DATETIME_FORMAT),
(tx.stopped_at).astimezone(tz).strftime(DATETIME_FORMAT),
tx.started_at.astimezone(tz).strftime(DATETIME_FORMAT),
tx.stopped_at.astimezone(tz).strftime(DATETIME_FORMAT),
tx.meter_stop,
tx.stop_reason,
]
Expand Down

0 comments on commit 2bf6698

Please sign in to comment.