Skip to content

Commit

Permalink
Fix time timezone detection
Browse files Browse the repository at this point in the history
  • Loading branch information
stickpin committed May 23, 2024
1 parent 503d10b commit 76fd853
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions custom_components/meinvodafone/MeinVodafoneContract.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def minutes_remaining(self):
@property
def minutes_remaining_last_update(self):
"""Return remaining minutes for the plan last update timestamp."""
return self.get_value(MINUTES, LAST_UPDATE)
return datetime.datetime.strptime(
self.get_value(MINUTES, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S"
).replace(tzinfo=datetime.UTC)

@property
def is_minutes_remaining_supported(self):
Expand All @@ -107,7 +109,9 @@ def minutes_used(self):
@property
def minutes_used_last_update(self):
"""Return used minutes for the plan last update timestamp."""
return self.get_value(MINUTES, LAST_UPDATE)
return datetime.datetime.strptime(
self.get_value(MINUTES, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S"
).replace(tzinfo=datetime.UTC)

@property
def is_minutes_used_supported(self):
Expand All @@ -125,7 +129,9 @@ def minutes_total(self):
@property
def minutes_total_last_update(self):
"""Return total minutes for the plan last update timestamp."""
return self.get_value(MINUTES, LAST_UPDATE)
return datetime.datetime.strptime(
self.get_value(MINUTES, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S"
).replace(tzinfo=datetime.UTC)

@property
def is_minutes_total_supported(self):
Expand Down Expand Up @@ -153,7 +159,9 @@ def sms_remaining(self):
@property
def sms_remaining_last_update(self):
"""Return remaining sms for the plan last update timestamp."""
return self.get_value(SMS, LAST_UPDATE)
return datetime.datetime.strptime(
self.get_value(SMS, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S"
).replace(tzinfo=datetime.UTC)

@property
def is_sms_remaining_supported(self):
Expand All @@ -171,7 +179,9 @@ def sms_used(self):
@property
def sms_used_last_update(self):
"""Return used sms for the plan last update timestamp."""
return self.get_value(SMS, LAST_UPDATE)
return datetime.datetime.strptime(
self.get_value(SMS, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S"
).replace(tzinfo=datetime.UTC)

@property
def is_sms_used_supported(self):
Expand All @@ -189,7 +199,9 @@ def sms_total(self):
@property
def sms_total_last_update(self):
"""Return total sms for the plan last update timestamp."""
return self.get_value(SMS, LAST_UPDATE)
return datetime.datetime.strptime(
self.get_value(SMS, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S"
).replace(tzinfo=datetime.UTC)

@property
def is_sms_total_supported(self):
Expand Down Expand Up @@ -217,7 +229,9 @@ def data_remaining(self):
@property
def data_remaining_last_update(self):
"""Return remaining data for the plan last update timestamp."""
return self.get_value(DATA, LAST_UPDATE)
return datetime.datetime.strptime(
self.get_value(DATA, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S"
).replace(tzinfo=datetime.UTC)

@property
def is_data_remaining_supported(self):
Expand All @@ -235,7 +249,9 @@ def data_used(self):
@property
def data_used_last_update(self):
"""Return used data for the plan last update timestamp."""
return self.get_value(DATA, LAST_UPDATE)
return datetime.datetime.strptime(
self.get_value(DATA, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S"
).replace(tzinfo=datetime.UTC)

@property
def is_data_used_supported(self):
Expand All @@ -253,7 +269,9 @@ def data_total(self):
@property
def data_total_last_update(self):
"""Return total data for the plan last update timestamp."""
return self.get_value(DATA, LAST_UPDATE)
return datetime.datetime.strptime(
self.get_value(DATA, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S"
).replace(tzinfo=datetime.UTC)

@property
def is_data_total_supported(self):
Expand Down Expand Up @@ -306,14 +324,12 @@ def is_billing_last_summary_supported(self):
@property
def billing_cycle_days(self):
"""Return days until end of the billing cycle."""
datetime_now = (
datetime.datetime.now(datetime.UTC)
.replace(tzinfo=None)
.replace(hour=0, minute=0, second=0, microsecond=0)
datetime_now = datetime.datetime.now(datetime.UTC).replace(
hour=0, minute=0, second=0, microsecond=0
)
cycle_end = datetime.datetime.strptime(
self.billing_cycle_end, "%Y-%m-%d"
).replace(tzinfo=None)
).replace(tzinfo=datetime.UTC)
delta = cycle_end - datetime_now

return delta.days
Expand Down

0 comments on commit 76fd853

Please sign in to comment.