Propose: Simple date validation operator

37 views
Skip to first unread message

TonyM

unread,
Mar 3, 2020, 6:25:11 PM3/3/20
to TiddlyWikiDev
Folks,

In this thread David asks how to generate a range of dates. 

This made me ask myself what if we had an operator that given a date input of the standard TiddlyWiki form YYYYMMDD+ 
it was able to filter out invalid dates according to calendar rules

That is if 20200229 or 20200229231215828  is filtered eg "is[validdate]" it would be passed through as there is a 29th of february this year.
That is if 20210229 or 20210229231215828 would not be because there is no leap year in 2021

This may be a simple javascript date function already available in tiddlywiki.

It would then become possible to do the following;

<$list filter="[range[1,31]addprefix[202002]is[validdate]]">

</$list>
to generate a list of February 2020 valid days of the month
I have not complicated the above with the need to zero fill the range value

From this proposed filter it would be very easy to generate date ranges or test any YYYMMDD for validity

This could as easily extend to time as well if required is[validtime] HHMMSS

What do you think?
Can someone help me make this so?

Regards
Tony

TonyM

unread,
Mar 3, 2020, 7:04:34 PM3/3/20
to TiddlyWikiDev
Folks,

As continues in the thread the inability to format a variable as a date is still a restriction.

I add it here because if the Original thread request can be satisfied by a simple widget clone and modify, perhaps this can use a similar mechanism.

The View widget only operates on text references so you first have to store dates.

My proposal to allow variable input was rejected as overloading the view widget. 
But this remains a serious gap for simple date manipulation and assumes standard date fields are all we use.

If the view widget can not accept dates could we have a simple date-format widget 
<$date-format date=<<variablename>> template="DDD DDth MMM YYYY"/>
<$date-format date=<<variablename>> format=relativedate"/>


The above would also accept text references, no output and perhaps an emptyMessage could be triggered for an invalid date.

Regards
Tony

TonyM

unread,
Mar 4, 2020, 7:40:54 PM3/4/20
to TiddlyWikiDev
Post Script;

I believe this proposed validatedate operator would would unlock the possibility of a lot of date handling without the inclusion of more complex date handling plugins etc...

Just to explain a little further using nested range operators it would be possible to generate any number of years, months and days such as from 1 to 31 days and have the proposed validate eliminate invalid dates. This would be good for producing date tiddlers or rejecting invalid date entries eg
[{date}is[validdate]]" emptyMessage="Invalid date"

  • Then the valid date(s) can be used to test for the existence or list tiddlers.
  • One could even use a generated list of valid dates to do relative dates such as +45 days later using the set widget index parameter
The inability to format a variable as a date is still a restriction

Regards
Tony

On Wednesday, March 4, 2020 at 10:25:11 AM UTC+11, TonyM wrote:
Reply all
Reply to author
Forward
0 new messages