On Thursday, August 27, 2020 at 12:04:00 PM UTC-7, Ed Heil wrote:
Here's a macro that calculates the day number (1 through 365/366) and a $button that stores the result in a tiddler field:
\define getDay()
\whitespace trim
<$vars yyyy=<<now "YYYY">> mm=<<now "MM">> dd=<<now "DD">>>
<$set name="dpm" filter="[<yyyy>divide[4]split[.]count[]match[1]]"
value="31 29 31 30 31 30 31 31 30 31 30 31" emptyValue="31 28 31 30 31 30 31 31 30 31 30 31">
{{{ [enlist:raw<dpm>first<mm>butlast[]sum[]add<dd>] }}}
\end
<$button> set days
<$wikify name="days" text=<<getDay>>>
<$action-setfield days=<<days>> />
</$wikify>
</$button>
The getDay() macro does this:
* \whitespace trim removes all whitespace from the macro output
* $vars gets the current year (YYYY), month (MM) and date (DD)
* $set name="dpm" (days per month) determines if the year is a leap year (i.e., evenly divisible by 4) and then defines a list of days per month
* the inline filter enlists the days per month (using :raw to include duplicate values)
* then it trims the list to only include the months up to, but not including, the current month
* and then sums those numbers and adds the date for the current month
The $button does this:
* $wikify takes the getDay() macro and converts it's output to plain text
* $action-setfield saves the plain text value to the "days" field of the current tiddler
enjoy,
-e