There's no doubt I'm overthinking it, which is why I asked for help. I need 
to take an inventory of all the dates I'm using since they are all somewhat 
custom. Sure, for day/year/current those can be overridden, but for alltime 
how is that handled for a custom format? 

I have other dates that are not in Cheetah (see original post). Earthquake 
epoch is a custom observation within the SLE, as well as a few other custom 
queries. The MQTT JS timestamp update is also custom. So there's fringe 
cases where built-in day/year/current TimeFormat won't apply. Those are 
what I'm trying to account for. 

So if I were to define a TimeFormat for these edge cases, do I have the 
proper unit tag to get that string?

On Friday, December 28, 2018 at 4:36:09 PM UTC-5, Tom Keffer wrote:
>
> I think you're making things harder for yourself than you need to. For 
> something like 
>
> $year.outTemp.maxtime
>
> WeeWX will automatically format the time in something appropriate for a 
> "year" context. The default format is specified in the [[TimeFormats]]. 
> Yes, you can override it by using the ".format()" suffix, but you shouldn't 
> need to do that very often.
>
> I'm not sure where "earthquake" figures into things. Is it an observation 
> type? If so, there's no need to treat it any differently.
>
> One thing that's worth being aware of is when the evaluation is done. For 
> Cheetah, it's at the time of report generation. At that point, the value is 
> frozen in time in  the HTML page. So, it's the right thing to do for values 
> that change with an archive record, but the wrong thing for LOOP data. In 
> that case, you'd need to use something like moments.
>
> -tk
>
> On Fri, Dec 28, 2018 at 12:53 PM Pat O'Brien <p...@obrienphoto.net 
> <javascript:>> wrote:
>
>> For Cheetah, I'm using this tag. Is it correct? Seems a bit longhand. 
>>
>> $unit.format.formatter.time_format_dict.earthquake within the .format(). 
>>
>> $year.outTemp.maxtime.format($unit.format.formatter.time_format_dict.
>> records_page_full_date)
>>
>> Again, need to generalize the name, but really I'm looking for feedback 
>> on best approach. 
>>
>>
>> On Friday, December 28, 2018 at 2:04:45 PM UTC-5, Pat O'Brien wrote:
>>>
>>> Sometimes I need to ask a question out-loud in order to start finding 
>>> the answer. In the skin options, you can define custom time formats, as 
>>> long as that is used as the context in the formatter. 
>>>
>>> I'm doing this within the SLE and it seems to be working so far. In 
>>> weewx.conf, under skin options:
>>>
>>>         [[[Units]]]
>>>             [[[[TimeFormats]]]]
>>>                 day = %H:%M
>>>                 earthquake = "%B %d, %Y, %-I:%M %p %Z"
>>>
>>> Then in the SLE,
>>>
>>> print self.generator.formatter.toString(( eqdata["features"][0][
>>> "properties"]["time"] / 1000, "unix_epoch", "group_time" ), context=
>>> 'earthquake')
>>>
>>> Returns December 22, 2018, 10:19 PM EST
>>>
>>> Instead of "earthquake" I can do "full_date" and "half_date", or 
>>> something to make it a bit more generic. 
>>>
>>> I still need to figure out Cheetah and JavaScript's moment library to be 
>>> able to use the "earthquake" context for formatting, but this is a start. 
>>>
>>> I'm open to other ideas and ways to do this if anyone has any. 
>>>
>>>
>>>
>>> On Friday, December 28, 2018 at 1:29:18 PM UTC-5, Pat O'Brien wrote:
>>>>
>>>> Currently I have a problem where I've hard-coded the date and time 
>>>> format within the Belchertown skin. I know I need to change it but I'm not 
>>>> sure how. 
>>>>
>>>> I'm using a mixture of Python, JavaScript and Cheetah to make it 
>>>> cohesive - but for those outside of the USA who want their formats in 
>>>> day/month/year, I can't do much to help them. 
>>>>
>>>> This isn't everything, but some examples of how I'm formatting various 
>>>> dates within the skin. I think the only thing in common would be that they 
>>>> are all epoch - but I would need to verify each instance. 
>>>>
>>>> Cheetah:
>>>> $current.dateTime.format("%B %d, %Y at %I:%M %p") # Returns December 
>>>> 28, 2018, 1:17:18 pm
>>>> $almanac.sunset.format("%-I:%M %p") # Returns 7:17 AM
>>>> $current.dateTime.format("%A, %B %d, %Y") # Returns Friday, December 
>>>> 28, 2018
>>>> $current.dateTime.format("%B, %Y") # Returns December, 2018
>>>>
>>>> JavaScript:
>>>> moment(data["almanac"]["sunrise"], "HH:mm:ss A").format("h:mm A"); # 
>>>> Returns 7:17 AM
>>>> moment.unix( data['alerts'][i]['expires'] ).format( 'MMMM D, YYYY, 
>>>> h:mm A' ); # Returns December 31, 2018, 7:00 AM
>>>> moment.unix( data["daily"]["data"][i]["time"] ).format( "ddd M/D" ); # 
>>>> Returns Sat 12/29
>>>> moment.unix(epoch).utcOffset($moment_js_utc_offset).format("MMMM D, 
>>>> YYYY, h:mm:ss a"); # Returns December 28, 2018, 1:17:18 pm
>>>>
>>>> Python extension:
>>>> time.strftime( "%B %d, %Y at %-I:%M %p", time.localtime( 
>>>> at_rainiest_day_query[0] ) ) # Returns July 17, 2018 at 2:35 PM
>>>> time.strftime( "%a %m/%d", time.localtime( time.time() ) ) # Returns 
>>>> Sat 12/29
>>>> time.strftime( "%B %d, %Y, %-I:%M %p %Z", time.localtime( eqdata[
>>>> "features"][0]["properties"]["time"] / 1000 ) ) # Returns December 22, 
>>>> 2018, 10:19 PM EST
>>>>
>>>> I see in skin.conf there's [Units] [[TimeFormats]] and I'm sure this is 
>>>> probably something I want to tap into - unless this is purely for Cheetah 
>>>> tags ($current, $day, etc)?
>>>>
>>>> Can someone point me in the right direction on how best to offer time 
>>>> and date formats in the users locale?
>>>>
>>>> Thanks
>>>>
>>>

Reply via email to