A quiet Date

289 views
Skip to first unread message

S. S.

unread,
Apr 2, 2019, 1:38:29 PM4/2/19
to TiddlyWiki

It's been a quiet day today in TiddlyWikiLand.

I'd like to share a small macro I've been working on the past weeks to address a simple problem.

I wanted to solve the difficulty I had in displaying Common Format dates, such as 2019-04-02 as Tuesday 2nd April 2019.

I decided to see if I could make a macro to do this, and to make it both configurable and fit within one tiddler, just to see if I was able to do so. I never realized how much effort that takes.

Most of the questions I have been asking on the Group recently dealt with issues that arose in trying to make this macro!

The tiddler is attached below.

Regards.


date Macro ver.1.00.tid

TonyM

unread,
Apr 2, 2019, 6:26:16 PM4/2/19
to TiddlyWiki
S S,

Nice work and nicely documented. This certainly addresses a gap in date handling with formats similar to those used for new journal entries, I think it will suit many users. 

It will take time for me to decide if I would adopt it on a regular basis because I have favored using the full tiddlywiki serial number to represent dates. For example my new journal process adds a journal-date field to enable more sophisticated search and selection of journal entries. However it is nice to know if I want to go down the alternative "simplified" dates path you have provided the means to do so.

A Suggestion: Use a json bundle to pack the macro and move everything that is displayed in the "date Macro" tiddler to another tiddler. The reason I say this is the act of adding the $:/tags/Macro tag will include the whole tiddler (Although not visible) every time a tiddler is displayed, it is like the importvariables process see https://tiddlywiki.com/#ImportVariablesWidget. Sure it seems to have no clear impact in a small wiki but it is not the optimum design approach. If you still want the documentation displayed when opening "date Macro" you can do a little test, if currentTiddler="date Macro" transclude the doco tiddler, otherwise do not.

Love your work, and thanks for sharing
Tony

Jan

unread,
Apr 2, 2019, 7:10:19 PM4/2/19
to tiddl...@googlegroups.com
Hi S.S.
Great work thanks this could solve some problems for me because I was forced me to give all dates with thes same precision, which is a drag if you are a historyteacher and some processes are decades. You have to start the industrial revolution on 01/01/1770 - sharp if you want to have the exact 14/07/1789  of the Bastille.
It would be great if it could replace moments.js in the timelineplugin https://github.com/kixam/TW5-visjsTimeline.
Thanks!!

Regards Jan
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/1808ec69-2ee7-460b-a6ca-43810a3ed824%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mohammad

unread,
Apr 3, 2019, 12:07:43 AM4/3/19
to TiddlyWiki
Hi S.S,
 Great job!  well documented.
Good flexibility to adopt many formats users may like.

Cheers
Mohammad

S. S.

unread,
Apr 6, 2019, 12:24:04 AM4/6/19
to tiddl...@googlegroups.com
Well,

I was playing with the Set Widget Tester for attribute precedence tiddler that I posted a few days ago, and realized that in the $set widget, the field attribute takes precedence over the index attribute, so perhaps it wouldn't be too difficult to add in the index parameter to the date Macro, which really was an oversight as data tiddlers are such an integral part of TiddlyWiki.

And so it was easy, with just a minor tweak to 2 lines of the code! Took the opportunity to brush up a little, with the following changes:
  1. Corrected mistakes in the  Examples section, Macro column: removed redundant sep parameter. Changed date to invalid-date
  2. Changed some single quote delimiters to triple
  3. Added fields for version number & issues & release-notes
  4. Added missing empty-message field to "set to default" macro
  5. Added code-black style for <code>
  6. Added index parameter & its documentation
So here it is - version 1.02 attached below :
 
The date macro takes a string in a Common Date Format and returns it in a specified Date Format.


Regards


Edit: Changed "would be too difficult" to "wouldn't be too difficult"
date Macro ver.1.02.tid

S. S.

unread,
Apr 8, 2019, 9:05:42 PM4/8/19
to TiddlyWiki

I'm glad Josiah made a post yesterday:  Query -- Changing creation date in a human actionable way? -- #creationDate

I thought, of course this <<date>> macro can do it! But it couldn't!!

Reason: The date result was being output in block mode, and the $action-setfield widget was not accepting it.

It took a while to figure that out. The fix was to remove all spaces and line breaks in 3 macros. Makes horrible reading - but now it works!

So, attached is v1.03 with those fixes, along with a macro to change the created date of a tiddler.
I'm not going to tell Josiah his answer is here - so even though it doesn't have a regex tag, he'll have to read it to get it  !!!



Change Field using date Macro.tid
date Macro ver.1.03.tid
Message has been deleted
Message has been deleted
Message has been deleted

S. S.

unread,
Apr 14, 2019, 11:20:56 PM4/14/19
to TiddlyWiki

Hi Josiah,

Glad you like the "neat little tool" !!! It was fun making it because it was harder than I thought - with so many initially un-imagined situations. Interestingly, it made me realize that what seems like a simple situation in life, actually has so many complex unseen or unnoticed interdependencies. What we imagine is so clear cut is just our own illusion created from a lack of understanding and insight. Who would have thought coding could make one philosophize!

I actually put the stackoverflow link of where I got the regex into a field in the date Macro tiddler. You can read over there why it was constructed that way, and how it takes into account exceptional leap years:

Every year divisible by 4 is a leap year, except when it is divisible by 100 unless it is divisible by 400.

There is a better YYYY-MM-DD regex a little below that which validates from years 1000 - 9999 but I got blurry eyed when trying to figure out the correct "match remembering" group for the separators . / - and so used the present one. The one I would like to use is in a comment a little further down in that stackoverflow post:

^((([1-9]\d{3})\-(0[13578]|1[02])\-(0[1-9]|[12]\d|3[01]))|(((19|[2-9]\d)\d{2})\-(0[13456789]|1[012])\-(0[1-9]|[12]\d|30))|(([1-9]\d{3})\-02\-(0[1-9]|1\d|2[0-8]))|(([1-9]\d(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))\-02\-29))$

Regards


On Sunday, April 14, 2019 at 5:30:31 PM UTC+7, @TiddlyTweeter wrote:
Hi S.S., I got very intrigued by the regex in this neat little tool of yours! The regext has a couple of issues the are not immediately obvious on accurate matching for dates in February. I've written a new version that is easier to understand. It's also easier to set date ranges in it. I'm testing it at the moment and will post it when I'm sure it works reliably.

Best wishes
Josiah

@TiddlyTweeter

unread,
Apr 15, 2019, 7:53:09 AM4/15/19
to TiddlyWiki
Hi SS,

I just read that stack post in some detail. Thanks for that. And I've previously looked at the social and historical stuff. Especially on the different dates on which different countries transferred to Gregorian dates from Julian.

What has surprised me is you can actually get regex to match date systems perfectly accurately. But a problem with a lot of the yyyy-mm-dd regex around is they are not tested against enough dates. And most of them have problems. I been taking good bits of them to derive something fully workable.

For pragmatic use a Gregorian (leap on centennial only once in 400 years) regex from 1800 to 9999 could be totally accurate for English speaking countries (which went Gregorian in 1752). Other countries like France or Germany could have even earlier start centuries.

And a Julian (leap on all centennials) regex from 0001 to 1799 would be accurate as anything else---given all the complexity of actual historical usage (e.g. some countries had more than one type of year calender in use). Useful and accurate enough I think.

I also wanted to make it so you can change the start century without having to wade through the complexity of the regex.

I'll use a slightly different method on capture groups so they are easier to count in the forest of brackets. This makes handling the separators a lot easier.

The neat little tool of yours gave me opportunity to play with a nicely rich regex. Thanks again.

Another round of tests and I'll put it out.

Best
Josiah

Message has been deleted

S. S.

unread,
Apr 20, 2019, 6:24:16 AM4/20/19
to TiddlyWiki

April is turning out to be the quietest month here since a long time!
Perhaps the warmer weather has led to more outdoor activities.

I wonder if anyone is using the date Macro & if there are any suggestions for improvement?

Meanwhile, I thought it might be useful adding a time parameter to the macro, and so I did.

time
A time string of up to 9 digits, 2 for hours, 2 for minutes, 2 for seconds, 3 for milliseconds (hhmmssXXX) applicable only when the date string includes a 2 digit day

Attached is the updated: date Macro v1.04

Regards.


date Macro ver.1.04.tid
Reply all
Reply to author
Forward
0 new messages