diff --git a/almanac.py b/almanac.py index 002e72f..cb225db 100755 --- a/almanac.py +++ b/almanac.py @@ -165,12 +165,14 @@ def body(name): # @cached({}) -def time(t): +def time(t, *a, **k): "python datetime (UT1) -> skyfield time" if isinstance(t, Time): return t - # return ts.from_datetime(t.replace(tzinfo=utc)) - return ts.ut1(t.year, t.month, t.day, t.hour, t.minute, t.second + t.microsecond / 1e6) + if isinstance(t, datetime): + # return ts.from_datetime(t.replace(tzinfo=utc)) + return ts.ut1(t.year, t.month, t.day, t.hour, t.minute, t.second + t.microsecond / 1e6) + return datetime(t, *a, **k) def dtime(t): @@ -911,10 +913,10 @@ def render(template, variables={}, progress=None): }) env.globals.update(variables) env.globals.update({ + "now": datetime.utcnow(), "today": datetime.utcnow().date(), "time": time, - "datetime": datetime, - "delta": timedelta, + "duration": timedelta, "days": lambda n: timedelta(days=n), "hours": lambda n: timedelta(hours=n), "dut1": delta_ut1, diff --git a/daily-pages.txt.j2 b/daily-pages.txt.j2 index 21c3f48..624495e 100644 --- a/daily-pages.txt.j2 +++ b/daily-pages.txt.j2 @@ -11,7 +11,7 @@ IERS polar motion data until {{iers("P","I")}}, predictions until {{iers("P","P" {%- endif %} {% for d in range(odays,odays+ndays,nhours//24) %} -{%- set t = datetime(year,1,1)+days(d) %} +{%- set t = time(year,1,1)+days(d) %} {%- set t1 = t+days((nhours/24/2)|int) %} {%- set t2 = t+hours(nhours/2) %} {{-t|f("{:%Y %B %d (%a)}")}} dUT1=UT1-UTC={{dut1(t2)|f("+0.0000s")}} dTT=TT-UT1={{dtt(t2)|f("+0.0000s")}} diff --git a/nautical-almanac.tex.j2 b/nautical-almanac.tex.j2 index ad1969b..5e1f57c 100644 --- a/nautical-almanac.tex.j2 +++ b/nautical-almanac.tex.j2 @@ -293,7 +293,7 @@ HoE = Height of Eye, Alt = Apparent Altitude = Sextant altitude corrected for in \fancyhead{} \fancyhead[C]{\textsf{Index to Selected Stars}} % -{%- set t=datetime(year,1,1) %} +{%- set t=time(year,1,1) %} \begin{tabular}[t]{|l|r|r|r|r|} \hline \V Name & No & Mag & SHA & Dec \\ @@ -355,7 +355,7 @@ HoE = Height of Eye, Alt = Apparent Altitude = Sextant altitude corrected for in \fancyfoot[C]{\footnotesize\textsf{\texttt{ {{-ephemeris}}}} ephemeris} {%- endif %} {%- for D in range(odays,odays+ndays,pdays) %} -{%- set t = datetime(year,1,1)+days(D) %} +{%- set t = time(year,1,1)+days(D) %} % % {{t}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %