[tw] Re: PrettyLink to a macro.. Swatch Internet Time in TiddlyWiki

2009-05-20 Thread rtimwest

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  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 <> 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 TiddlyWiki@googlegroups.com
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/TiddlyWiki?hl=en
-~--~~~~--~~--~--~---



[tw] Re: PrettyLink to a macro.. Swatch Internet Time in TiddlyWiki

2009-05-19 Thread Eric Shulman

> 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 <> 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 TiddlyWiki@googlegroups.com
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/TiddlyWiki?hl=en
-~--~~~~--~~--~--~---



[tw] Re: PrettyLink to a macro.. Swatch Internet Time in TiddlyWiki

2009-05-19 Thread rtimwest

Curious that you should bring up just that subject in response to my
own one-and-only post.

I wasn't going to mention this yet, and don't know if there's any
interest out there, but since you brought up the newJournal macro,
here goes...

Some of you are aware that I've been working on combining two of my
interests, TiddlyWiki and Swatch Internet Time (also called Internet
time, sometimes beat time or even .beats "dot beats").

For those of you that haven't run across it before, Internet Time is a
greatly simplified, limited-use form of timekeeping in which it's the
same time everywhere (no time zones and no "Daylight Savings" time),
which greatly simplifies coordinating people spread out over long
distances geographically (hence "Internet"), and in which the day is
divided into 1,000 equal parts, called "beats", which makes elapsed
time and intervals trivial to deal with compared to the old system
(24x60x60). It's usually displayed with an "@" symbol, as "@921" or
"@921.46", to keep it from being confused with any other time value.

I have long been a proponent of the system (against some resistance)
for appropriate uses (it's not intended to replace local time), and
had even written a defense of it, which I resurrected when I re-
started my site not long ago. It's up there now.

A week or so ago, after having created/altered a macro to display the
journals the way I wanted them, I wondered if I could also write
something to let me (just me) use Internet Time to time-stamp my
TiddlyWiki journals.

Turns out that date objects in Javascript are pretty sweet. Somewhat
to my surprise this proved to be very do-able as a replacement for the
"newJournal" macro (as called from the shadow tiddler SideBarOptions).
In fact, I was not only able to allow the use of "beats" in the title
(to three levels of precision), but it was possible to create a syntax
extension that allows that, plus the date and/or time in Biel,
Switzerland in any of the current possible formats (the date in Biel
is the one that should be used if a date is displayed in conjunction
with Internet Time), AND still preserve all of the current syntax for
displaying local time and date- nothing is lost. So, as of a couple of
days a go, my journal timestamps look like this:

Internet: 2009.05.20 @091.65  (local, 9:11 PM, May 19th, 2009)

A couple of bugs have come up and been fixed, a lot of typos, mistakes
and awkward phrasing in the docs/comments, and there are more user
options needed (the parameters are being used), but it's pretty much
worked fine. That was a few days ago..

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.
I rewrote it that way, did a quick and ugly hack job on Mr. Shulman's
DigitalClock (with apologies) as a proof-of-concept, and that's now
running in my title bar, displaying rolling Internet Time (to
centibeats).

So, if there is any interest out there, Internet Time is now available
in TiddlyWiki for journal timestamps, real-time clocks, or any other
program. Should be very straightforward for other programmers to call
in their code.

http://rtimwest.com (my site)
http://rtimwest.com/SwatchInternetTime (info, and link to the code)
http://rtimwest.com/newJournalPlusSIT  (straight to the code)

It's obviously very new, but it should be very safe- it's a very
minimal intercept of built-in functionality, just Javascript and TW
functions, and trivial to remove completely. If anyone cares to try it
at this very early stage, have fun and let me know, especially if you
find a problem (I already have a list of needed features... did I
mention that the parameters are already being used?).

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.

So... in answer to the reply, it just so happens that I've gotten
pretty familiar with how the newJournal macro works since my first
post here. ;-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to TiddlyWiki@googlegroups.com
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/TiddlyWiki?hl=en
-~--~~~~--~~--~--~---