Skip to content

Commit

Permalink
cleanup time
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Lucke committed Apr 3, 2023
1 parent 85355a3 commit 2967462
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions almanac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion daily-pages.txt.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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")}}
Expand Down
4 changes: 2 additions & 2 deletions nautical-almanac.tex.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 \\
Expand Down Expand Up @@ -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}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
Expand Down

0 comments on commit 2967462

Please sign in to comment.