summaryrefslogtreecommitdiff
path: root/graphics/pgf/base/tex/pgfcalendar.code.tex
blob: a954d4adf03d2c5a78e6055f14e6bf19bda62faa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
% Copyright 2019 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS{pgfcalendar.code.tex}

\input pgfint.code.tex

% Translation stuff

\ifx\translate\@undefined
  \def\translate#1{#1}
\fi

% Load month dictionary, if possible

\ifx\usedictionary\@undefined
\else
  \usedictionary{translator-months-dictionary}
\fi




% Typeset a calendar
%
% #1 = prefix for the calendar nodes
% #2 = begin date in ISO format
% #3 = end date in ISO format
% #4 = date rendering code
%
% Description:
%
% First note that this macro need not be called inside a pgfpicture
% (even though it often will be). You can use it to typeset
% calendars also using packages other than pgf. You do not even need
% to load pgf to use this file.
%
% A calendar is typeset as follows: You specify a range of dates (by
% providing a begin and an end date). Then, for each date the code #4
% is executed. When the code is called, lots of information about the
% current date (like its day of week) is available. The job of
% #4 is to render the date. Typically, this is done by placing nodes
% somewhere, but the function could do other things as well.
% It is also the job of #4 to position the calendar correctly.
%
% The different calls of #4 are not surrounded by TeX groups (though
% you can do so yourself, of course). This means that settings can
% accumulate between different calls, which is often desirable and
% useful.
%
% Inside #4 code, different macros can be access:
%
% \pgfcalendarprefix
% The parameter #1. This prefix is recommended for nodes inside the
% calendar, but you have to use it yourself explicitly.
%
% \pgfcalendarbeginiso
% Start date of range being typeset in ISO format (like 2006-01-10)
%
% \pgfcalendarbeginjulian
% Julian day number of start date begin typeset
%
% \pgfcalendarendiso
% End date of range begin typeset
%
% \pgfcalendarendjulian
% Same as Julian day number
%
% \pgfcalendarcurrentjulian (a TeX-count)
% Julian day number of day to be rendered/considered
%
% \pgfcalendarcurrentweekday
% Weekday (0 = Monday) of day to be checked
%
% \pgfcalendarcurrentyear
% Year of day to be checked
%
% \pgfcalendarcurrentmonth
% Month of day to be checked
%
% \pgfcalendarcurrentday
% Day of month of day to be checked
%
%
% Inside the \pgfcalendar macro the macro \ifdate is available, which
% has the same effect as \pgfcalendarifdate{\pgfcalendarcurrentjulian}
% (only faster). This means that you
% can write, say, \ifdate{Monday}{current date is a Monday}{Not a Monday}.
%
% Example:
%
% \begin{tikzpicture}
%   \pgfcalendar{cal}{2007-01-20}{2007-02-10}
%     {\node[anchor=base] {\pgfcalendaronday}; \pgftransformyshift{-1.5em}}
% \end{tikzpicture}
%
% \pgfcalendar{cal}{2007-01-20}{2007-02-10}{ \pgfcalendaronday\ }

\long\def\pgfcalendar#1#2#3#4{%
  \begingroup%
    % Setup local \ifdate
    \let\ifdate=\pgfcalendar@local@ifdate%
    % Let's start with computing start and end dates...
    \def\pgfcalendarprefix{#1}%
    \pgfcalendardatetojulian{#2}{\pgfcalendarcurrentjulian}%
    \edef\pgfcalendarbeginjulian{\the\pgfcalendarcurrentjulian}%
    \edef\pgfcalendarbeginiso{#2}%
    \pgfcalendardatetojulian{#3}{\pgfutil@tempcnta}%
    \edef\pgfcalendarendjulian{\the\pgfutil@tempcnta}%
    \advance\pgfutil@tempcnta by1\relax%
    \edef\pgfcalendarendjulianplus{\the\pgfutil@tempcnta}%
    \edef\pgfcalendarendiso{#3}%
    %
    % Start main loop
    %
    \loop%
    \ifnum\pgfcalendarcurrentjulian<\pgfcalendarendjulianplus\relax%
      % Setup information about current date
      \pgfcalendarjuliantodate{\pgfcalendarcurrentjulian}%
      {\pgfcalendarcurrentyear}{\pgfcalendarcurrentmonth}{\pgfcalendarcurrentday}%
      \pgfcalendarjuliantoweekday{\pgfcalendarcurrentjulian}{\pgfutil@tempcntb}%
      \edef\pgfcalendarcurrentweekday{\the\pgfutil@tempcntb}%
      % Render:
      #4%
      % Advance day:
      \advance\pgfcalendarcurrentjulian by1\relax%
    \repeat%
  \endgroup%
}

\newcount\pgfcalendarcurrentjulian

\def\pgfcalendar@local@ifdate{%
  \let\pgfcalendarifdatejulian=\pgfcalendarcurrentjulian%
  \let\pgfcalendarifdateyear=\pgfcalendarcurrentyear%
  \let\pgfcalendarifdatemonth=\pgfcalendarcurrentmonth%
  \let\pgfcalendarifdateday=\pgfcalendarcurrentday%
  \let\pgfcalendarifdateweekday=\pgfcalendarcurrentweekday%
  \pgfcalendar@launch@ifdate%
}



% Execute on specific kinds of dates
%
% #1 = ISO-format date
% #2 = date specification
% #3 = code
%
% Description:
%
% The given code #3 is execute on every day that matches the date
% specification #2. This specification is a comma-separated list of
% key-value pairs with the path /pgf/calendar. The code for a
% key-value should check whether the given day matches its
% specification. If so, it should set \pgfcalendarmatches to true.
%
% When the key-value code is executed, the following macros will have
% been setup:
%
% \pgfcalendarifdatejulian
% Julian day number of day to be checked
%
% \pgfcalendarifdateweekday
% Weekday (0 = Monday) of day to be checked
%
% \pgfcalendarifdateyear
% Year of day to be checked
%
% \pgfcalendarifdatemonth
% Month of day to be checked
%
% \pgfcalendarifdateday
% Day of month of day to be checked
%
% The setting of these macros will persist after the call, so a
% side-effect of calling this macro is to setup these macros.
%
% By setting \ifpgfcalendar@do@not@recompute to false, the computation
% of the year, month etc. is suppressed.
%
% Examples:
%
% \pgfcalendarifdate{2007-01-10}{all}{}
% % Simply setup the macros
%
% \pgfcalendarifdate{2007-01-10}{mondays}{Is a monday}
%
% \pgfcalendarifdate{\mydate}{date=05-01}{\mydate is a Worker's Day}

\def\pgfcalendarifdate#1#2#3#4{%
  \pgfcalendardatetojulian{#1}{\pgfutil@tempcnta}%
  \pgfcalendarjuliantodate{\pgfutil@tempcnta}
    {\pgfcalendarifdateyear}{\pgfcalendarifdatemonth}{\pgfcalendarifdateday}%
  \edef\pgfcalendarifdatejulian{\the\pgfutil@tempcnta}%
  % Compute info about date
  \pgfcalendarjuliantoweekday{\pgfutil@tempcnta}{\pgfutil@tempcntb}%
  \edef\pgfcalendarifdateweekday{\the\pgfutil@tempcntb}%
  %
  \pgfcalendar@launch@ifdate{#2}{#3}{#4}%
}


\long\def\pgfcalendar@launch@ifdate#1#2#3{%
  % When this macro is called, the pgfcalendarifdatexxxx macros must
  % be setup correctly
  %
  % Set match to false
  \pgfcalendarmatchesfalse%
  \pgfqkeys{/pgf/calendar}{#1}%
  \ifpgfcalendarmatches%
    #2%
  \else%
    #3%
  \fi%
}

\newif\ifpgfcalendarmatches


% Keys for matching

\pgfkeys{/pgf/calendar/all/.code=\pgfcalendarmatchestrue}

\pgfkeys{/pgf/calendar/Monday/.code={\ifnum\pgfcalendarifdateweekday=0\relax\pgfcalendarmatchestrue\fi}}
\pgfkeys{/pgf/calendar/Tuesday/.code={\ifnum\pgfcalendarifdateweekday=1\relax\pgfcalendarmatchestrue\fi}}
\pgfkeys{/pgf/calendar/Wednesday/.code={\ifnum\pgfcalendarifdateweekday=2\relax\pgfcalendarmatchestrue\fi}}
\pgfkeys{/pgf/calendar/Thursday/.code={\ifnum\pgfcalendarifdateweekday=3\relax\pgfcalendarmatchestrue\fi}}
\pgfkeys{/pgf/calendar/Friday/.code={\ifnum\pgfcalendarifdateweekday=4\relax\pgfcalendarmatchestrue\fi}}
\pgfkeys{/pgf/calendar/Saturday/.code={\ifnum\pgfcalendarifdateweekday=5\relax\pgfcalendarmatchestrue\fi}}
\pgfkeys{/pgf/calendar/Sunday/.code={\ifnum\pgfcalendarifdateweekday=6\relax\pgfcalendarmatchestrue\fi}}

\pgfkeys{/pgf/calendar/workday/.code={\ifnum\pgfcalendarifdateweekday<5\relax\pgfcalendarmatchestrue\fi}}
\pgfkeys{/pgf/calendar/weekend/.code={\ifnum\pgfcalendarifdateweekday>4\relax\pgfcalendarmatchestrue\fi}}

\pgfkeys{/pgf/calendar/equals/.cd,.value required,.code={%
  \pgfcalendar@special@datetojulian{#1}%
  \ifnum\pgfcalendarifdatejulian=\pgfutil@tempcnta\relax%
    \pgfcalendarmatchestrue%
  \fi}%
}

\pgfkeys{/pgf/calendar/day of month/.cd,.value required,.code={\ifnum#1=\pgfcalendarifdateday\relax\pgfcalendarmatchestrue\fi}}
\pgfkeys{/pgf/calendar/end of month/.cd,.default=1,.code={%
  % Tricky and expensive ... do only if necessary
  \ifpgfcalendarmatches%
  \else% sigh
    {%
      \pgfutil@tempcnta=\pgfcalendarifdatejulian\relax%
      \advance\pgfutil@tempcnta by#1\relax%
      \pgfcalendarjuliantodate{\pgfutil@tempcnta}{\pgf@dummy}{\pgf@dummy}{\pgf@cal@temp}%
      \global\let\pgf@cal@temp=\pgf@cal@temp%
    }%
    \ifnum\pgf@cal@temp=1\relax\pgfcalendarmatchestrue\fi%
  \fi}%
}

\pgfkeys{/pgf/calendar/at least/.cd,.value required,.code={%
  \pgfcalendar@special@datetojulian{#1}%
  \ifnum\pgfcalendarifdatejulian<\pgfutil@tempcnta\relax%
  \else%
    \pgfcalendarmatchestrue%
  \fi%
}}

\pgfkeys{/pgf/calendar/at most/.cd,.value required,.code={%
  \pgfcalendar@special@datetojulian{#1}%
  \ifnum\pgfcalendarifdatejulian>\pgfutil@tempcnta\relax%
  \else%
    \pgfcalendarmatchestrue%
  \fi%
}}

\pgfkeys{/pgf/calendar/between/.cd,.value required,.code args={#1and#2}{%
  \pgfcalendar@special@datetojulian{#1}%
  \ifnum\pgfcalendarifdatejulian<\pgfutil@tempcnta\relax%
  \else%
    \pgfcalendar@special@datetojulian{#2}%
    \ifnum\pgfcalendarifdatejulian>\pgfutil@tempcnta\relax%
    \else%
      \pgfcalendarmatchestrue%
    \fi%
  \fi%
}}

\def\pgfcalendar@special@datetojulian#1{%
  \edef\pgf@temp{#1}%
  \expandafter\pgfcalendar@special@split@test\pgf@temp-\relax{#1}%
}

\def\pgfcalendar@special@split@test#1-#2-#3\relax#4{%
  \def\pgf@temp{#3}%
  \ifx\pgf@temp\pgfutil@empty%
    \def\pgf@temp{\pgfcalendarifdateyear-#1-#2}%
  \else%
    \def\pgf@temp{#4}%
  \fi%
  \pgfcalendardatetojulian{\pgf@temp}{\pgfutil@tempcnta}%
}


% Suggested name for nodes inside a calendar
%
% Description:
%
% It is suggested that (main) nodes (if present) in a calendar should
% get this name.
%
% Example:
%
% \pgfcalendar{cal}{2007-01-20}{2007-02-10}{}
% { \node[anchor=base] (\pgfcalendarsuggestedname) {\pgfcalendarifdateday};
%   \pgftransformyshift{-1.5em} }
%
% \draw (cal-2007-01-30) -- (cal-2007-02-08);

\def\pgfcalendarsuggestedname{%
  \ifx\pgfcalendarprefix\pgfutil@empty\else\pgfcalendarprefix-%
  \pgfcalendarcurrentyear-\pgfcalendarcurrentmonth-\pgfcalendarcurrentday\fi%
}



%
%
% Date conversion functions
%
%



% Convert a date to the Julian day number (number of days since
% January 1st, -4712)
%
% #1 = date specification
% #2 = counter that should be set to the number of days
%
% Description:
%
% The conversion is taken from the Wikipedia entry on Julian days.
%
% The date specification works as follows:
%
% - It starts with a year. Use \year for the current year (the year
%   the file is being typeset).
% - Next comes a hyphen.
% - Next comes a month (number). Use \month for the current month.
% - Next comes a hyphen.
% - Next comes either a day of month (number, use \day for current
%   day) or "last". The keyword "last" refers the last day of the
%   month. Thus, 2006-01-last is the same as 2006-01-31 and
%   2000-02-last is the same as 2002-02-29.
% - Next may come a plus sign, followed by a number (positive or
%   negative). This will adjust the date by the given number of
%   days. Thus, 2006-01-31+1 is the same as 2006-02-01 and
%   2006-02-01+-2 is the same as 2006-01-30. And \year-\month-day+1 is
%   tomorrow. You may add a space before the +.
%
% Example:
%
% \pgfcalendardatetojulian{2006-01-10}{\mycount}

\def\pgfcalendardatetojulian#1#2{\edef\pgf@temp{#1}\expandafter\pgfcalendar@datetojulian\pgf@temp+/{#2}}
\def\pgfcalendar@datetojulian#1-#2-#3+#4/#5{%
  {%
    %
    % Store year, month and days.
    %
    \count1=#1\relax%
    \count2=#2\relax%
    % If #3=="last", then calculate first day of next month
    \edef\pgf@temp{#3}%
    \ifx\pgf@temp\pgfcalendar@last@text%
      \advance\count2 by1\relax%
      \count3=1\relax%
    \else%
      \count3=#3\relax%
    \fi%
    %
    % Store offset
    %
    \edef\pgf@@temp{#4}%
    \ifx\pgf@@temp\pgfutil@empty%
      \count8=0\relax%
    \else%
      \pgfcalendar@unpack#4%
    \fi%
    %
    %
    % 4) a = \lfloor (14-month) /12 \rfloor
    %
    \ifnum\count2<3\relax%
      \count4=1\relax%
    \else%
      \count4=0\relax%
    \fi%
    %
    % 5) y = year + 4800 - a
    %
    \count5=\count1\relax%
    \advance\count5 by 4800\relax%
    \advance\count5 by-\count4\relax%
    %
    % 6) m = month + 12a - 3
    %
    \count6=\count2\relax%
    \count0=\count4\relax%
    \multiply\count0 by12\relax
    \advance\count6 by\count0\relax%
    \advance\count6 by-3\relax%
    %
    % 7) jdn = day + \floor{(153 m+2)/5} + 365y + \floor{y/4} -
    % \floor{y/100} + \florr{y/400} - 32045
    %
    \count7=\count3\relax%
    % + \floor{(153 m+2)/5} :
    \count0=\count6\relax%
    \multiply\count0 by 153\relax%
    \advance\count0 by 2\relax%
    \divide\count0 by 5\relax%
    \advance\count7 by \count0\relax%
    % + 365y :
    \count0=\count5%
    \multiply\count0by365\relax%
    \advance\count7 by\count0\relax%
    % + \floor{y/4}
    \count0=\count5\relax%
    \divide\count0 by 4\relax%
    \advance\count7 by\count0%
    % - \floor{y/100}
    \count0=\count5\relax%
    \divide\count0 by 100\relax%
    \advance\count7 by-\count0\relax%
    % + \floor{y/400}
    \count0=\count5\relax%
    \divide\count0 by 400\relax%
    \advance\count7 by\count0%
    %  - 32045
    \advance\count7 by-32045\relax%
    %
    % Undo "last" advance
    \ifx\pgf@temp\pgfcalendar@last@text%
      \advance\count7by-1\relax%
    \fi%
    % Add offset
    \advance\count7by\count8\relax%
    \expandafter%
  }%
  \expandafter#5\the\count7\relax%
}
\def\pgfcalendar@last@text{last}
\def\pgfcalendar@unpack#1+{%
  \count8=#1\relax%
}

% Convert Julian day number date.
%
% #1 = the number of Julian days
% #2 = a macro in which the year should be stored.
% #3 = a macro in which the month should be stored.
% #4 = a macro in which the day should be stored.
%
% Formula used:
%
% 1) J = Julian day number
% 2) j = J + 32044
% 3) g = j div 146097
% 4) dg = j mod 146097
% 5) c = (dg div 36524 + 1) * 3 div 4
% 6) dc = dg - c * 36524
% 7) b = dc div 1461
% 8) db = dc mod 1461
% 9) a = (db div 365 + 1) * 3 div 4
% 10)da = db - a * 365
% 11)y = g * 400 + c * 100 + b * 4 + a
% 12)m = (da * 5 + 308) div 153 - 2
% 13)d = da - (m + 4) * 153 div 5 + 122
% 14)Y = y - 4800 + (m + 2) div 12
% 15)M = (m + 2) mod 12 + 1
% 16)D = d + 1
%
% Example
%
% \pgfcalendarjuliantodate{\mynumber}{\myyear}{\mymonth}{\myday}

\def\pgfcalendarjuliantodate#1#2#3#4{%
  {%
    % 1) J = Julian day number
    \count1=#1\relax%
    % 2) j = J + 32044
    \count2=\count1\relax%
    \advance\count2 by 32044\relax%
    % 3) g = j div 146097
    \count3=\count2\relax%
    \divide\count3 by 146097\relax%
    % 4) dg = j mod 146097
    \count4=\count3\relax%
    \multiply\count4 by-146097\relax%
    \advance\count4 by\count2\relax%
    % 5) c = (dg div 36524 + 1) * 3 div 4
    \count5=\count4\relax%
    \divide\count5 by36524\relax%
    \advance\count5 by1\relax%
    \multiply\count5 by3\relax%
    \divide\count5 by4\relax%
    % 6) dc = dg - c * 36524
    \count6=\count4\relax%
    \count0=\count5\relax%
    \multiply\count0 by-36524\relax%
    \advance\count6 by\count0\relax%
    % 7) b = dc div 1461
    \count7=\count6\relax%
    \divide\count7 by1461\relax%
    % 8) db = dc mod 1461
    \count8=\count7\relax%
    \multiply\count8 by-1461\relax%
    \advance\count8 by\count6\relax%
    % 9) a = (db div 365 + 1) * 3 div 4
    \count9=\count8\relax%
    \divide\count9 by 365\relax%
    \advance\count9 by 1\relax%
    \multiply\count9 by3\relax%
    \divide\count9 by4\relax%
    % 10)da = db - a * 365
    \count10=\count8\relax%
    \count0=\count9\relax%
    \multiply\count0 by-365\relax%
    \advance\count10 by\count0\relax%
    % 11)y = g * 400 + c * 100 + b * 4 + a
    \count11=\count3\relax%
    \multiply\count11 by400\relax%
    \count0=\count5\relax%
    \multiply\count0 by100\relax%
    \advance\count11 by\count0\relax%
    \count0=\count7\relax%
    \multiply\count0 by4\relax%
    \advance\count11 by\count0\relax%
    \advance\count11 by\count9\relax%
    % 12)m = (da * 5 + 308) div 153 - 2
    \count12=\count10\relax%
    \multiply\count12 by5\relax%
    \advance\count12 by 308\relax%
    \divide\count12 by 153\relax%
    \advance\count12 by -2\relax%
    % 13)d = - (m + 4) * 153 div 5 + 122 + da
    \count13=\count12\relax%
    \advance\count13 by 4\relax%
    \multiply\count13 by153\relax%
    \divide\count13 by5\relax%
    \count13=-\count13\relax%
    \advance\count13 by 122\relax%
    \advance\count13 by \count10\relax%
    % 14)Y =  (m + 2) div 12 + y - 4800
    \count14=\count12\relax%
    \advance\count14 by 2\relax%
    \divide\count14 by12\relax%
    \advance\count14 by\count11\relax%
    \advance\count14 by-4800\relax%
    % 15)M = (m + 2) mod 12 + 1
    \count15=\count12\relax%
    \advance\count15 by2\relax%
    \count0=\count15\relax%
    \divide\count0 by12\relax%
    \multiply\count0 by12\relax%
    \advance\count15 by-\count0\relax%
    \advance\count15 by1\relax%
    % 16)D = d + 1
    \count16=\count13%
    \advance\count16by 1\relax%
    %
    \xdef\pgf@temp@year{\the\count14}%
    \xdef\pgf@temp@month{\ifnum\count15<10 0\fi\the\count15}%
    \xdef\pgf@temp@day{\ifnum\count16<10 0\fi\the\count16}%
  }%
  \let#2=\pgf@temp@year%
  \let#3=\pgf@temp@month%
  \let#4=\pgf@temp@day%
}



% Returns the day of week as a number between 0 = Monday and 6 =
% Sunday
%
% #1 = a Julian day number
% #2 = a counter into which the weekday should be put.
%
% Example:
%
% \pgfcalendardatetojulian{2006-01-10}{\mycount}
% \pgfcalendarjuliantoweekday{\mycount}{\myweekday}

\def\pgfcalendarjuliantoweekday#1#2{%
  {%
    \pgfutil@tempcnta=#1\relax%
    #2=\pgfutil@tempcnta%
    \divide#2by7\relax%
    \multiply#2by-7\relax%
    \advance#2by\pgfutil@tempcnta\relax%
    \expandafter%
  }%
  \expandafter#2\the#2\relax%
}



% Converts a day of week into a weekday name (long or short)
%
% #1 = a number representing a weekday (0=Monday)
%
% Example:
%
% \pgfcalendardatetojulian{2006-01-10}{\mycount}
% \pgfcalendarjuliantoweekday{\mycount}{\myweekday}
% October 1st, 2006 was a \pgfcalendarweekdayname{\myweekday}

\def\pgfcalendarweekdayname#1{%
  \pgfutil@translate{\ifcase#1Monday\or Tuesday\or Wednesday\or Thursday\or Friday\or Saturday\or Sunday\fi}%
}

\def\pgfcalendarweekdayshortname#1{%
  \pgfutil@translate{\ifcase#1Mon\or Tue\or Wed\or Thu\or Fri\or Sat\or Sun\fi}%
}


% Converts a month of year number into a month name (long or short)
%
% #1 = a number representing a month (1=January)
%
% Example:
%
% \pgfcalendarmonthname

\def\pgfcalendarmonthname#1{%
  \pgfutil@translate{\ifcase#1\or January\or February\or March\or April\or
    May\or June\or July\or August\or September\or October\or
    November\or December\fi}%
}

\def\pgfcalendarmonthshortname#1{%
  \pgfutil@translate{\ifcase#1\or Jan\or Feb\or Mar\or Apr\or
    May\or Jun\or Jul\or Aug\or Sep\or Oct\or
    Nov\or Dec\fi}%
}






% Macro for easy typesetting of days, etc.
%
% #1 = kind selection
% #2 = length and representation selection
%
% Description:
%
% Replaces the shorthand according to the following rules: The
% first letter of the shorthand describes the kind of
% shorthand. Possible kinds are:
%
% d = day of current date (in an invocation of \pgfcalendar)
% m = month of current date
% y = year of current date
% w = week day of current date
%
% The second parameter determines how the kind is represented:
%
% - = shortest possible numerical way (allowed only for d, m, y)
% = = same, but always of the same length (padded with blanks as
%     needed, allowed only for d, m, y)
% 0 = numerical representation for d and m padded with leading zeros.
% t = textual representation (allowed only for d, m, w)
% . = abbreviated textual representation (allowed only for d, m, w)
%
% It is advised that you say, for example,
% \let\%=\pgfcalendarshorthand.
%
% With this setting, you can typeset an ISO-date by saying \%y0-\%m0-\%d0.
% For another example, on 2007-02-09, which is a
% Friday, you can write "\%wt, \%mt \%d-, \%y0" to get "Friday, February 9, 2007"

\def\pgfcalendarshorthand#1#2{\csname pgfcalendar@shorthand@#1#2\endcsname}
\expandafter\def\csname pgfcalendar@shorthand@d-\endcsname{%
  {\pgfutil@tempcnta=\pgfcalendarcurrentday\relax\the\pgfutil@tempcnta}}
\expandafter\def\csname pgfcalendar@shorthand@d=\endcsname{%
  {\pgfutil@tempcnta=\pgfcalendarcurrentday\relax\ifnum\pgfutil@tempcnta<10\relax\setbox0=\hbox{1}\kern\wd0\relax\fi\the\pgfutil@tempcnta}}
\expandafter\def\csname pgfcalendar@shorthand@d0\endcsname{%
  \pgfcalendarcurrentday}
\expandafter\def\csname pgfcalendar@shorthand@m-\endcsname{%
  {\pgfutil@tempcnta=\pgfcalendarcurrentmonth\relax\the\pgfutil@tempcnta}}
\expandafter\def\csname pgfcalendar@shorthand@m=\endcsname{%
  {\pgfutil@tempcnta=\pgfcalendarcurrentmonth\relax\ifnum\pgfutil@tempcnta<10\relax\setbox0=\hbox{1}\kern\wd0\relax\fi\the\pgfutil@tempcnta}}
\expandafter\def\csname pgfcalendar@shorthand@m0\endcsname{%
  \pgfcalendarcurrentmonth}
\expandafter\def\csname pgfcalendar@shorthand@y-\endcsname{%
  \pgfcalendarcurrentyear}
\expandafter\def\csname pgfcalendar@shorthand@y=\endcsname{%
  \pgfcalendarcurrentyear}
\expandafter\def\csname pgfcalendar@shorthand@y0\endcsname{%
  \pgfcalendarcurrentyear}
\expandafter\def\csname pgfcalendar@shorthand@w.\endcsname{%
  \pgfcalendarweekdayshortname{\pgfcalendarcurrentweekday}}
\expandafter\def\csname pgfcalendar@shorthand@wt\endcsname{%
  \pgfcalendarweekdayname{\pgfcalendarcurrentweekday}}
\expandafter\def\csname pgfcalendar@shorthand@m.\endcsname{%
  \pgfcalendarmonthshortname{\pgfcalendarcurrentmonth}}
\expandafter\def\csname pgfcalendar@shorthand@mt\endcsname{%
  \pgfcalendarmonthname{\pgfcalendarcurrentmonth}}

% Calculate the date of Easter

% Credits to Håkon Malmedal on TeX.SX https://tex.stackexchange.com/a/57243
% and Donald Knuth, TAoCP, Vol 1, 3rd Ed, Section 1.3.2, Algorithm E, p. 160.

\newcount\pgf@cal@easter@Y
\newcount\pgf@cal@easter@G
\newcount\pgf@cal@easter@C
\newcount\pgf@cal@easter@X
\newcount\pgf@cal@easter@Z
\newcount\pgf@cal@easter@D
\newcount\pgf@cal@easter@E
\newcount\pgf@cal@easter@N
\newcount\pgf@cal@easter@M
\newcount\pgf@cal@easter@julianday

\pgfutil@protected\def\pgfcalendareastersunday#1#2{%
  \pgfintset\pgf@cal@easter@Y{#1}%
  % E1. Golden number
  \pgfintset\pgf@cal@easter@G{%
    \pgfintmod{\pgf@cal@easter@Y}{19}+1
  }%
  % E2. Century
  \pgfintset\pgf@cal@easter@C{%
    \pgfintdivfloor{\pgf@cal@easter@Y}{100}+1
  }%
  % E3. Corrections
  \pgfintset\pgf@cal@easter@X{%
    \pgfintdivfloor{3*\pgf@cal@easter@C}{4}-12
  }%
  \pgfintset\pgf@cal@easter@Z{%
    \pgfintdivfloor{8*\pgf@cal@easter@C+5}{25}-5
  }%
  % E4. Find Sunday
  \pgfintset\pgf@cal@easter@D{%
    \pgfintdivfloor{5*\pgf@cal@easter@Y}{4}-\pgf@cal@easter@X-10
  }%
  % E5. Epact (full moon)
  \pgfintset\pgf@cal@easter@E{%
    \pgfintmod{11*\pgf@cal@easter@G+20+\pgf@cal@easter@Z-\pgf@cal@easter@X}{30}
  }%
  \ifnum\pgf@cal@easter@E<0
    \pgfintset\pgf@cal@easter@E{\pgf@cal@easter@E+30}%
  \fi
  \ifnum\pgf@cal@easter@E=25
    \ifnum\pgf@cal@easter@G>11
      \pgfintset\pgf@cal@easter@E{\pgf@cal@easter@E+1}%
    \fi
  \else
    \ifnum\pgf@cal@easter@E=24
      \pgfintset\pgf@cal@easter@E{\pgf@cal@easter@E+1}%
    \fi
  \fi
  % E6. Find full moon
  \pgfintset\pgf@cal@easter@N{44-\pgf@cal@easter@E}%
  \ifnum\pgf@cal@easter@N<21
    \pgfintset\pgf@cal@easter@N{\pgf@cal@easter@N+30}%
  \fi
  % E7. Advance to Sunday
  \pgfintset\pgf@cal@easter@N{%
    \pgf@cal@easter@N+7-\pgfintmod{\pgf@cal@easter@D+\pgf@cal@easter@N}{7}
  }%
  % E8. Get month
  \ifnum\pgf@cal@easter@N>31
    \pgfintset\pgf@cal@easter@N{\pgf@cal@easter@N-31}%
    \pgfintset\pgf@cal@easter@M{4}% April
  \else
    \pgfintset\pgf@cal@easter@M{3}% March
  \fi
  \pgfcalendardatetojulian
    {\pgf@cal@easter@Y-\pgf@cal@easter@M-\pgf@cal@easter@N}%
    {#2}%
}

\pgfkeys{/pgf/calendar/Easter/.cd,.default=0,.code={%
  \pgfcalendareastersunday{\pgfcalendarifdateyear}{\pgf@cal@easter@julianday}%
  \ifnum\pgfcalendarifdatejulian=\pgfinteval{\pgf@cal@easter@julianday+#1}
    \expandafter\pgfcalendarmatchestrue
  \fi}%
}


\endinput