Curious Observation great date hack?, title field synonymous with currentTiddler & optional challenge.

103 views
Skip to first unread message

TW Tones

unread,
Jul 30, 2020, 10:02:51 PM7/30/20
to tiddl...@googlegroups.com
Folks,

[edited more examples]
[note] As in this thread the use of UTC with dates can help improve the accuracy.

For the intellectually or wiki text, curious, I stumbled upon the following as a result of someone else's code

I have not yet published many wikis and plugins because I am still exploring all the fundamental methods without resorting to javascript. This is and example of how I overcame a serious limitation by discovering something which is perhaps an undocumented feature. If there is a gap, I am trying to fill it.

However I give you notice I hope to publish a large number of macros, tools and plugins in the near future, especially to support designers and rapid development.

Try this on tiddlywiki.com in a tiddler
<$list filter="[range[10,100,10]]">
{{!!title}}
</$list>
This seems intuitive correct but if you think about it the `{{!!title}}` field, does not exist for the virtual tiddlers that result from this range widget.

Why would I care?
  • In tiddlywiki the only inbuilt way to translate a date serial number into a date is the view widget
    • eg `<$view tiddler="" $field="" format="date" template="YYYY-0MM-0DD"/>`
    • or  `<$view tiddler="" $field="" format="relativedate"/>`
  • Created and modified dates as fields are an exception to this rule try {{!!created}} to see what I mean.
  • The view widget does not permit variables as input, which has being a long time annoyance to me
  • I now have an avenue to bypass this limitation, also observed in use in some of JED's code
For example provide a literal date as a variable via the list, but use the title as a field
<$list filter="[[20210506]]">
<$view field=title format="date" template="YYYY-0MM-0DD"/>
</$list>
  • Not sure If I can get the relative date even with a full date serial (yet)
Another exciting development, try this
<$list filter="[range[20210215,20210315,1]]">
<$view field=title format="date" template="YYYY-0MM-0DD"/>
<br>
</$list>
I am incrementing the date 2021/02/15 one day at a time until 2021/03/15
  • Notice the list only returns valid dates
  • Now you can get a list of valid dates 
Recognises year change
<$list filter="[range[20201225,20210105,1]]">
<$view field=title format="date" template="YYYY-0MM-0DD"/>
<br>
</$list>

Use to convert formats
<$list filter="[[2020-12-25]split[-]join[]]"><!-- or variable,field etc -->
<$view field=title format="date" template="0DD/0MM/YYYY"/>
<br>
</$list>
Whilst I could use join[/] I would not reorder the values, as in this case

Other interesting and working examples
<$list filter="[range[20201201,20211201,100]]">
<$view field=title format="date" template="DDD YYYY-0MM-0DD"/>
<br>
</$list>
What is the day of week of the first of every month?

Adding 7 days creeps forward? Not quite right?
<$list filter="[range[20201225,20210105,7]]">
<$view field=title format="date" template="0WW DDD YYYY-0MM-0DD"/>
<br>
</$list>
What is happening here, whats wrong with the order, is there a work around.

Conclusions
  • Setting currentTiddler in a list via a filter allows you to use any filter to set a value, including a variable and use title as the input to the ViewWidget.
  • This opens the view widget up to any date even if it is a variable (or any other widget with this limitation?)
  • given it only returns valid dates, it is a source of a series of valid dates taking into account the changes inherit in calendars
  • It can be used to reformat any valid date even as a variable, or generated with increments.
  • A set of easy to use wikitext macros can be written to count, generate, manipulate dates, without any plugin or JavaScript code.
Optional challenge(s) (for the reader)
  • It could be used to generate a method of counting days between two dates (left for the curious) 
    • Tip count the output?
  • Used to generate date tiddlers of any format.
[Edited Post script]

So just to be clear a revolutionary approach here we can use variable dates > to view Widget
should look like this

Working examples on tiddlywiki.com

\define var-date() 19230217
<$set name=today-date value="20200731">
<$set name=formatted-date value="2020/31/07">
<$wikify name=field-date text="{{!!field-date}}">


Format variable date <$list filter=<<var-date>> >
<$view field=title format="date" template="YYYY-0MM-0DD"/>
</$list>

or

Tomorrow <$list filter="[<today-date>add[1]]" >
<$view field=title format="date" template="YYYY-0MM-0DD"/
>
</$list>

or

Yesterday <$list filter="[<today-date>subtract[1]]" >
<$view field=title format="date" template="YYYY-0MM-0DD"/
>
</$list>

or

Formatting <<formatted-date>> to
<$list filter="[<formatted-date>split[/]join[]]" >
<$view field=title format="date" template="
0DD-0MM-YYYY"/>
</$list>

Or

From field as variable <$tiddler tiddler=<<field-date>> >
<$view field=title format="date" template="YYYY-0MM-0DD"/
>
</$tiddler>

</
$wikify></$set></$set>

Regards
TW Tones

CJ Veniot

unread,
Jul 30, 2020, 10:47:49 PM7/30/20
to TiddlyWiki
That is such wickedly awesome stuff, but I should know better than to try to grasp all of this when I've already gone past my bedtime.

I'll be going to bed counting filters jumping over tiddlers.  Hoping to get a good sleep so I can look at this all over again bright-eyed and bushy-tailed.

Still bright enough at the moment to belt out a happy "BRAVO!"  and "ENCORE!"
On Thursday, July 30, 2020 at 11:02:51 PM UTC-3 TW Tones wrote:
Folks,
Regards
TW Tones

Eric Shulman

unread,
Jul 30, 2020, 11:27:25 PM7/30/20
to TiddlyWiki
On Thursday, July 30, 2020 at 7:02:51 PM UTC-7, TW Tones wrote:
For example provide a literal date as a variable via the list, but use the title as a field
<$list filter="[[20210506]]">
<$view field=title format="date" template="YYYY-0MM-0DD"/>
</$list>

Very clever!

Note also that you can use the <$tiddler> widget to achieve the same effect:
<$tiddler tiddler="20210506">

<$view field=title format="date" template="YYYY-0MM-0DD"/>
</$tiddler>

I just updated http://TiddlyTools.com/timer.html to use this technique in the TiddlyTools/Timer, timer_showdate() macro.

Previously, I was constructing my date/time format by manually splitting the 17-digit timestamp into parts and
then outputting the parts individually.    Using your method of formatting a variable containing a timestamp,
the code is much simpler... and, it also made it possible to add a configuration option in TiddlyTools/Timer/Setup
so that the Task timer date/time format now can be easily customized.

Good catch!

-e


TW Tones

unread,
Jul 31, 2020, 3:53:55 AM7/31/20
to TiddlyWiki
Eric/all,

Glad I could teach you something for a change, you are always teaching me something, thanks for expanding this knowledge to include the tiddlers widget.

All,

So just to be clear a revolutionary approach here we can use variable dates to view Widget
should look like this

Working examples on tiddlywiki.com, added to top post.
\define var-date() 19230217
<$set name=today-date value="20200731">
<$set name=formatted-date value="2020/31/07">
<$wikify name=field-date text="{{!!field-date}}">


Format variable date <$list filter=<<var-date>> >
<$view field=title format="date" template="YYYY-0MM-0DD"/>
<
/$list>


or
Tomorrow <$list filter="[<today-date>add[1]]" >
<$view field=title format="date" template="YYYY-0MM-0DD"/
>
</$list>


or
Yesterday <$list filter="[<today-date>subtract[1]]" >
<$view field=title format="date" template="YYYY-0MM-0DD"/
>
</$list>


or


Formatting <<formatted-date>> to
<$list filter="[<formatted-date>split[/]join[]]" >
<$view field=title format="date" template="YYYY-0MM-0DD"/
>
</$list>


Or


From field as variable <$tiddler tiddler=<<field-date>> >
<$view field=title format="date" template="YYYY-0MM-0DD"/
>
</$tiddler>


</
$wikify></$set></$set>

Regards
Tony

TW Tones

unread,
Jul 31, 2020, 6:35:48 AM7/31/20
to TiddlyWiki
The formatted date example given is not working. I am not sure why yet.

Regards
Tony

Werner

unread,
Jul 31, 2020, 6:50:42 AM7/31/20
to TiddlyWiki
Tony,

I tried it and also came upon that it just SEEMS to work. Consider this slight change to your code, and you will find out why:

<$list filter="[range[20210215,20210315,1]]">
<$view field=title format="number" />
<$view field=title format="date" template="YYYY-0MM-0DD"/><br>
</$list>

So, the starting and end points in the range are interpreted as numbers and count up correctly (number-wise). So after 20210228, there'll be 20210229 which the date formatter seems to interpret as 20210301. This goes on until 20210299 and 20210300 which, again, is interpreted as 20120228. Then the count-up continues until 20210315. 

So, nice catch, but unfortunately doesn't work.

Best,
Werner

Eric Shulman

unread,
Jul 31, 2020, 8:43:55 AM7/31/20
to TiddlyWiki
Tony,

one small detail:

The <$view> widget's time output is shifted by time zone.
To correct for this, the output template needs to use the "[UTC]" prefix.

Thus, for my timezone (West coast, US which is currently 7 hours behind UTC)

<$tiddler tiddler="2020073112000000000">
<$view field="title" format="date" template="YYYY 0MM 0DD 0hh:0mm:0ss.0XXX" />
</$tiddler>

gives: 2020 07 31 05:00:00.000 (which is 7 hours too early!)


while

<$tiddler tiddler="2020073112000000000">
<$view field="title" format="date" template="[UTC]YYYY 0MM 0DD 0hh:0mm:0ss.0XXX"/>
</$tiddler>

gives: 2020 07 31 12:00:00.000 (which is correct)


-e

TW Tones

unread,
Jul 31, 2020, 9:09:12 AM7/31/20
to TiddlyWiki
Thanks Werner and Eric

That utc oftenn bites me back.

It seems we can hide some of this detail in some macros.

Cool eh?

TW tones

Eric Shulman

unread,
Jul 31, 2020, 10:08:02 AM7/31/20
to TiddlyWiki
On Friday, July 31, 2020 at 6:09:12 AM UTC-7, TW Tones wrote:

That utc often bites me back.


Yeah.... if you are just showing dates,
then it can *seem* to work, depending
on what time of day it is when you test!

-e


 
 
Reply all
Reply to author
Forward
0 new messages