Add support for T and Z (#566)

pull/583/head
Igor Chubin 4 years ago
parent 51a924675a
commit 10392a878f

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

@ -234,6 +234,16 @@ def render_zenith(data, query, local_time_of):
Local time of zenith""" Local time of zenith"""
return local_time_of("noon") 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 = { FORMAT_SYMBOL = {
@ -257,6 +267,9 @@ FORMAT_SYMBOL_ASTRO = {
'S': render_sunrise, 'S': render_sunrise,
's': render_sunset, 's': render_sunset,
'z': render_zenith, 'z': render_zenith,
'T': render_local_time,
'Z': render_local_timezone,
} }
def render_line(line, data, query): 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) .replace(hour=0, minute=0, second=0, microsecond=0)
current_sun = sun(city.observer, date=datetime_day_start) 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)\ .replace(tzinfo=pytz.utc)\
.astimezone(local_tz)\ .astimezone(local_tz)\
.strftime("%H:%M:%S") .strftime("%H:%M:%S")

Loading…
Cancel
Save