Skip to content

Commit

Permalink
Merge pull request #197 from Snuffy2/Show-since-month-and-date-locale…
Browse files Browse the repository at this point in the history
…-specific

Show locale specific (since date)
  • Loading branch information
Snuffy2 authored Aug 6, 2023
2 parents 44a3545 + 744fc86 commit fc90918
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions custom_components/places/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import copy
import hashlib
import json
import locale
import logging
import os
import re
Expand Down Expand Up @@ -2351,7 +2352,7 @@ def do_update(self, reason):
f"({self.get_attr(CONF_NAME)}) New State from DeviceTracker Zone Name: "
+ f"{self.get_attr(ATTR_NATIVE_VALUE)}"
)
current_time = "%02d:%02d" % (now.hour, now.minute)
current_time = f"{now.hour:02}:{now.minute:02}"
self.set_attr(
ATTR_LAST_CHANGED, str(now.isoformat(sep=" ", timespec="seconds"))
)
Expand Down Expand Up @@ -2472,10 +2473,21 @@ def change_dot_to_stationary(self, now, changed_diff_sec):

def change_show_time_to_date(self):
if not self.is_attr_blank(ATTR_NATIVE_VALUE) and self.get_attr(CONF_SHOW_TIME):
localedate = str(locale.nl_langinfo(locale.D_FMT)).replace(" ", "")
if localedate.lower().endswith("%y"):
localemmdd = localedate[:-3]
elif localedate.lower().startswith("%y"):
localemmdd = localedate[3:]
else:
localemmdd = "%m/%d"
mmddstring = (
datetime.fromisoformat(self.get_attr(ATTR_LAST_CHANGED))
.strftime(f"{localemmdd}")
.replace(" ", "")[:5]
)
self.set_attr(
ATTR_NATIVE_VALUE,
f"{self.get_attr(ATTR_NATIVE_VALUE)[: -14]}"
+ f" (since {datetime.fromisoformat(self.get_attr(ATTR_LAST_CHANGED)).strftime('%m/%d')})",
f"{self.get_attr(ATTR_NATIVE_VALUE)[: -14]}" + f" (since {mmddstring})",
)

if not self.is_attr_blank(ATTR_NATIVE_VALUE):
Expand Down

0 comments on commit fc90918

Please sign in to comment.