Skip to content

Commit

Permalink
Final date fix for statistics (#32)
Browse files Browse the repository at this point in the history
* Fix date problem with statistics endpoint.

* Increment version number 0.3.2

* Patch 1

* Patch 2
  • Loading branch information
DurgNomis-drol authored Aug 3, 2021
1 parent 4d4f686 commit 3c193f6
Show file tree
Hide file tree
Showing 3 changed files with 747 additions and 730 deletions.
25 changes: 21 additions & 4 deletions mytoyota/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ async def get_driving_statistics(
interval: can be "day", "week" or "month". Default "month"
from_date: from which date you want statistics. Default is current day,
week or month if None.
Week numbers are not ISO week numbers, but Japan week numbers.
A week starts on a Sunday and not Monday.
Will return null if no ride have been performed in the timeframe.
"""

if interval not in ("day", "week", "month"):
Expand All @@ -138,15 +144,26 @@ def calculate_from_date() -> str:
return date

if interval == "week":
date = arrow.now().span("week", week_start=7)[0].format("YYYY-MM-DD")

if date == arrow.now().format("YYYY-MM-DD"):
date = (
arrow.now()
.span("week", week_start=7)[0]
.shift(days=-1)
.format("YYYY-MM-DD")
)
return date

date = arrow.now().floor("month").format("YYYY-MM-DD")

if date == arrow.now().format("YYYY-MM_DD"):
date = (
arrow.now()
.span("week", week_start=7)[0]
.span("month", week_start=7)[0]
.shift(days=-1)
.format("YYYY-MM-DD")
)
return date

date = arrow.now().floor("month").shift(days=-1).format("YYYY-MM-DD")
return date

if from_date is None:
Expand Down
Loading

0 comments on commit 3c193f6

Please sign in to comment.