Eric, Thanks for taking a look. I'll respond to this and then move any further discussion to the other section.
I think we're very much on the same page; this first (pre-Alpha) version does leverage Date.formatString, n times for however many "@@" Biel-date strings (probably should be once for all), and again with the whole string for local datetime, just as you suggest. The big difference in what you're saying seems to be the point of interception, that the replacement macro really isn't necessary, and I agree that the hijack approach on the Date method itself is much more elegant. Not sure I would have had the audacity to try it as a first attempt even if I had been aware that the hijack syntax applied to core objects (it's doing that with button object, I wasn't thinking of broader applications at the time), but I will. Should be fun. It's going to need another name... Thanks. On May 19, 11:01 pm, Eric Shulman <[email protected]> wrote: > > A couple of days ago it occurred to me that it might be preferable to > > have the core date-handling routine as a stand-alone pure Javascript > > function (declared as a window variable), so that it could be called > > by any other program in TiddlyWiki... or maybe even ported elsewhere. > > If anyone decides to critique the code, please keep in mind that less > > than three weeks ago I had never touched a line of Javascript. > > Even though you are just starting out with both TiddlyWiki and > Javascript, it's quite apparent that you 'grok' software, and you've > done reasonably well by following the patterns in the existing code. > However, for this particular use-case, there may be a *much* simpler, > more generalized way to add your functionality... > > The key is to know that the TW core is already defining an > extended .formatString() method that converts standard JS Date() > objects into formatted text strings, using specified 'date format > codes': > ------------------------------------------ > Date.prototype.formatString = function(template) > { > var t = template.replace(/0hh12/g,String.zeroPad(this.getHours12(), > 2)); > t = t.replace(/hh12/g,this.getHours12()); > t = t.replace(/0hh/g,String.zeroPad(this.getHours(),2)); > ... > t = t.replace(/\\/g,""); > return t;}; > > --------------------- > When applied to a date object ('this'), the function uses regular > expressions to selectively match and replace the various format codes > (e.g., "0hh12", "hh12", etc.) contained in the input parameter > ('template') with their respective values and then returns the > resulting text string. > > For your purposes, all you really want to do is to add your "bbb.bb" > and @...@ format processing to the existing .formatString() code, so > that use of the SIT format codes with all *existing* TW features -- > including the core's <<newJournal>> macro, as well as any plugins that > render formatted dates -- without needing any new macro definitions at > all! > > The best way to do this is to *hijack* the existing function, like > this: > > //save existing function > Date.prototype.formatString_SIT_orig=Date.prototype.formatString; > //redefine function > Date.prototype.formatString = function(template) { > ... SIT processing goes here ... > ... replaces "bbb.bb" and "@...@" sequences in template ... > // let core do rest of the work... > return this.formatString_SIT_orig(template); > > } > > When .formatString() is invoked, any SIT format sequences in the input > 'template' (date format string) are first replaced with their > respective output text (e.g. 921.54) and then the modified template is > passed on to the core so any remaining format codes can be converted. > > Of course, the specific code for "SIT processing" is up to you to > figure out... but I think you get the idea... > > enjoy, > -e > Eric Shulman > TiddlyTools / ELS Design Studios > > note: in order to avoid becoming too "tech heavy" in this group, > further discussions about TiddlyWiki plugin development and javascript > programming techniques should be moved to the TiddlyWikiDev group. > Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/TiddlyWiki?hl=en -~----------~----~----~----~------~----~------~--~---

