The <$vars day={{daysFromEndOfMonth}}> doesn’t automatically “wikify” (render) the transcluded content. Rather, it just assigns the content of that tiddler to the variable. It is only when you subsequently display the variable that it’s content is rendered to produce numeric output.
To obtain the rendered output of a transclusion and store it in a variable, you can use the $wikify widget, like this:
<$wikify name=day text={{daysFromEndOfMonth}}>
Also note that you can write the daysFromEndOfMonth tiddler more more compactly, like this:
Any idea why <<lastDay1 <now MM> >> is giving me 31 instead of 30?
Also, is there a difference between \function lastDay2() [enlist:raw[31 28 31 30 31 30 31 31 30 31 30 31]]+[nth<now MM>]
as opposed to \function lastDay2() [enlist:raw[31 28 31 30 31 30 31 31 30 31 30 31]nth<now MM>]
or are they equivalent?
The core does not currently provide any support for date/time operations beyond formatting. I think a strong case can be made for the universality of these operations, and so I would be happy to consider adding such primitives.
I would be inclined to focus on exposing the date/time functionality provided natively by JavaScript. There are libraries like moment.js that go a lot deeper (eg parsing dates and times in different timezones), but they tend to be quite large (moment.js is 18kb).
The area we should look at of moment.js is the chainable API. It is somewhat similar to TiddlyWiki’s filter architecture and might provide some pointers to help structure the new operators.
You’re not wrong, but I’ve got almost 3 years to add in support for leap-years, by which time I may or may not still be using it (or maybe by then we’ll have native support for date operations). If I’m depending on it for anything that needs to be exact, I’ll put a reminder in my calendar for January 2028, and that still leaves me a month to fix it.
The first filter run says “if the current year is divisible by 4 and the current month is February, then the last day is 29”
ELSE, the second run is the same as before
The above calculation is inaccurate for most century years, because the actual rule for leap years is: if the year is divisible by 4 or 400, but NOT divisible by 100 (thus, 2000 is a leap year; 2100, 2200, and 2300 are not leap years; 2400 is a leap year; 2500, 2600, and 2700 are not leap years; 2800 is a leap year, etc.).
If this is legal syntax, it’s news to me. I don’t always keep up, so it might be. But I think you need a transclusion to pass the result of <<now MM>>. So your line would look like:
I figured if I could do <<lastDay1 4>> it would make sense to be able to do <<lastDay1 <now MM> >>.
It produced an output of 31, so I figured there was probably some off-by-one error buried in there for some reason (returning either the 3rd or 5th element, instead of the 4th).
After a bit more reading, it looks like if I rename my function to .lastDay1, I can do {{{ [.lastDay1<now MM>] }}}, which is a bit more readable to me. Incorporating everything, I get:
Function definitions must only be composed of filter runs, you can’t use anything else, like a <$let> widget.
Also, format:date operator input dates should be formatted like TiddlyWiki dates: YYYY0MM0DD0hh0mm0ssXXX. Thus your date variable definition using YYYY-0MM-0DD format won’t work.