date format variable?

41 views
Skip to first unread message

FND

unread,
Jun 28, 2007, 3:01:07 AM6/28/07
to Tiddl...@googlegroups.com
Hi all,

I have finally decided to upgrade all of my TWs to v2.2, so I'm
currently composing a sample (or prefab?) with all the basic components.

In order to display the dates in ISO 8601 format, I used to modify the
ViewTemplate like this:
<span macro='view modified date [[YYYY-0MM-0DD 0hh:0mm]]'></span>
[...]
<span macro='view created date [[YYYY-0MM-0DD]]'></span>
Now the default date format has vanished from the shadow ViewTemplate.

While it is still possible to simply add the format just like before, I
wonder whether there is a variable now that I could modify instead (via
my DefaultOptions tiddler).
That strikes me as a "cleaner" method - even though I'd lose the ability
to have a different timestamp for the "created" field...


-- F.

Simon Baird

unread,
Jun 28, 2007, 3:29:56 AM6/28/07
to Tiddl...@googlegroups.com
I do this kind of thing in MGTD alpha. It's not very nice though:

http://mgtd-alpha.tiddlyspot.com/#ViewTemplate


<div class='subtitle'>

<span macro='view modifier link'></span>,
<span macro="hideWhen store.getValue('MonkeyGTDSettings','mgtd.usemdy')=='true'">
<span macro='view modified date [[DD/MM/YY]]'></span>
(<span macro='message views.wikified.createdPrompt'></span>
<span macro='view created date [[DD/MM/YY]]'></span>)
</span>
<span macro="showWhen store.getValue ('MonkeyGTDSettings','mgtd.usemdy')=='true'">
<span macro='view modified date [[MM/DD/YY]]'></span>
(<span macro='message views.wikified.createdPrompt'></span>
<span macro='view created date [[MM/DD/YY]]'></span>)
</span>
</div>
--
simon...@gmail.com

FND

unread,
Jun 28, 2007, 3:33:16 AM6/28/07
to Tiddl...@googlegroups.com
> I do this kind of thing in MGTD alpha. It's not very nice though

So you also add the date format directly to the ViewTemplate? Or am I
missing something here?


-- F.

Simon Baird

unread,
Jun 28, 2007, 3:51:02 AM6/28/07
to Tiddl...@googlegroups.com
On 6/28/07, FND <Ace_...@gmx.net> wrote:

No there are two possible formats. And a checkbox to change between them. See here:
http://mgtd-alpha.tiddlyspot.com/#MonkeyGTDSettings

As I said, not nice.. :)

It would be much nicer to be able to enter the preferred format somewhere. (But please not a cookie, baked or otherwise.  :).

Simon.

--
simon...@gmail.com

FND

unread,
Jun 28, 2007, 4:04:52 AM6/28/07
to Tiddl...@googlegroups.com
> No there are two possible formats.

Ohh, now I see! Sorry, I didn't look closely enough before...

> It would be much nicer to be able to enter the preferred format
> somewhere. (But please not a cookie, baked or otherwise. :).

Agreed.
I just took a quick look at the code, and there is something interesting
in "config.macros.view.handler": "config.views.wikified.dateFormat" is
used when no format has been specified in the ViewTemplate - but I'm not
sure whether (or how) that could be used for our purposes then...


-- F.

BJ

unread,
Jun 28, 2007, 6:29:16 AM6/28/07
to TiddlyWiki
On Jun 28, 3:51 am, "Simon Baird" <simon.ba...@gmail.com> wrote:
> > > I do this kind of thing in MGTD alpha. It's not very nice though
>
>
> It would be much nicer to be able to enter the preferred format somewhere.
> (But please not a cookie, baked or otherwise. :).
>

Um... forgive me, it was a long night last night and I haven't had my
requisite 1500ml of carbonated sodium benzoated caffeine yet this
morning, but am I missing something here? Don't you do this in your
regular MPTW layout?? I've taken that and modified it just a touch,
but it basically does what I think is being asked for here...

In a configTweak or equivalent:

// used in MptwViewTemplate
config.mptwDateFormat = 'DD/MM/YY';
config.mptwJournalFormat = 'Journal DD/MM/YY';

And then in the view template (the Mptw one in this case):


<span macro='view modified date {{config.mptwDateFormat?
config.mptwDateFormat:"MM/0DD/YY"}}'></span>


(<span macro='message views.wikified.createdPrompt'></span>

<span macro='view created date {{config.mptwDateFormat?
config.mptwDateFormat:"MM/0DD/YY"}}'></span>)
</div>

Using this technique, I have a number of different variations which I
control in one place (date formats, time formats, etc...).

Wouldn't this be what was originally asked for??

FND

unread,
Jun 28, 2007, 6:32:06 AM6/28/07
to Tiddl...@googlegroups.com
> Wouldn't this be what was originally asked for??


Well, I guess this is sort of what I'd asked for - but it feels like a
dirty hack somehow (Simon has acknowledged that himself).
So if we could go through "config.views.wikified.dateFormat" somehow,
that'd be a cleaner (and presumably easier) method...


-- F.

BJ

unread,
Jun 28, 2007, 11:38:59 AM6/28/07
to TiddlyWiki

Well, then in that DefaultOptions tiddler (I call mine ConfigOverride,
but it's the same thing), could you not just override the value of
config.views.wikified.dateFormat to be what you wanted? There is also
config.macros.timeline.dateFormat that could be changed as well, to
use a different date format for the date "dividers" in the Timeline
tab.

Or add something like <<option txtDateFormat>> in the OptionsPanel,
and then refer to that (config.options.txtDateFormat) to override
config.views.wikified.dateFormat and
config.macros.timeline.dateFormat? (Or have a different option field
for the timeline format). I just tried that in a quick test and it
seemed to work okay.

BJ

unread,
Jun 28, 2007, 11:41:23 AM6/28/07
to TiddlyWiki
Of course, I just realized that the field in the option panel goes
against Simon's plea for not using "baked goods" for storing the
value... but it's always an option.

FND

unread,
Jun 28, 2007, 1:11:10 PM6/28/07
to Tiddl...@googlegroups.com
> could you not just override the value of
> config.views.wikified.dateFormat to be what you wanted? There is also
> config.macros.timeline.dateFormat that could be changed as well

Oh my - why didn't I just try that?! I somehow expected it not to work,
but it *does* indeed work! So now I'm using the following overrides:
config.views.wikified.dateFormat = "YYYY-0MM-0DD 0hh:0mm";
config.macros.timeline.dateFormat = "YYYY-0MM-0DD (ddd)";
No more need to touch the ViewTemplate for me...
Thanks, BJ!

One more thing: There's also an occurrence of dateFormat in connection
with listView; I'm not quite sure what the "ListView gadget" does
though; could anyone enlighten me?


-- F.

Simon Baird

unread,
Jun 28, 2007, 8:15:13 PM6/28/07
to Tiddl...@googlegroups.com
On 6/28/07, BJ <bjbac...@gmail.com> wrote:

On Jun 28, 3:51 am, "Simon Baird" <simon.ba...@gmail.com> wrote:
> > > I do this kind of thing in MGTD alpha. It's not very nice though
>
>
> It would be much nicer to be able to enter the preferred format somewhere.
> (But please not a cookie, baked or otherwise.  :).
>


In a configTweak or equivalent:

// used in MptwViewTemplate
config.mptwDateFormat = 'DD/MM/YY';
config.mptwJournalFormat = 'Journal DD/MM/YY';

And then in the view template (the Mptw one in this case):

<span macro='view modified date {{config.mptwDateFormat ?
config.mptwDateFormat:"MM/0DD/YY"}}'></span>
        (<span macro='message views.wikified.createdPrompt'></span>
        <span macro='view created date {{config.mptwDateFormat ?
config.mptwDateFormat:"MM/0DD/YY"}}'></span>)
</div>

Using this technique, I have a number of different variations which I
control in one place (date formats, time formats, etc...).

Wouldn't this be what was originally asked for??

Actually, yeah I forgot about that. Sorry, brain like a sieve.

But here's an even better idea I just learned from BramChen:

<span macro='view created date [[DateFormat::shortDateFormat]]'></span>

Because of of the [[ ]] notation for including stuff in templates this works without any need for {{ }} or setting config.anything.

(You put slices in DateFormat tiddler, eg:

shortDateFormat: DD-0MM-YYYY


Simon.



--
simon...@gmail.com

Simon Baird

unread,
Jun 28, 2007, 8:16:28 PM6/28/07
to Tiddl...@googlegroups.com
On 6/28/07, FND <Ace_...@gmx.net> wrote:

> Wouldn't this be what was originally asked for??


Well, I guess this is sort of what I'd asked for - but it feels like a
dirty hack somehow (Simon has acknowledged that himself).

Actually the MPTW technique is a lot better than the MGTD technique. But Bram's technique has to be the best. (See previous message).

So if we could go through "config.views.wikified.dateFormat" somehow,
that'd be a cleaner (and presumably easier) method...



--
simon...@gmail.com

Simon Baird

unread,
Jun 28, 2007, 8:21:46 PM6/28/07
to Tiddl...@googlegroups.com
On 6/29/07, FND <Ace_...@gmx.net> wrote:

> could you not just override the value of
> config.views.wikified.dateFormat to be what you wanted?  There is also
> config.macros.timeline.dateFormat that could be changed as well

Oh my - why didn't I just try that?! I somehow expected it not to work,
but it *does* indeed work! So now I'm using the following overrides:
     config.views.wikified.dateFormat = "YYYY-0MM-0DD 0hh:0mm";
     config.macros.timeline.dateFormat = "YYYY-0MM-0DD (ddd)";
No more need to touch the ViewTemplate for me...
Thanks, BJ!

I didn't know these ones either. Nice one BJ. But then do you remove the format embedded in ViewTemplate?? Never mind I will have to try it. Now does anyone want to write the definitive guide to TW date formats for the doco wiki?

Ps, The slice technique is still useful I think as it doesn't require a plugin to modify the format.



--
simon...@gmail.com

FND

unread,
Jun 29, 2007, 6:09:15 AM6/29/07
to Tiddl...@googlegroups.com
> But here's an even better idea I just learned from BramChen:
> <span macro='view created date [[DateFormat::shortDateFormat]]'></span>

That's brilliant!
More proof for the "TiddlyWiki makes you learn something new every day"
hypothesis...

N.B.: Make sure to use quotes in the DateFormat tiddler if the desired
format contains spaces.

In order to make this work for the timeline, use the following code in
your systemConfig tiddler (e.g. DefaultOptions or ConfigOverride):
config.macros.timeline.dateFormat =
store.getTiddlerSlice('DateFormat','shortDateFormat');
(I took that code from your solution in the "ColorPalette overview"
thread, Simon.)

N.B.: In this case, the date format must *not* be wrapped in quotes,
which is a bit of an annoying inconsistency.

That's one more reason to put this all into the systemConfig tiddler,
which is where it belongs anyway IMHO. But I don't know how to
distinguish between CREATED and MODIFIED dates then (I want both date
and time for MODIFIED, but only date for CREATED).

As for modifying variables in a systemConfig tiddler instead of
modifying the ViewTemplate:

> But then do you remove the format embedded in ViewTemplate??

Yes, because the default format (i.e. config.views.wikified.dateFormat)
is used if no dateFormat parameter has been specified.

> Now does anyone want to write the definitive guide to TW date
> formats for the doco wiki?

I'm not sure I could convey this in an understandable manner - I'll put
it on my to-do list though.


-- F.

BJ

unread,
Jun 29, 2007, 8:04:04 AM6/29/07
to TiddlyWiki

On Jun 28, 8:21 pm, "Simon Baird" <simon.ba...@gmail.com> wrote:
>
> I didn't know these ones either. Nice one BJ. But then do you remove the
> format embedded in ViewTemplate??

Actually, the base TW's shadowed ViewTemplate tiddler doesn't have any
date format embedded in it... the calls to the view macro for the
dates are just <span macro='view created date'></span> (or 'view
modified date').

> Ps, The slice technique is still useful I think as it doesn't require a
> plugin to modify the format.

Yes, that is a pretty slick way to do it, although obviously it would
require the modifications to the view template to support it.
However, given that other things in the base TW use that approach
(i.e. ColorPalette), it might make sense if this is also done for date
formats and other configuration pieces. My concern is if it would be
as "error-resistant" as needed... what would happen if somebody has a
modified (non-shadow) tiddler with the different slices, but
accidently deletes one of the slices that are needed? With it defined
as a specific variable, there would always be that to fall back on.

BJ

unread,
Jun 29, 2007, 8:21:20 AM6/29/07
to TiddlyWiki

On Jun 29, 6:09 am, FND <Ace_No...@gmx.net> wrote:
> > But here's an even better idea I just learned from BramChen:

> In order to make this work for the timeline, use the following code in
> your systemConfig tiddler (e.g. DefaultOptions or ConfigOverride):
> config.macros.timeline.dateFormat =
> store.getTiddlerSlice('DateFormat','shortDateFormat');
> (I took that code from your solution in the "ColorPalette overview"
> thread, Simon.)

Now THAT's interesting... and might address my concerns about being a
bit more "bullet-proof" -- perhaps using the conditional operator in
the equate to check to see if the tiddler slice can be obtained, and
leaving it alone or setting it to a default value if no slice is
returned.

Doing that same approach for config.views.wikified.dateFormat would
also eliminate the need to update the ViewTemplate code displaying the
created or modified dates, providing you wanted to use the same format
for both. I don't see why you couldn't create a different variable to
use for one of those cases, and then refer to it specifically in the
ViewTemplate where needed. I do something like that already to set
the date format used as the title for journal tiddlers.


>
> N.B.: In this case, the date format must *not* be wrapped in quotes,
> which is a bit of an annoying inconsistency.
>


I wonder if this relates to the comment in the base TW code (around
line 750) where the "translateable strings" are defined... it says
that strings in double quotes should be translated, strings in single
quotes will be left alone. Just a thought...

FND

unread,
Jun 29, 2007, 10:03:46 AM6/29/07
to Tiddl...@googlegroups.com
I've posted this suggested change (along with some code) on [twdev]:
http://groups.google.com/group/TiddlyWikiDev/t/2fe4e7bd3e01f8a6

Let's see what JR and the devs think...


-- F.

Reply all
Reply to author
Forward
0 new messages