I can't think of any cool trick using the existing set of tags, so you would have to define a new search list extension. Call it $midnight.
It would look something like this (NOT TESTED):
from weewx.cheetahgenerator import SearchList
from datetime import datetime, timedelta
class Midnight(SearchList):
def midnight(self, epoch_time, direction=+1):
"""
Determine the time at midnight
Args:
epoch_time (float|int): The reference time
direction (int): The direction to search for midnight.
For example, +1 would mean midnight tonight, +2 midnight tomorrow night, etc.
Returns:
float: The time at midnight in Unix epoch time
"""
# Convert epoch to datetime
time_dt = datetime.fromtimestamp(epoch_time)
# Calculate midnight
target_midnight = time_dt.replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(days=direction)
# Convert back to epoch time
midnight_epoch = target_midnight.timestamp()
To use:
#if $tide.event_ts.raw > $midnight($tide.event_ts.raw)
#set day_when="tomorrow"
#else
#set day_when="today"
#end if
<p>The next <span style="color: red">HIGH</span> tide is at $tide.event_ts.format("%H:%M") $day_when</p>
I'm sure I made some errors in there, but hopefully you get the idea.
-tk