Mark,
This is powerfully done. It is true it needs to be packaged, so it can be
readily used. In this version or an alternate macro perhaps the result
could be presented in the date serial number
format https://tiddlywiki.com/prerelease/#Date%20Fields, because then it
could be saved in a date field and fed into the view widget date or
relative date to be displayed in any format. The date serial number can
then also be tested with > or < tests.
If your macro was to accept a date serial number as input plus the days
from now (ideally negative days also), and output a date serial number,
such a macro would be worthy of inclusion in the standard distribution.
Perhaps even an operator (if that is possible)
daysfromnow:modified[+7]
would return a dateserial number, that could be immediately compared with
another date.
Perhaps one day we may also have an operator
now[]
that would return a dateserial number of now!
Love your work!
Tony
On Tuesday, October 22, 2019 at 7:03:16 AM UTC+11, Mark S. wrote:
>
> Hi Mat et al,
>
> Ok, here's the complete kit ... I hope. Including a sample helper macro
> for finding days from now.
>
> The main thing that had to be changed in your macro is that all divisions
> had to be converted to integer divisions. I appended the "floor"
> operator wherever needed to accomplish this.
>
> \define g(y,m,d,offset:"0")
> <$set name=m value={{{ [<__m__>add[9]remainder[12]] }}}>
> <$set name=y value={{{ [<m>divide[10]floor[]negate[]add<__y__>] }}} >
> <$set name=y4 value={{{ [<y>divide[4]floor[]] }}}>
> <$set name=y100 value={{{ [<y>divide[100]floor[]] }}}>
> <$set name=y400 value={{{ [<y>divide[400]floor[]] }}}>
> <$set name=m306 value={{{ [<m>multiply[306]add[5]divide[10]floor[]] }}}>
> <$set name=result value={{{ [[365]multiply<y>add<y4>subtract<y100>add
> <y400>add<m306>add[$d$]add[$offset$]subtract[1]] }}} >
> <<result>>
> </$set></$set></$set></$set></$set></$set></$set>
> \end
>
>
> \define d(g)
> <$set name=daysperyear value="365.2425">
> <!-- y = (10000*g + 14780)/3652425 -->
> <$set name=y value={{{ [[10000]multiply<__g__>add[14780]divide[3652425]
> floor[]] }}}>
> <!-- ddd = g - (365*y + y/4 - y/100 + y/400) -->
> <$set name=y4 value={{{ [<y>divide[4]floor[]] }}}>
> <$set name=y100 value={{{ [<y>divide[100]floor[]] }}}>
> <$set name=y400 value={{{ [<y>divide[400]floor[]] }}}>
> <$set name=dddtest value={{{ [[365]multiply<y>add<y4>subtract<y100>add
> <y400>negate[]add<__g__>] }}} >
> <$set name=prioryear value={{{ [<y>subtract[1]] }}} >
> <$set name=y value={{{ [<dddtest>prefix[-]then<prioryear>] [<dddtest>!
> prefix[-]then<y>] }}} >
> <$set name=ddd value={{{ [[365]multiply<y>add<y4>subtract<y100>add<y400>
> negate[]add<__g__>] }}} >
> <!-- mi = (100*ddd + 52)/3060 -->
> <$set name=mi value={{{ [[100]multiply<ddd>add[52]divide[3060]floor[]] }}}
> >
> <!-- mm = (mi + 2)%12 + 1 -->
> <$set name=mm value={{{ [<mi>add[2]remainder[12]add[1]] }}} >
> <!-- y = y + (mi + 2)/12 -->
> <$set name=y value={{{ [<mi>add[2]divide[12]floor[]add<y>] }}} >
> <!-- dd= ddd - (mi*306 + 5)/10 + 1 -->
> <$set name=dd value={{{ [<mi>multiply[306]add[5]divide[10]floor[]negate[]
> add<ddd>add[1]] }}} >
> <<y>>, <<mm>>, <<dd>> <br/>
> </$set></$set></$set></$set></$set></$set></$set></$set></$set></$set></
> $set></$set></$set>
> \end
>
> \define daysfrom(y,m,d,o)
> <$wikify name=future text="<<g $y$ $m$ $d$ $o$>>">
> <$macrocall $name="d" g=<<future>>/>
> </$wikify>
> \end
>
> Days from: <<daysfrom 2019 10 21 11>>
>
>
>
>
>
>
> On Tuesday, August 20, 2019 at 12:18:41 PM UTC-7, Mat wrote:
>>
>> Hi Mark
>>
>> I found this algo
>>
>>
>> https://web.archive.org/web/20170507133619/https://alcor.concordia.ca/~gpkatch/gdate-algorithm.html
>>
>> It should be enough with our new math functions. As an experiment I made
>> the first part (the g function):
>>
>> \define g(y, m, d)
>> <$set name=m value={{{ [[$m$]add[9]remainder[12]] }}}>
>> <$set name=y value={{{ [<m>divide[10]subtract[$y$]negate[]] }}}>
>> <$set name=y4 value={{{ [<y>add[4]] }}}>
>> <$set name=y100 value={{{ [<y>divide[100]] }}}>
>> <$set name=y400 value={{{ [<y>divide[400]] }}}>
>> <$set name=m3 value={{{ [<m>multiply[306]add[5]divide[10]] }}}>
>> {{{
>> [[365]multiply<y>add<y4>subtract<y100>add<y400>add<m3>add[$d$]subtract[1]]
>> }}}
>> </$set></$set></$set></$set></$set></$set>
>> \end
>>
>> This seems to work but it is only half of what is needed so I can't tell
>> for sure. What you're asking for is
>>
>> d(g(y,m,d) + n)
>>
>>
>> which thus requires the d function and maybe also to mess a bit with the
>> <<now>> macro to extract the desired bits. Or maybe it could be integrated
>> into the function for a more elegant solution.
>>
>> Tell me if you need more help and I'll fiddle a bit more. I'm a bit heavy
>> on work for some time but I'm a tiddly junkie so small and well defined
>> bits like these...
>>
>> <:-)
>>
>>
>>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/d35b070d-0932-4cfc-88d5-70c06d26062e%40googlegroups.com.