Dear list, I would like to be able to design some calendars. Is there any way to have a command (Lua or ConTeXt) that can increase or decrease a given date by days (something like \nextday or \previousday). I have tried \date and \increment or \decrement, as shown in the wiki: \starttext Today is \currentdate. \dorecurse{25} {\increment\normalday} Tomorrow will be \currentdate. \decrement\normalday %\increment\normalmonth% -- gives an error \increment\normalyear And today in a year will be \currentdate. \stoptext But the main problem is that I end up having the improbable day of December 41st, 2024 (with \decrement\normalday, it would read -9th). Besides, \normalmonth cannot be incremented or decremented (although this would be useless for me). Is there any way to get a command that can increment or decrement by days a given date? Many thanks for your help, Pablo
Am 16.12.24 um 19:05 schrieb Pablo Rodriguez via ntg-context:
I would like to be able to design some calendars.
While this doesn’t answer your question, did you try Willi’s calendar modules, as outlined in https://articles.contextgarden.net/journal/2022.html ? I guess the code also contains date calculations. Hraban
On 12/16/24 19:36, Henning Hraban Ramm wrote:
Am 16.12.24 um 19:05 schrieb Pablo Rodriguez via ntg-context:
I would like to be able to design some calendars.
While this doesn’t answer your question, did you try Willi’s calendar modules, as outlined in https://articles.contextgarden.net/journal/2022.html ? I guess the code also contains date calculations. Hi Hraban,
it doesn’t fit my needs (which are way different from his pocket diary). Having a command that increases or days (according to the calendar) avoids me having to implement the whole logic. Besides, I think \normalday could be way more useful if it could increment the whole date, not only the day number. I must admit that I barely understand how \normalday behaves like any other counter. Pablo
On 16/12/2024 21:03, Pablo Rodriguez via ntg-context wrote:
Besides, I think \normalday could be way more useful if it could increment the whole date, not only the day number.
does this help? https://www.lua.org/pil/22.1.html
nn = os.date("*t", os.time{year=2024, month=12+15, day=16+19}) nn.year, nn.month, nn.day
To produce a date table, we use the format string "*t". For instance, the following code temp = os.date("*t", 906000490) produces the table {year = 1998, month = 9, day = 16, yday = 259, wday = 4, hour = 23, min = 48, sec = 10, isdst = false}
On 12/16/24 21:30, vm via ntg-context wrote:
On 16/12/2024 21:03, Pablo Rodriguez via ntg-context wrote:
Besides, I think \normalday could be way more useful if it could increment the whole date, not only the day number.
does this help?
I’m afraid not, because I wonder how to typeset a whole year with that os.date() and os.time() functions. I mean, a huge xtable that contains 12 months, with a variable number of weeks and days each, placing each day number in weeks from Monday to Sunday. I cannot even get a header with the correct year number (although I know how to invoke that, I get 2028 instead of 2024 [probably because of for-loops]). It seems that it is too complex for me (and I have already invested two afternoons in this). For some reason, not meant to be in my case, Pablo
Pablo Rodriguez via ntg-context schrieb am 16.12.2024 um 22:18:
On 12/16/24 21:30, vm via ntg-context wrote:
On 16/12/2024 21:03, Pablo Rodriguez via ntg-context wrote:
Besides, I think \normalday could be way more useful if it could increment the whole date, not only the day number. does this help?
https://www.lua.org/pil/22.1.html I’m afraid not, because I wonder how to typeset a whole year with that os.date() and os.time() functions.
I mean, a huge xtable that contains 12 months, with a variable number of weeks and days each, placing each day number in weeks from Monday to Sunday.
I cannot even get a header with the correct year number (although I know how to invoke that, I get 2028 instead of 2024 [probably because of for-loops]).
It seems that it is too complex for me (and I have already invested two afternoons in this).
For some reason, not meant to be in my case,
Use trialtypesetting in a table when you perform calculations etc. \starttext \startxtable \startxrow \startxcell \startmode[*trialtypesetting] 123456789 \stopmode \startnotmode[*trialtypesetting] 123 %123\rlap{\lightgray 456789} \stopnotmode \stopxcell \stopxrow \stopxtable \startxtable \startxrow \startxcell \doifelsemode{*trialtypesetting} {123456789} {123} %{123\rlap{\lightgray 456789}} \stopxcell \stopxrow \stopxtable \startxtable \startxrow \startxcell \iftrialtypesetting 123456789 \else 123 %123\rlap{\lightgray 456789} \fi \stopxcell \stopxrow \stopxtable \stoptext Wolfgang
On 12/16/24 22:52, Wolfgang Schuster wrote:
Pablo Rodriguez via ntg-context schrieb am 16.12.2024 um 22:18:
[...] I cannot even get a header with the correct year number (although I know how to invoke that, I get 2028 instead of 2024 [probably because of for-loops]). [...] Use trialtypesetting in a table when you perform calculations etc.
Many thanks for the info, Wolfgang. This is something I need to keep in mind when I get weird results in loops. Many thanks for your help, Pablo
On 16/12/2024 22:18, Pablo Rodriguez via ntg-context wrote:
It seems that it is too complex for me (and I have already invested two afternoons in this).
For some reason, not meant to be in my case,
like everyday for one year 8<--- \startluacode function userdata.now(dd) local wdays = {"Sun ", "Mon ", "Tue ", "Wed ", "Thu ", "Fri ", "Sat "} local z = os.date("*t", os.time()) local nn = os.date("*t", os.time{year=z.year, month=z.month, day=z.day+dd}) --context(wdays[nn.wday] .. nn.year .. "-" .. nn.month .. "-" .. nn.day) context(string.format("%s %04d-%02d-%02d ", wdays[nn.wday], nn.year, nn.month, nn.day)) end \stopluacode \starttext \tt Today is \ctxlua{userdata.now(0)} \dorecurse{366}{\ctxlua{userdata.now(\recurselevel)}\\ } \stoptext --->8 ( i'm not fluent in lua, so there might be a much better way to handle it ;-)
On 16/12/2024 22:18, Pablo Rodriguez via ntg-context wrote:
For some reason, not meant to be in my case,
In your terminal, one line fits all ;-) T="cal2025.tex" && echo "\\starttext\\startTEXpage\\starttyping" >${T} && cal 2025 >>${T} && echo "\\stoptyping\\stopTEXpage\\stoptext" >>${T} && context ${T}
On 12/17/24 10:02, vm via ntg-context wrote:
On 16/12/2024 22:18, Pablo Rodriguez via ntg-context wrote:
For some reason, not meant to be in my case,
In your terminal, one line fits all ;-)
T="cal2025.tex" && echo "\\starttext\\startTEXpage\\starttyping" >${T} && cal 2025 >>${T} && echo "\\stoptyping\\stopTEXpage\\stoptext" >>${T} && context ${T}
Many thanks for your three suggestions, vm. They would be a way to start doing it, but fortunately there is a proper calendar solution. Many thanks for your help, Pablo
Pablo Rodriguez via ntg-context schrieb am 16.12.2024 um 19:05:
Dear list,
I would like to be able to design some calendars.
Is there any way to have a command (Lua or ConTeXt) that can increase or decrease a given date by days (something like \nextday or \previousday).
I have tried \date and \increment or \decrement, as shown in the wiki:
\starttext Today is \currentdate.
\dorecurse{25} {\increment\normalday}
Tomorrow will be \currentdate.
\decrement\normalday
%\increment\normalmonth% -- gives an error \increment\normalyear
And today in a year will be \currentdate. \stoptext
But the main problem is that I end up having the improbable day of December 41st, 2024 (with \decrement\normalday, it would read -9th).
Besides, \normalmonth cannot be incremented or decremented (although this would be useless for me).
Is there any way to get a command that can increment or decrement by days a given date?
https://www.mail-archive.com/ntg-context@ntg.nl/msg88605.html Wolfgang
On 12/16/24 21:21, Wolfgang Schuster wrote:
Pablo Rodriguez via ntg-context schrieb am 16.12.2024 um 19:05:
[...] Is there any way to get a command that can increment or decrement by days a given date?
https://www.mail-archive.com/ntg-context@ntg.nl/msg88605.html
Many thanks for your reply, Wolfgang. I‘m afraid that approach is too complex for me to implement a full calendar of previous, current and next year. I have tried that, but only the required xtable seems too complicated to me (using xtables). Pablo
On Mon, 16 Dec 2024, Pablo Rodriguez via ntg-context wrote:
I‘m afraid that approach is too complex for me to implement a full calendar of previous, current and next year.
tikz has various macros to typeset calendars: \usemodule[tikz] \usetikzlibrary[calendar] \starttext \starttikzpicture \calendar[dates=2025-01-01 to 2025-04-last,week list, month label above centered]; \stoptikzpicture \stoptext Also see https://tikz.dev/library-calender and https://texample.net/tikz/examples/feature/calendar-library/ (which, in principle, can be translated to ConTeXt rather easily). Aditya
On 12/16/24 23:49, Aditya Mahajan wrote:
On Mon, 16 Dec 2024, Pablo Rodriguez via ntg-context wrote:
I‘m afraid that approach is too complex for me to implement a full calendar of previous, current and next year.
tikz has various macros to typeset calendars: [...] Also see https://tikz.dev/library-calender and https://texample.net/ tikz/examples/feature/calendar-library/ (which, in principle, can be translated to ConTeXt rather easily).
Hi Aditya, many thanks for the reference: this solves all my needs (see below). It would be great (as per https://texample.net/tikz/examples/birthday-calendar/) to have automatic Easter calculation. I guess Lua code would be easier to write, but I cannot get how each Easter Sunday may be computed. Many thanks for your help and excuse my crappy (but functional) code, Pablo \unprotect \permanent\tolerant\protected\def\translate[#1]% {\getparameters[\??translation][#1]% \ifcsname\??translation\currentlanguage\endcsname \lastnamedcs \orelse\ifcsname\??translation\s!en\endcsname \lastnamedcs \else #1% \fi} \protect \usemodule[tikz] \usetikzlibrary[calendar] \setupbodyfont[palatino] \def\pgfcalendarmonthname#1{% \translate{\ifcase#1\or Enero\or Febrero\or Marzo\or Abril\or Mayo\or Junio\or Julio\or Agosto\or Septiembre\or Octubre\or Noviembre\or Diciembre\fi}% } \starttext \startbuffer \setupheadertexts[\framed[frame=off, foregroundstyle=\bfd, width=1tw, align=outer,]{\recursestring}] \startlayout[standard][align=center] \startxtable[frame=off] \ctxlua{document.rcount = 1} \dorecurse{4} {\startxrow[toffset=1st] \dorecurse{3} {\startxcell \starttikzpicture \calendar(mycal)[dates=\recursestring-\cldcontext{document.rcount}-01 to \recursestring-\cldcontext{document.rcount}-last, week list, month label above left, month text={\feature[+][smallcaps]\%mt}, ] if (Sunday, equals=2025-04-20, equals=2025-04-18, equals=2025-04-19, equals=01-01, equals=01-06, equals=02-22, equals=05-01, equals=07-28, equals=08-15, equals=09-9, equals=09-15, equals=11-1, equals=12-6, equals=12-8, equals=12-25, equals=02-22) [font=\bf]; \stoptikzpicture \stopxcell\ctxlua{document.rcount = document.rcount + 1} \startxcell[width={\ifnum\recurselevel <3 .04675tw\else 0tw\fi}] \stopxcell} \stopxrow} \stopxtable \stoplayout \stopbuffer \doloopoverlist{2050} {\getbuffer} \stoptext
Am 17.12.24 um 16:44 schrieb Pablo Rodriguez via ntg-context:
It would be great (as per https://texample.net/tikz/examples/birthday-calendar/) to have automatic Easter calculation.
I guess Lua code would be easier to write, but I cannot get how each Easter Sunday may be computed.
Hi Pablo, you didn’t follow my suggested links. While Willi’s “main” module PocketDiary doesn’t fit your needs, the calculations and examples for other kinds of calendars are all there. https://modules.contextgarden.net/dl/PocketDiary-V2.zip https://modules.contextgarden.net/dl/Collection-of-calendars-based-on-Pocket... https://modules.contextgarden.net/dl/Date-driven-lists.zip Hraban
On 12/17/24 17:09, Henning Hraban Ramm wrote:
Am 17.12.24 um 16:44 schrieb Pablo Rodriguez via ntg-context:
It would be great (as per https://texample.net/tikz/examples/birthday-calendar/) to have automatic Easter calculation.
I guess Lua code would be easier to write, but I cannot get how each Easter Sunday may be computed.
Hi Pablo, you didn’t follow my suggested links.
Sorry, Hraban, I followed the only link I got in my message. What I completetely overlooked was that there were two more articles by Willi about PocketDiary. I thought the first article was the module presentation for the new version. I had mistakenly thought that that first article was all it was about that. Apologies for my hurried reading (also to Willi), Pablo
On 17. Dec 2024, at 16:44, Pablo Rodriguez via ntg-context
wrote: I guess Lua code would be easier to write, but I cannot get how each Easter Sunday may be computed.
Here you go: a = math.fmod(year,19) b = math.floor(year / 100) c = math.fmod(year,100) d = math.floor(b / 4) e = math.fmod(b,4) f = math.floor((b + 8) / 25) g = math.floor((b - f + 1) / 3) h = math.fmod((19 * a + b - d - g + 15),30) i = math.floor(c / 4) k = math.fmod(c,4) L = math.fmod((32 + 2 * e + 2 * i - h - k),7) m = math.floor((a + 11 * h + 22 * L) / 451) eastersundaymonth = math.floor((h + L - 7 * m + 114) / 31) eastersunday = math.fmod((h + L - 7 * m + 114),31) + 1 Thomas
participants (6)
-
Aditya Mahajan
-
Henning Hraban Ramm
-
Pablo Rodriguez
-
Thomas A. Schmitz
-
vm
-
Wolfgang Schuster