Time format for Sunrise/Sunset

53 views
Skip to first unread message

K1IW

unread,
Jul 8, 2020, 9:55:06 PM7/8/20
to weewx-user
I've installed weewx at two different locations.  For the HTML page, on the first, both the current time and sunrise/sunset are displayed in 12-hour time.
On the second, current time is in 12-hour, but sunrise/sunset are in 24-hour.

I'd like them to both be 12-hour.   I looked at the one that already shows in 12-hour and can't find the string "%I:" in any of the
configuration files.  I've also diff'd the config files between the servers and can't find any differences that can explain this.
Granted, there are a LOT of files, so maybe I missed one.

What controls the time format of sunrise/sunset?

Both are weewx 4.1.1


Thanks,
Bob

gjr80

unread,
Jul 8, 2020, 10:59:16 PM7/8/20
to weewx-user
Hi,

You haven't said which skin your are using, but since Seasons is the default skin for a new/clean 4.1.1 install I will assume you are using Seasons.

If you have a look in weewx.conf under [StdReport] [[Defaults]] [[[Units]]] you should find a [[[[TimeFormats]]]] stanza as follows:

                # The following section sets the format for each time scale.
               
# The values below will work in every locale, but they may not look
               
# particularly attractive.
               
[[[[TimeFormats]]]]
                hour = %H:%M 
                day = %X
                week = %X (%A)
                month = %x %X
                year = %x %X
               rainyear = %x %X
                current = %x %X 
                ephem_day = %X
ephem_year
= %x %X

This stanza defines the default date-time formats used by tags in various contexts. Unless they have been specifically changed the date-time in the Seasons title bar will use the current format and the sunrise/sunset the ephem_day format. The %x and %X formats depend on the system locale, so systems set to a different locale may in fact show different formats for the same date-time data (this was done not to necessarily be correct for all users but to at least give all users readable/sensible output). That being said on a given system under a default install the time component of the current time and sunrise/sunset time should be in the same format (%X) as should the format of the date component of the current time and sunrise/sunset time (%x). were you by chance looking at your system in the morning where the current time would be before midday and the sunset time after midday, this could give the appearance of the current time being in 12 hour format whilst sunrise/sunset is in 24 hour format.

You can of course change the defaults which is quite acceptable and encouraged (these changes will survive a WeeWX upgrade). You can also force the formats used for each tag by specifying the date-time format to be used in the individual tags in the template concerned, again this should be safe across upgrades.

Gary

K1IW

unread,
Jul 9, 2020, 2:11:44 PM7/9/20
to weewx-user
You are correct about Seasons and Locale.

The one that was in 12 hour had a US locale.  The one that was in 24 hour had a GB locale.
When I fixed the locale of the latter, it went to 12-hour.

Note though:  When I changed  "hour ="  to "%I:%M %p", it had no effect.  I had to change the locale to get it to work the way I wanted.


Thanks,
Bob

gjr80

unread,
Jul 9, 2020, 6:03:45 PM7/9/20
to weewx-user
Good that you got the outcome you wanted.

Just to wrap up, your changes to the ‘hour’ time format will have no effect on the Seasons main page. I mentioned in my previous post that the format applied is context dependent. By this I mean that the default format applied depends on the WeeWX tag being used. ‘current’ is applied to $current and $trend tags; ‘day’ is the most common and is applied to $hour, $day and $span tags; ‘week’ is applied to $week tags; ‘month’ is applied to $month tags and ‘year’ is applied to $year and $rainyear tags. ‘hour’ is only applied when iterating over the hours in a $day tag (eg, ‘hour’ is applied to the $hours tag in for $hours in $day). There are a few other special cases I won’t go into.

Bottom line is to change the current date-time and sunrise/sunset time formats on the Seasons home page you need to modify the ‘current’ and ‘ephem_day’ format setting respectively.

Gary
Reply all
Reply to author
Forward
0 new messages