Excellent, thanks. I think I started down this route but then lost my way. I'll have to get it focused.
Is there a way to have JavaScript and moment.js, or strftime.js, take advantage of this same formatting/customization? Maybe something you've done with WeeRT? On Friday, December 28, 2018 at 5:30:48 PM UTC-5, Tom Keffer wrote: > > OK, I think I see what you're trying to do. > > You are returning formatted strings, when you should be returning > ValueHelpers. Take the value "eqtime": this would look something like > this (NOT TESTED): > > # Assuming eqtime is in Unix Epoch Time...? > eqtime = eqdata["features"][0]["properties"]["time"] > eq_vt = weewx.units.ValueTuple(eqtime, "unix_epoch", "group_time") > eq_vh = weewx.units.ValueHelper(eq_vt, > context='year', > formatter=self.generator.formatter, > converter=self.generator.converter) > > ... > > search_list_extension = { > ... > earthquake_time: eq_vh > ... > } > > Do something similar for all your variables. The whole > "search_list_extension" data structure should return pretty much nothing > but ValueHelpers. > > Slightly more complicated, yes, but in exchange, you let WeeWX take care > of localization, formatting, etc. Best yet, if the user decides s/he wants > to change how yearly dates are formatted, it changes *everywhere*, > including in your skin! > > The key is understanding the two classes ValueTuple and ValueHelper. They > are both pretty simple. It's worth taking a look. > > -tk > > > > On Fri, Dec 28, 2018 at 2:07 PM Pat O'Brien <p...@obrienphoto.net > <javascript:>> wrote: > >> Ok cool, this is helpful especially for the Cheetah and all_stats, thanks! >> >> I'm still a bit lost on the SLE. If we keep going with the Earthquake >> example, it's defined here >> <https://github.com/poblabs/weewx-belchertown/blob/master/bin/user/belchertown.py#L665> >> as >> a string already formatted. This is a perfect example of what I'm trying to >> fix to allow user customization. So, should I return that as an epoch to >> Cheetah? Or another method? >> >> For the records page, I'm also doing custom $year, which may not be >> applicable for all $year throughout the skin - so that's why I was focused >> on a custom TimeFormat for that page specifically. >> >> On Friday, December 28, 2018 at 5:02:52 PM UTC-5, Tom Keffer wrote: >>> >>> 1. If no context is specified, then the default is "current", which is >>> not what you'd want for $alltime. Something like "year" would be more >>> appropriate. So, the TimespanBinder in example "stats.py" should probably >>> be written as >>> >>> all_stats = TimespanBinder(timespan, >>> db_lookup, >>> context=year, >>> formatter=self.generator.formatter, >>> converter=self.generator.converter, >>> skin_dict=self.generator.skin_dict) >>> >>> 2. If the SLE returns a ValueHelper (it should), then the time >>> formatting will be taken care of. That's its job! >>> >>> -tk >>> >>> >>> On Fri, Dec 28, 2018 at 1:52 PM Pat O'Brien <p...@obrienphoto.net> >>> wrote: >>> >>>> 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> >>>>> 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 >>>>>>>> >>>>>>>