Add support for T and Z (#566)

This commit is contained in:
Igor Chubin 2021-02-28 10:29:46 +01:00
parent 51a924675a
commit 10392a878f
2 changed files with 18 additions and 2 deletions

View File

@ -171,7 +171,9 @@ To specify your own custom output format, use the special `%`-notation:
S Sunrise*,
z Zenith*,
s Sunset*,
d Dusk*.
d Dusk*,
T current time*,
Z local timezone.
(*times are shown in the local timezone)
```

View File

@ -234,6 +234,16 @@ def render_zenith(data, query, local_time_of):
Local time of zenith"""
return local_time_of("noon")
def render_local_time(data, query, local_time_of):
"""local_time (T)
Local time"""
return "%{{NOW("+ local_time_of("TZ") +")}}"
def render_local_timezone(data, query, local_time_of):
"""local_time (Z)
Local time"""
return local_time_of("TZ")
##################################
FORMAT_SYMBOL = {
@ -257,6 +267,9 @@ FORMAT_SYMBOL_ASTRO = {
'S': render_sunrise,
's': render_sunset,
'z': render_zenith,
'T': render_local_time,
'Z': render_local_timezone,
}
def render_line(line, data, query):
@ -282,7 +295,8 @@ def render_line(line, data, query):
.replace(hour=0, minute=0, second=0, microsecond=0)
current_sun = sun(city.observer, date=datetime_day_start)
local_time_of = lambda x: current_sun[x]\
local_time_of = lambda x: city.timezone if x == "TZ" else \
current_sun[x]\
.replace(tzinfo=pytz.utc)\
.astimezone(local_tz)\
.strftime("%H:%M:%S")