Debian Codegraph @

texmf-dist/tex/generic/pgf/utilities/pgfcalendar.code.tex

raw
1 % Copyright 2019 by Till Tantau
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10 \ProvidesFileRCS{pgfcalendar.code.tex}
11
12 \ifdefined\pgfintloaded\else
13 \input pgfint.code.tex
14 \fi
15
16 % Translation stuff
17
18 \ifx\translate\@undefined
19 \def\translate#1{#1}
20 \fi
21
22 % Load month dictionary, if possible
23
24 \ifx\usedictionary\@undefined
25 \else
26 \usedictionary{translator-months-dictionary}
27 \fi
28
29
30
31
32 % Typeset a calendar
33 %
34 % #1 = prefix for the calendar nodes
35 % #2 = begin date in ISO format
36 % #3 = end date in ISO format
37 % #4 = date rendering code
38 %
39 % Description:
40 %
41 % First note that this macro need not be called inside a pgfpicture
42 % (even though it often will be). You can use it to typeset
43 % calendars also using packages other than pgf. You do not even need
44 % to load pgf to use this file.
45 %
46 % A calendar is typeset as follows: You specify a range of dates (by
47 % providing a begin and an end date). Then, for each date the code #4
48 % is executed. When the code is called, lots of information about the
49 % current date (like its day of week) is available. The job of
50 % #4 is to render the date. Typically, this is done by placing nodes
51 % somewhere, but the function could do other things as well.
52 % It is also the job of #4 to position the calendar correctly.
53 %
54 % The different calls of #4 are not surrounded by TeX groups (though
55 % you can do so yourself, of course). This means that settings can
56 % accumulate between different calls, which is often desirable and
57 % useful.
58 %
59 % Inside #4 code, different macros can be access:
60 %
61 % \pgfcalendarprefix
62 % The parameter #1. This prefix is recommended for nodes inside the
63 % calendar, but you have to use it yourself explicitly.
64 %
65 % \pgfcalendarbeginiso
66 % Start date of range being typeset in ISO format (like 2006-01-10)
67 %
68 % \pgfcalendarbeginjulian
69 % Julian day number of start date begin typeset
70 %
71 % \pgfcalendarendiso
72 % End date of range begin typeset
73 %
74 % \pgfcalendarendjulian
75 % Same as Julian day number
76 %
77 % \pgfcalendarcurrentjulian (a TeX-count)
78 % Julian day number of day to be rendered/considered
79 %
80 % \pgfcalendarcurrentweekday
81 % Weekday (0 = Monday) of day to be checked
82 %
83 % \pgfcalendarcurrentyear
84 % Year of day to be checked
85 %
86 % \pgfcalendarcurrentmonth
87 % Month of day to be checked
88 %
89 % \pgfcalendarcurrentday
90 % Day of month of day to be checked
91 %
92 %
93 % Inside the \pgfcalendar macro the macro \ifdate is available, which
94 % has the same effect as \pgfcalendarifdate{\pgfcalendarcurrentjulian}
95 % (only faster). This means that you
96 % can write, say, \ifdate{Monday}{current date is a Monday}{Not a Monday}.
97 %
98 % Example:
99 %
100 % \begin{tikzpicture}
101 % \pgfcalendar{cal}{2007-01-20}{2007-02-10}
102 % {\node[anchor=base] {\pgfcalendaronday}; \pgftransformyshift{-1.5em}}
103 % \end{tikzpicture}
104 %
105 % \pgfcalendar{cal}{2007-01-20}{2007-02-10}{ \pgfcalendaronday\ }
106
107 \long\def\pgfcalendar#1#2#3#4{%
108 \begingroup%
109 % Setup local \ifdate
110 \let\ifdate=\pgfcalendar@local@ifdate%
111 % Let's start with computing start and end dates...
112 \def\pgfcalendarprefix{#1}%
113 \pgfcalendardatetojulian{#2}{\pgfcalendarcurrentjulian}%
114 \edef\pgfcalendarbeginjulian{\the\pgfcalendarcurrentjulian}%
115 \edef\pgfcalendarbeginiso{#2}%
116 \pgfcalendardatetojulian{#3}{\pgfutil@tempcnta}%
117 \edef\pgfcalendarendjulian{\the\pgfutil@tempcnta}%
118 \advance\pgfutil@tempcnta by1\relax%
119 \edef\pgfcalendarendjulianplus{\the\pgfutil@tempcnta}%
120 \edef\pgfcalendarendiso{#3}%
121 %
122 % Start main loop
123 %
124 \loop%
125 \ifnum\pgfcalendarcurrentjulian<\pgfcalendarendjulianplus\relax%
126 % Setup information about current date
127 \pgfcalendarjuliantodate{\pgfcalendarcurrentjulian}%
128 {\pgfcalendarcurrentyear}{\pgfcalendarcurrentmonth}{\pgfcalendarcurrentday}%
129 \pgfcalendarjuliantoweekday{\pgfcalendarcurrentjulian}{\pgfutil@tempcntb}%
130 \edef\pgfcalendarcurrentweekday{\the\pgfutil@tempcntb}%
131 % Render:
132 #4%
133 % Advance day:
134 \advance\pgfcalendarcurrentjulian by1\relax%
135 \repeat%
136 \endgroup%
137 }
138
139 \newcount\pgfcalendarcurrentjulian
140
141 \def\pgfcalendar@local@ifdate{%
142 \let\pgfcalendarifdatejulian=\pgfcalendarcurrentjulian%
143 \let\pgfcalendarifdateyear=\pgfcalendarcurrentyear%
144 \let\pgfcalendarifdatemonth=\pgfcalendarcurrentmonth%
145 \let\pgfcalendarifdateday=\pgfcalendarcurrentday%
146 \let\pgfcalendarifdateweekday=\pgfcalendarcurrentweekday%
147 \pgfcalendar@launch@ifdate%
148 }
149
150
151
152 % Execute on specific kinds of dates
153 %
154 % #1 = ISO-format date
155 % #2 = date specification
156 % #3 = code
157 %
158 % Description:
159 %
160 % The given code #3 is execute on every day that matches the date
161 % specification #2. This specification is a comma-separated list of
162 % key-value pairs with the path /pgf/calendar. The code for a
163 % key-value should check whether the given day matches its
164 % specification. If so, it should set \pgfcalendarmatches to true.
165 %
166 % When the key-value code is executed, the following macros will have
167 % been setup:
168 %
169 % \pgfcalendarifdatejulian
170 % Julian day number of day to be checked
171 %
172 % \pgfcalendarifdateweekday
173 % Weekday (0 = Monday) of day to be checked
174 %
175 % \pgfcalendarifdateyear
176 % Year of day to be checked
177 %
178 % \pgfcalendarifdatemonth
179 % Month of day to be checked
180 %
181 % \pgfcalendarifdateday
182 % Day of month of day to be checked
183 %
184 % The setting of these macros will persist after the call, so a
185 % side-effect of calling this macro is to setup these macros.
186 %
187 % By setting \ifpgfcalendar@do@not@recompute to false, the computation
188 % of the year, month etc. is suppressed.
189 %
190 % Examples:
191 %
192 % \pgfcalendarifdate{2007-01-10}{all}{}
193 % % Simply setup the macros
194 %
195 % \pgfcalendarifdate{2007-01-10}{mondays}{Is a monday}
196 %
197 % \pgfcalendarifdate{\mydate}{date=05-01}{\mydate is a Worker's Day}
198
199 \def\pgfcalendarifdate#1#2#3#4{%
200 \pgfcalendardatetojulian{#1}{\pgfutil@tempcnta}%
201 \pgfcalendarjuliantodate{\pgfutil@tempcnta}
202 {\pgfcalendarifdateyear}{\pgfcalendarifdatemonth}{\pgfcalendarifdateday}%
203 \edef\pgfcalendarifdatejulian{\the\pgfutil@tempcnta}%
204 % Compute info about date
205 \pgfcalendarjuliantoweekday{\pgfutil@tempcnta}{\pgfutil@tempcntb}%
206 \edef\pgfcalendarifdateweekday{\the\pgfutil@tempcntb}%
207 %
208 \pgfcalendar@launch@ifdate{#2}{#3}{#4}%
209 }
210
211
212 \long\def\pgfcalendar@launch@ifdate#1{%
213 % When this macro is called, the pgfcalendarifdatexxxx macros must
214 % be setup correctly
215 %
216 % Set match to false
217 \pgfcalendarmatchesfalse%
218 \pgfqkeys{/pgf/calendar}{#1}%
219 \ifpgfcalendarmatches%
220 \expandafter\pgfutil@firstoftwo
221 \else%
222 \expandafter\pgfutil@secondoftwo
223 \fi%
224 }
225
226 \newif\ifpgfcalendarmatches
227
228
229 % Keys for matching
230
231 \pgfkeys{/pgf/calendar/all/.code=\pgfcalendarmatchestrue}
232
233 \pgfkeys{/pgf/calendar/Monday/.code={\ifnum\pgfcalendarifdateweekday=0\relax\pgfcalendarmatchestrue\fi}}
234 \pgfkeys{/pgf/calendar/Tuesday/.code={\ifnum\pgfcalendarifdateweekday=1\relax\pgfcalendarmatchestrue\fi}}
235 \pgfkeys{/pgf/calendar/Wednesday/.code={\ifnum\pgfcalendarifdateweekday=2\relax\pgfcalendarmatchestrue\fi}}
236 \pgfkeys{/pgf/calendar/Thursday/.code={\ifnum\pgfcalendarifdateweekday=3\relax\pgfcalendarmatchestrue\fi}}
237 \pgfkeys{/pgf/calendar/Friday/.code={\ifnum\pgfcalendarifdateweekday=4\relax\pgfcalendarmatchestrue\fi}}
238 \pgfkeys{/pgf/calendar/Saturday/.code={\ifnum\pgfcalendarifdateweekday=5\relax\pgfcalendarmatchestrue\fi}}
239 \pgfkeys{/pgf/calendar/Sunday/.code={\ifnum\pgfcalendarifdateweekday=6\relax\pgfcalendarmatchestrue\fi}}
240
241 \pgfkeys{/pgf/calendar/workday/.code={\ifnum\pgfcalendarifdateweekday<5\relax\pgfcalendarmatchestrue\fi}}
242 \pgfkeys{/pgf/calendar/weekend/.code={\ifnum\pgfcalendarifdateweekday>4\relax\pgfcalendarmatchestrue\fi}}
243
244 \pgfkeys{/pgf/calendar/equals/.cd,.value required,.code={%
245 \pgfcalendar@special@datetojulian{#1}%
246 \ifnum\pgfcalendarifdatejulian=\pgfutil@tempcnta\relax%
247 \pgfcalendarmatchestrue%
248 \fi}%
249 }
250
251 \pgfkeys{/pgf/calendar/day of month/.cd,.value required,.code={\ifnum#1=\pgfcalendarifdateday\relax\pgfcalendarmatchestrue\fi}}
252 \pgfkeys{/pgf/calendar/end of month/.cd,.default=1,.code={%
253 % Tricky and expensive ... do only if necessary
254 \ifpgfcalendarmatches%
255 \else% sigh
256 {%
257 \pgfutil@tempcnta=\pgfcalendarifdatejulian\relax%
258 \advance\pgfutil@tempcnta by#1\relax%
259 \pgfcalendarjuliantodate{\pgfutil@tempcnta}{\pgf@dummy}{\pgf@dummy}{\pgf@cal@temp}%
260 \global\let\pgf@cal@temp=\pgf@cal@temp%
261 }%
262 \ifnum\pgf@cal@temp=1\relax\pgfcalendarmatchestrue\fi%
263 \fi}%
264 }
265
266 \pgfkeys{/pgf/calendar/at least/.cd,.value required,.code={%
267 \pgfcalendar@special@datetojulian{#1}%
268 \ifnum\pgfcalendarifdatejulian<\pgfutil@tempcnta\relax%
269 \else%
270 \pgfcalendarmatchestrue%
271 \fi%
272 }}
273
274 \pgfkeys{/pgf/calendar/at most/.cd,.value required,.code={%
275 \pgfcalendar@special@datetojulian{#1}%
276 \ifnum\pgfcalendarifdatejulian>\pgfutil@tempcnta\relax%
277 \else%
278 \pgfcalendarmatchestrue%
279 \fi%
280 }}
281
282 \pgfkeys{/pgf/calendar/between/.cd,.value required,.code args={#1and#2}{%
283 \pgfcalendar@special@datetojulian{#1}%
284 \ifnum\pgfcalendarifdatejulian<\pgfutil@tempcnta\relax%
285 \else%
286 \pgfcalendar@special@datetojulian{#2}%
287 \ifnum\pgfcalendarifdatejulian>\pgfutil@tempcnta\relax%
288 \else%
289 \pgfcalendarmatchestrue%
290 \fi%
291 \fi%
292 }}
293
294 \def\pgfcalendar@special@datetojulian#1{%
295 \edef\pgf@temp{#1}%
296 \expandafter\pgfcalendar@special@split@test\pgf@temp-\relax{#1}%
297 }
298
299 \def\pgfcalendar@special@split@test#1-#2-#3\relax#4{%
300 \def\pgf@temp{#3}%
301 \ifx\pgf@temp\pgfutil@empty%
302 \def\pgf@temp{\pgfcalendarifdateyear-#1-#2}%
303 \else%
304 \def\pgf@temp{#4}%
305 \fi%
306 \pgfcalendardatetojulian{\pgf@temp}{\pgfutil@tempcnta}%
307 }
308
309
310 % Suggested name for nodes inside a calendar
311 %
312 % Description:
313 %
314 % It is suggested that (main) nodes (if present) in a calendar should
315 % get this name.
316 %
317 % Example:
318 %
319 % \pgfcalendar{cal}{2007-01-20}{2007-02-10}{}
320 % { \node[anchor=base] (\pgfcalendarsuggestedname) {\pgfcalendarifdateday};
321 % \pgftransformyshift{-1.5em} }
322 %
323 % \draw (cal-2007-01-30) -- (cal-2007-02-08);
324
325 \def\pgfcalendarsuggestedname{%
326 \ifx\pgfcalendarprefix\pgfutil@empty\else\pgfcalendarprefix-%
327 \pgfcalendarcurrentyear-\pgfcalendarcurrentmonth-\pgfcalendarcurrentday\fi%
328 }
329
330
331
332 %
333 %
334 % Date conversion functions
335 %
336 %
337
338
339
340 % Convert a date to the Julian day number (number of days since
341 % January 1st, -4712)
342 %
343 % #1 = date specification
344 % #2 = counter that should be set to the number of days
345 %
346 % Description:
347 %
348 % The conversion is taken from the Wikipedia entry on Julian days.
349 %
350 % The date specification works as follows:
351 %
352 % - It starts with a year. Use \year for the current year (the year
353 % the file is being typeset).
354 % - Next comes a hyphen.
355 % - Next comes a month (number). Use \month for the current month.
356 % - Next comes a hyphen.
357 % - Next comes either a day of month (number, use \day for current
358 % day) or "last". The keyword "last" refers the last day of the
359 % month. Thus, 2006-01-last is the same as 2006-01-31 and
360 % 2000-02-last is the same as 2002-02-29.
361 % - Next may come a plus sign, followed by a number (positive or
362 % negative). This will adjust the date by the given number of
363 % days. Thus, 2006-01-31+1 is the same as 2006-02-01 and
364 % 2006-02-01+-2 is the same as 2006-01-30. And \year-\month-day+1 is
365 % tomorrow. You may add a space before the +.
366 %
367 % Example:
368 %
369 % \pgfcalendardatetojulian{2006-01-10}{\mycount}
370
371 \def\pgfcalendardatetojulian#1#2{\edef\pgf@temp{#1}\expandafter\pgfcalendar@datetojulian\pgf@temp+/{#2}}
372 \def\pgfcalendar@datetojulian#1-#2-#3+#4/#5{%
373 {%
374 %
375 % Store year, month and days.
376 %
377 \count1=#1\relax%
378 \count2=#2\relax%
379 % If #3=="last", then calculate first day of next month
380 \edef\pgf@temp{#3}%
381 \ifx\pgf@temp\pgfcalendar@last@text%
382 \advance\count2 by1\relax%
383 \count3=1\relax%
384 \else%
385 \count3=#3\relax%
386 \fi%
387 %
388 % Store offset
389 %
390 \edef\pgf@@temp{#4}%
391 \ifx\pgf@@temp\pgfutil@empty%
392 \count8=0\relax%
393 \else%
394 \pgfcalendar@unpack#4%
395 \fi%
396 %
397 %
398 % 4) a = \lfloor (14-month) /12 \rfloor
399 %
400 \ifnum\count2<3\relax%
401 \count4=1\relax%
402 \else%
403 \count4=0\relax%
404 \fi%
405 %
406 % 5) y = year + 4800 - a
407 %
408 \count5=\count1\relax%
409 \advance\count5 by 4800\relax%
410 \advance\count5 by-\count4\relax%
411 %
412 % 6) m = month + 12a - 3
413 %
414 \count6=\count2\relax%
415 \count0=\count4\relax%
416 \multiply\count0 by12\relax
417 \advance\count6 by\count0\relax%
418 \advance\count6 by-3\relax%
419 %
420 % 7) jdn = day + \floor{(153 m+2)/5} + 365y + \floor{y/4} -
421 % \floor{y/100} + \florr{y/400} - 32045
422 %
423 \count7=\count3\relax%
424 % + \floor{(153 m+2)/5} :
425 \count0=\count6\relax%
426 \multiply\count0 by 153\relax%
427 \advance\count0 by 2\relax%
428 \divide\count0 by 5\relax%
429 \advance\count7 by \count0\relax%
430 % + 365y :
431 \count0=\count5%
432 \multiply\count0by365\relax%
433 \advance\count7 by\count0\relax%
434 % + \floor{y/4}
435 \count0=\count5\relax%
436 \divide\count0 by 4\relax%
437 \advance\count7 by\count0%
438 % - \floor{y/100}
439 \count0=\count5\relax%
440 \divide\count0 by 100\relax%
441 \advance\count7 by-\count0\relax%
442 % + \floor{y/400}
443 \count0=\count5\relax%
444 \divide\count0 by 400\relax%
445 \advance\count7 by\count0%
446 % - 32045
447 \advance\count7 by-32045\relax%
448 %
449 % Undo "last" advance
450 \ifx\pgf@temp\pgfcalendar@last@text%
451 \advance\count7by-1\relax%
452 \fi%
453 % Add offset
454 \advance\count7by\count8\relax%
455 \expandafter%
456 }%
457 \expandafter#5\the\count7\relax%
458 }
459 \def\pgfcalendar@last@text{last}
460 \def\pgfcalendar@unpack#1+{%
461 \count8=#1\relax%
462 }
463
464 % Convert Julian day number date.
465 %
466 % #1 = the number of Julian days
467 % #2 = a macro in which the year should be stored.
468 % #3 = a macro in which the month should be stored.
469 % #4 = a macro in which the day should be stored.
470 %
471 % Formula used:
472 %
473 % 1) J = Julian day number
474 % 2) j = J + 32044
475 % 3) g = j div 146097
476 % 4) dg = j mod 146097
477 % 5) c = (dg div 36524 + 1) * 3 div 4
478 % 6) dc = dg - c * 36524
479 % 7) b = dc div 1461
480 % 8) db = dc mod 1461
481 % 9) a = (db div 365 + 1) * 3 div 4
482 % 10)da = db - a * 365
483 % 11)y = g * 400 + c * 100 + b * 4 + a
484 % 12)m = (da * 5 + 308) div 153 - 2
485 % 13)d = da - (m + 4) * 153 div 5 + 122
486 % 14)Y = y - 4800 + (m + 2) div 12
487 % 15)M = (m + 2) mod 12 + 1
488 % 16)D = d + 1
489 %
490 % Example
491 %
492 % \pgfcalendarjuliantodate{\mynumber}{\myyear}{\mymonth}{\myday}
493
494 \def\pgfcalendarjuliantodate#1#2#3#4{%
495 {%
496 % 1) J = Julian day number
497 \count1=#1\relax%
498 % 2) j = J + 32044
499 \count2=\count1\relax%
500 \advance\count2 by 32044\relax%
501 % 3) g = j div 146097
502 \count3=\count2\relax%
503 \divide\count3 by 146097\relax%
504 % 4) dg = j mod 146097
505 \count4=\count3\relax%
506 \multiply\count4 by-146097\relax%
507 \advance\count4 by\count2\relax%
508 % 5) c = (dg div 36524 + 1) * 3 div 4
509 \count5=\count4\relax%
510 \divide\count5 by36524\relax%
511 \advance\count5 by1\relax%
512 \multiply\count5 by3\relax%
513 \divide\count5 by4\relax%
514 % 6) dc = dg - c * 36524
515 \count6=\count4\relax%
516 \count0=\count5\relax%
517 \multiply\count0 by-36524\relax%
518 \advance\count6 by\count0\relax%
519 % 7) b = dc div 1461
520 \count7=\count6\relax%
521 \divide\count7 by1461\relax%
522 % 8) db = dc mod 1461
523 \count8=\count7\relax%
524 \multiply\count8 by-1461\relax%
525 \advance\count8 by\count6\relax%
526 % 9) a = (db div 365 + 1) * 3 div 4
527 \count9=\count8\relax%
528 \divide\count9 by 365\relax%
529 \advance\count9 by 1\relax%
530 \multiply\count9 by3\relax%
531 \divide\count9 by4\relax%
532 % 10)da = db - a * 365
533 \count10=\count8\relax%
534 \count0=\count9\relax%
535 \multiply\count0 by-365\relax%
536 \advance\count10 by\count0\relax%
537 % 11)y = g * 400 + c * 100 + b * 4 + a
538 \count11=\count3\relax%
539 \multiply\count11 by400\relax%
540 \count0=\count5\relax%
541 \multiply\count0 by100\relax%
542 \advance\count11 by\count0\relax%
543 \count0=\count7\relax%
544 \multiply\count0 by4\relax%
545 \advance\count11 by\count0\relax%
546 \advance\count11 by\count9\relax%
547 % 12)m = (da * 5 + 308) div 153 - 2
548 \count12=\count10\relax%
549 \multiply\count12 by5\relax%
550 \advance\count12 by 308\relax%
551 \divide\count12 by 153\relax%
552 \advance\count12 by -2\relax%
553 % 13)d = - (m + 4) * 153 div 5 + 122 + da
554 \count13=\count12\relax%
555 \advance\count13 by 4\relax%
556 \multiply\count13 by153\relax%
557 \divide\count13 by5\relax%
558 \count13=-\count13\relax%
559 \advance\count13 by 122\relax%
560 \advance\count13 by \count10\relax%
561 % 14)Y = (m + 2) div 12 + y - 4800
562 \count14=\count12\relax%
563 \advance\count14 by 2\relax%
564 \divide\count14 by12\relax%
565 \advance\count14 by\count11\relax%
566 \advance\count14 by-4800\relax%
567 % 15)M = (m + 2) mod 12 + 1
568 \count15=\count12\relax%
569 \advance\count15 by2\relax%
570 \count0=\count15\relax%
571 \divide\count0 by12\relax%
572 \multiply\count0 by12\relax%
573 \advance\count15 by-\count0\relax%
574 \advance\count15 by1\relax%
575 % 16)D = d + 1
576 \count16=\count13%
577 \advance\count16by 1\relax%
578 %
579 \xdef\pgf@temp@year{\the\count14}%
580 \xdef\pgf@temp@month{\ifnum\count15<10 0\fi\the\count15}%
581 \xdef\pgf@temp@day{\ifnum\count16<10 0\fi\the\count16}%
582 }%
583 \let#2=\pgf@temp@year%
584 \let#3=\pgf@temp@month%
585 \let#4=\pgf@temp@day%
586 }
587
588
589
590 % Returns the day of week as a number between 0 = Monday and 6 =
591 % Sunday
592 %
593 % #1 = a Julian day number
594 % #2 = a counter into which the weekday should be put.
595 %
596 % Example:
597 %
598 % \pgfcalendardatetojulian{2006-01-10}{\mycount}
599 % \pgfcalendarjuliantoweekday{\mycount}{\myweekday}
600
601 \def\pgfcalendarjuliantoweekday#1#2{%
602 {%
603 \pgfutil@tempcnta=#1\relax%
604 #2=\pgfutil@tempcnta%
605 \divide#2by7\relax%
606 \multiply#2by-7\relax%
607 \advance#2by\pgfutil@tempcnta\relax%
608 \expandafter%
609 }%
610 \expandafter#2\the#2\relax%
611 }
612
613
614
615 % Converts a day of week into a weekday name (long or short)
616 %
617 % #1 = a number representing a weekday (0=Monday)
618 %
619 % Example:
620 %
621 % \pgfcalendardatetojulian{2006-01-10}{\mycount}
622 % \pgfcalendarjuliantoweekday{\mycount}{\myweekday}
623 % October 1st, 2006 was a \pgfcalendarweekdayname{\myweekday}
624
625 \def\pgfcalendarweekdayname#1{%
626 \pgfutil@translate{\ifcase#1Monday\or Tuesday\or Wednesday\or Thursday\or Friday\or Saturday\or Sunday\fi}%
627 }
628
629 \def\pgfcalendarweekdayshortname#1{%
630 \pgfutil@translate{\ifcase#1Mon\or Tue\or Wed\or Thu\or Fri\or Sat\or Sun\fi}%
631 }
632
633
634 % Converts a month of year number into a month name (long or short)
635 %
636 % #1 = a number representing a month (1=January)
637 %
638 % Example:
639 %
640 % \pgfcalendarmonthname
641
642 \def\pgfcalendarmonthname#1{%
643 \pgfutil@translate{\ifcase#1\or January\or February\or March\or April\or
644 May\or June\or July\or August\or September\or October\or
645 November\or December\fi}%
646 }
647
648 \def\pgfcalendarmonthshortname#1{%
649 \pgfutil@translate{\ifcase#1\or Jan\or Feb\or Mar\or Apr\or
650 May\or Jun\or Jul\or Aug\or Sep\or Oct\or
651 Nov\or Dec\fi}%
652 }
653
654
655
656
657
658
659 % Macro for easy typesetting of days, etc.
660 %
661 % #1 = kind selection
662 % #2 = length and representation selection
663 %
664 % Description:
665 %
666 % Replaces the shorthand according to the following rules: The
667 % first letter of the shorthand describes the kind of
668 % shorthand. Possible kinds are:
669 %
670 % d = day of current date (in an invocation of \pgfcalendar)
671 % m = month of current date
672 % y = year of current date
673 % w = week day of current date
674 %
675 % The second parameter determines how the kind is represented:
676 %
677 % - = shortest possible numerical way (allowed only for d, m, y)
678 % = = same, but always of the same length (padded with blanks as
679 % needed, allowed only for d, m, y)
680 % 0 = numerical representation for d and m padded with leading zeros.
681 % t = textual representation (allowed only for d, m, w)
682 % . = abbreviated textual representation (allowed only for d, m, w)
683 %
684 % It is advised that you say, for example,
685 % \let\%=\pgfcalendarshorthand.
686 %
687 % With this setting, you can typeset an ISO-date by saying \%y0-\%m0-\%d0.
688 % For another example, on 2007-02-09, which is a
689 % Friday, you can write "\%wt, \%mt \%d-, \%y0" to get "Friday, February 9, 2007"
690
691 \def\pgfcalendarshorthand#1#2{\csname pgfcalendar@shorthand@#1#2\endcsname}
692 \expandafter\def\csname pgfcalendar@shorthand@d-\endcsname{%
693 {\pgfutil@tempcnta=\pgfcalendarcurrentday\relax\the\pgfutil@tempcnta}}
694 \expandafter\def\csname pgfcalendar@shorthand@d=\endcsname{%
695 {\pgfutil@tempcnta=\pgfcalendarcurrentday\relax\ifnum\pgfutil@tempcnta<10\relax\setbox0=\hbox{1}\kern\wd0\relax\fi\the\pgfutil@tempcnta}}
696 \expandafter\def\csname pgfcalendar@shorthand@d0\endcsname{%
697 \pgfcalendarcurrentday}
698 \expandafter\def\csname pgfcalendar@shorthand@m-\endcsname{%
699 {\pgfutil@tempcnta=\pgfcalendarcurrentmonth\relax\the\pgfutil@tempcnta}}
700 \expandafter\def\csname pgfcalendar@shorthand@m=\endcsname{%
701 {\pgfutil@tempcnta=\pgfcalendarcurrentmonth\relax\ifnum\pgfutil@tempcnta<10\relax\setbox0=\hbox{1}\kern\wd0\relax\fi\the\pgfutil@tempcnta}}
702 \expandafter\def\csname pgfcalendar@shorthand@m0\endcsname{%
703 \pgfcalendarcurrentmonth}
704 \expandafter\def\csname pgfcalendar@shorthand@y-\endcsname{%
705 \pgfcalendarcurrentyear}
706 \expandafter\def\csname pgfcalendar@shorthand@y=\endcsname{%
707 \pgfcalendarcurrentyear}
708 \expandafter\def\csname pgfcalendar@shorthand@y0\endcsname{%
709 \pgfcalendarcurrentyear}
710 \expandafter\def\csname pgfcalendar@shorthand@w.\endcsname{%
711 \pgfcalendarweekdayshortname{\pgfcalendarcurrentweekday}}
712 \expandafter\def\csname pgfcalendar@shorthand@wt\endcsname{%
713 \pgfcalendarweekdayname{\pgfcalendarcurrentweekday}}
714 \expandafter\def\csname pgfcalendar@shorthand@m.\endcsname{%
715 \pgfcalendarmonthshortname{\pgfcalendarcurrentmonth}}
716 \expandafter\def\csname pgfcalendar@shorthand@mt\endcsname{%
717 \pgfcalendarmonthname{\pgfcalendarcurrentmonth}}
718
719 % Calculate the date of Easter
720
721 % Credits to HÃ¥kon Malmedal on TeX.SX https://tex.stackexchange.com/a/57243
722 % and Donald Knuth, TAoCP, Vol 1, 3rd Ed, Section 1.3.2, Algorithm E, p. 160.
723
724 \newcount\pgf@cal@easter@Y
725 \newcount\pgf@cal@easter@G
726 \newcount\pgf@cal@easter@C
727 \newcount\pgf@cal@easter@X
728 \newcount\pgf@cal@easter@Z
729 \newcount\pgf@cal@easter@D
730 \newcount\pgf@cal@easter@E
731 \newcount\pgf@cal@easter@N
732 \newcount\pgf@cal@easter@M
733 \newcount\pgf@cal@easter@julianday
734
735 \pgfutil@protected\def\pgfcalendareastersunday#1#2{%
736 \pgfintset\pgf@cal@easter@Y{#1}%
737 % E1. Golden number
738 \pgfintset\pgf@cal@easter@G{%
739 \pgfintmod{\pgf@cal@easter@Y}{19}+1
740 }%
741 % E2. Century
742 \pgfintset\pgf@cal@easter@C{%
743 \pgfintdivfloor{\pgf@cal@easter@Y}{100}+1
744 }%
745 % E3. Corrections
746 \pgfintset\pgf@cal@easter@X{%
747 \pgfintdivfloor{3*\pgf@cal@easter@C}{4}-12
748 }%
749 \pgfintset\pgf@cal@easter@Z{%
750 \pgfintdivfloor{8*\pgf@cal@easter@C+5}{25}-5
751 }%
752 % E4. Find Sunday
753 \pgfintset\pgf@cal@easter@D{%
754 \pgfintdivfloor{5*\pgf@cal@easter@Y}{4}-\pgf@cal@easter@X-10
755 }%
756 % E5. Epact (full moon)
757 \pgfintset\pgf@cal@easter@E{%
758 \pgfintmod{11*\pgf@cal@easter@G+20+\pgf@cal@easter@Z-\pgf@cal@easter@X}{30}
759 }%
760 \ifnum\pgf@cal@easter@E<0
761 \pgfintset\pgf@cal@easter@E{\pgf@cal@easter@E+30}%
762 \fi
763 \ifnum\pgf@cal@easter@E=25
764 \ifnum\pgf@cal@easter@G>11
765 \pgfintset\pgf@cal@easter@E{\pgf@cal@easter@E+1}%
766 \fi
767 \else
768 \ifnum\pgf@cal@easter@E=24
769 \pgfintset\pgf@cal@easter@E{\pgf@cal@easter@E+1}%
770 \fi
771 \fi
772 % E6. Find full moon
773 \pgfintset\pgf@cal@easter@N{44-\pgf@cal@easter@E}%
774 \ifnum\pgf@cal@easter@N<21
775 \pgfintset\pgf@cal@easter@N{\pgf@cal@easter@N+30}%
776 \fi
777 % E7. Advance to Sunday
778 \pgfintset\pgf@cal@easter@N{%
779 \pgf@cal@easter@N+7-\pgfintmod{\pgf@cal@easter@D+\pgf@cal@easter@N}{7}
780 }%
781 % E8. Get month
782 \ifnum\pgf@cal@easter@N>31
783 \pgfintset\pgf@cal@easter@N{\pgf@cal@easter@N-31}%
784 \pgfintset\pgf@cal@easter@M{4}% April
785 \else
786 \pgfintset\pgf@cal@easter@M{3}% March
787 \fi
788 \pgfcalendardatetojulian
789 {\pgf@cal@easter@Y-\pgf@cal@easter@M-\pgf@cal@easter@N}%
790 {#2}%
791 }
792
793 \pgfkeys{/pgf/calendar/Easter/.cd,.default=0,.code={%
794 \pgfcalendareastersunday{\pgfcalendarifdateyear}{\pgf@cal@easter@julianday}%
795 \ifnum\pgfcalendarifdatejulian=\pgfinteval{\pgf@cal@easter@julianday+#1}
796 \expandafter\pgfcalendarmatchestrue
797 \fi}%
798 }
799
800
801 \endinput