ISO week date format template

111 views
Skip to first unread message

J N

unread,
Sep 9, 2021, 3:31:46 PMSep 9
to TiddlyWiki
I would like to use the ISO week date format for the title of new journal tiddlers and elsewhere, since I find it practical to be aware of the week day in combination with a sortable date format.

YYYY-Www-D or YYYYWwwD

E.g. 2021-w36-4 for thursday of week 36, 2021-09-09.

I can not see a way to get the week day number in the built in date format tokens.


The closest I've got is YYYY-W0WW-ddd, but that renders as 2021-W36-Thu, which will not sort alphanumerically in date order like an ISO date would.

I can see that the template tokens are implemented in a system tiddler named $:/core/modules/utils/utils.js.

Getting the day of week is trivial in JavaScript, e.g. adding a token matching a single "D" for this:

[/^D/, function() {
return date.getDay() || 7;
}]

The utils.js tiddler seems to contain a lot of other stuff however, and I guess local changes would have to be merged on achieving updates of TiddlyWiki.

Maybe there are other ways to achieve custom date formatting of this kind in TiddlyWiki?

J N

unread,
Sep 9, 2021, 3:57:30 PMSep 9
to TiddlyWiki
A correction of the example given for a week date in TiddlyWiki is that the template should use the wYYYY token for the ISO week-numbering year, not YYYY, since weeks may cross the traditional year boundary with some days of the week falling outside the year the week belongs to. It is a bit surprising that the final element of the week day number is missing when the other parts of the ISO standard are supported.

Charlie Veniot

unread,
Sep 10, 2021, 11:49:23 PMSep 10
to TiddlyWiki
G'day,

Just to get the conversation started, try this in a new tiddler in some tiddlywiki:

<$vars dateNow= <<now wYYYY-W0WW-ddd>>>

{{{ [<dateNow>search-replace:[Mon],[1]search-replace:[Tue],[2]search-replace:[Wed],[3]search-replace:[Thu],[4]search-replace:[Fri],[5]search-replace:[Sat],[6]search-replace:[Thu],[7]] }}}

</$vars>

Charlie Veniot

unread,
Sep 11, 2021, 9:19:35 AMSep 11
to TiddlyWiki
  Oops, typo in the last "search-replace"  

"[Thu],[7]" should be "[Sun],[7]"

The dangers of mindless cut and paste ...
Message has been deleted

J N

unread,
Sep 12, 2021, 6:26:51 AMSep 12
to TiddlyWiki
Thank you for the suggested workaround.

Is it possible to define that operation in a tiddler and then refer to the value in a template for creating a new journal entry?

If so, maybe one could also use JavaScript directly to provide the value for the tiddler template.

Jeremy Ruston

unread,
Sep 12, 2021, 6:58:44 AMSep 12
to TiddlyWiki
Thanks CJ for the cunning workaround. For v5.2.0 I've now added a new date format string token "dddd" for directly obtaining the ISO weekday number (ie 1=Monday, 7=Sunday):


(It'll take a few minutes from this posting until the change shows up).

Best wishes

Jeremy.

PMario

unread,
Sep 12, 2021, 7:01:54 AMSep 12
to TiddlyWiki
Thanks Jeremy,
I did just have a look at the code to create a PR. You have been faster to fix it as I've been looking up the code ;)
-m

Charlie Veniot

unread,
Sep 12, 2021, 9:48:57 AMSep 12
to TiddlyWiki
I'm thinking it might be worth you using the 5.2 pre-release version of TiddlyWiki, seeing as it has the ISO date format.

However, if you do want to continue with the workaround:

I wouldn't bother with javascript.  You have all you need in TiddlyWiki:  https://tiddlywiki.com/#Making%20a%20custom%20journal%20button

What do you think? 

J N

unread,
Sep 13, 2021, 2:34:08 PMSep 13
to TiddlyWiki
Nice to hear it is already taken care of, thank you.
I was almost on my way to make a pull request myself, as an exercise in contributing to an open source project, but I am not sure about the customs, if I should create an issue first.

Of curiosity, may I ask why you chose "dddd" as the token for week date number, instead of the "D" symbol used in the ISO 8601 formats notation?

J N

unread,
Sep 13, 2021, 2:42:38 PMSep 13
to TiddlyWiki
Yes, I will probably upgrade to 5.2 then to get that specific feature.

Thank you for the doc ref, there seem to be many possibilities to customize functionality.

The last block of example code means that I should create the config tiddlers without the $:/ prefix if I want them to appear in the sidebar UI?

Jeremy Ruston

unread,
Sep 13, 2021, 2:46:04 PMSep 13
to tiddl...@googlegroups.com
Nice to hear it is already taken care of, thank you.
I was almost on my way to make a pull request myself, as an exercise in contributing to an open source project, but I am not sure about the customs, if I should create an issue first.

It's probably usually best to open an issue (or comment on an existing one) for discussion before preparing a PR to minimise the chances of it subsequently being rejected for a reason you haven't foreseen. We are always keen to welcome new contributors, and you'll find plenty of help and encouragement when you need it.

Of curiosity, may I ask why you chose "dddd" as the token for week date number, instead of the "D" symbol used in the ISO 8601 formats notation?

We don't currently use any single character tokens, originally to minimise the chances of triggering any boilerplate text in the template (ie, a format string could be "The year is YYYY").

Now that I started to write out the rationale for the choice of "dddd", I'm realising that perhaps I think "dd" might be a better choice. What do others think?

Best wishes

Jeremy



On Sunday, 12 September 2021 at 12:58:44 UTC+2 jeremy... wrote:
Thanks CJ for the cunning workaround. For v5.2.0 I've now added a new date format string token "dddd" for directly obtaining the ISO weekday number (ie 1=Monday, 7=Sunday):


(It'll take a few minutes from this posting until the change shows up).

Best wishes

Jeremy.

On Sunday, September 12, 2021 at 11:26:51 AM UTC+1 J N wrote:
Thank you for the suggested workaround.

Is it possible to define that operation in a tiddler and then refer to the value in a template for creating a new journal entry?

If so, maybe one could also use JavaScript directly to provide the value for the tiddler template.


On Saturday, 11 September 2021 at 15:19:35 UTC+2 cj.v wrote:
  Oops, typo in the last "search-replace"  

"[Thu],[7]" should be "[Sun],[7]"

The dangers of mindless cut and paste ...

On Saturday, September 11, 2021 at 12:49:23 AM UTC-3 Charlie Veniot wrote:
G'day,

Just to get the conversation started, try this in a new tiddler in some tiddlywiki:

<$vars dateNow= <<now wYYYY-W0WW-ddd>>>

{{{ [<dateNow>search-replace:[Mon],[1]search-replace:[Tue],[2]search-replace:[Wed],[3]search-replace:[Thu],[4]search-replace:[Fri],[5]search-replace:[Sat],[6]search-replace:[Thu],[7]] }}}

</$vars>


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/4101de67-bd22-489b-bdd7-3b98ab99be3fn%40googlegroups.com.

J N

unread,
Sep 13, 2021, 3:50:21 PMSep 13
to TiddlyWiki
Ok, I see that there is also already a conflict with the ISO notation in the DDD token, which in ISO 8601 is used for three digit day of year.
Maybe that could be nice to have as TW date token also.

> As represented above, [YYYY] indicates a year. [DDD] is the day of that year, from 001 through 365 (366 in leap years). For example, "1981-04-05" is also "1981-095".

The "dd" format is reminding of the numerical notation in the month date, but at the same time may be confusingly similar and suggesting a two digit representation. "dddd" feels more related to the existing weekday name notations, one could think that longer token indicates lesser units in this case. I'm not sure which one to prefer.
How could a day of year-token fit into this? yDDD?

PMario

unread,
Sep 14, 2021, 2:38:18 AMSep 14
to TiddlyWiki
On Monday, September 13, 2021 at 8:46:04 PM UTC+2 Jeremy Ruston wrote:

Now that I started to write out the rationale for the choice of "dddd", I'm realising that perhaps I think "dd" might be a better choice. What do others think?

I think 0dd and dd should be an option. I think 0dd is needed to get easy default sort order.

-mario

Jeremy Ruston

unread,
Sep 14, 2021, 4:19:10 AMSep 14
to TiddlyWiki
The "dd" format is reminding of the n umerical notation in the month date, but at the same time may be confusingly similar and suggesting a two digit representation. "dddd" feels more related to the existing weekday name notations, one could think that longer token indicates lesser units in this case. I'm not sure which one to prefer.

That's roughly my thinking too. In particular, there is a precedent for longer tokens generating shorter substitutions.

> How could a day of year-token fit into this? yDDD?

If we stick with `dddd` for day of week, perhaps we'd use `ddddd` for day of year? Perhaps that's excessively long, but it does seem like a very unusual requirement in any case; only users who were looking for it would want it, if you see what I mean.

I think 0dd and dd should be an option. I think 0dd is needed to get easy default sort order. 

The day of week is a number from 1 to 7, so zero padding doesn't seem useful.

Best wishes

Jeremy

PMario

unread,
Sep 14, 2021, 7:34:53 AMSep 14
to TiddlyWiki
On Tuesday, September 14, 2021 at 10:19:10 AM UTC+2 Jeremy Ruston wrote:

If we stick with `dddd` for day of week, perhaps we'd use `ddddd` for day of year?

They are very similar. For me it's difficult to recognise a difference. ...
 
Perhaps that's excessively long, but it does seem like a very unusual requirement in any case; only users who were looking for it would want it, if you see what I mean.

You are right. Only users that search for it will use it.
 
I think 0dd and dd should be an option. I think 0dd is needed to get easy default sort order. 

The day of week is a number from 1 to 7, so zero padding doesn't seem useful.

Right. My bad.

But ddddd day of year may have 1 or 2 leading zeros. ...

-m

Jeremy Ruston

unread,
Sep 14, 2021, 12:03:39 PMSep 14
to TiddlyWiki
OK, I'm thinking now:

* To change the token for week number to `dd`
* To add a new token for day of year `dddd` and `0dddd`

Best wishes

Jeremy

J N

unread,
Sep 16, 2021, 3:24:33 AMSep 16
to TiddlyWiki
Sounds fine to me.
The zero-padded format is probably the common case for the day of year.
"yDDD" would be the more shape-similar and mnemonic, but it's already in the proposals and maybe it breaks away from existing patterns.
The main thing is that the ISO date parts are represented and available.

Reply all
Reply to author
Forward
0 new messages