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/f5696b18-c0c3-4c4b-ad4e-3aafc3f93f18%40googlegroups.com.