Latest news 2024-07-03: Ebook sale (1st – 31st July 2024): short story cybercrime fiction Unsocial Media free; short story cybercrime fiction Smile for the Camera free; short story noir crime fiction I’ve Heard the Mermaid Sing free; crime fiction novel The Private Enemy US$1.99; illustrated children’s story The Foolish Hedgehog US$0.99.

7.2 The pgfcalendar Package Utility Commands

The pgfcalendar package may be used independently of the pgf package, but if used without pgf (or tikz) the pgfkeys package also needs to be loaded:




In the command definitions below, ⟨date⟩ indicates a date specified using one of the following formats:

Where ⟨year⟩ is the year (for example, 2014 or \year for the current year); ⟨month⟩ is the month number (for example, 6 for June or \month for the current month) and ⟨day⟩ is the day number (for example, 21 for the twenty-first of the month or \day for the current day). The ⟨increment⟩ (in days) may be either a positive or negative number. If negative the leading + is still required. For example, 2014-6-last+-4 means four days before the last day of June.

The pgfcalendar provides the commands:


This converts a Gregorian date into the Julian day number and stores the result in ⟨register⟩, which must be a TeX register (not a LaTeX counter).


(Recall \newcount from §2.1.3 Arithmetic.)




\pgfcalendarjuliantodate{Julian day}{year cs}{month cs}{day cs}

This converts a Julian day number to an ISO-date and stores the resulting year, month and day-of-month numbers in the control sequences ⟨year cs⟩, ⟨month cs⟩ and ⟨day cs⟩.





\pgfcalendarjuliantoweekday{Julian day}{register}

This converts a Julian day number to a week day number, where 0 indicates Monday, 1 indicates Tuesday, etc. The result is stored in the TeX register specified by ⟨register⟩.





(which indicates Thursday).

\pgfcalendarifdate{date}{test}{true code}{false code}

This tests the given date and does ⟨true code⟩ if the test succeeds otherwise it does ⟨false code⟩. The ⟨test⟩ may be one of the following key words:

Always yields true.
True if the date is a Monday.
True if the date is a Tuesday.
True if the date is a Wednesday.
True if the date is a Thursday.
True if the date is a Friday.
True if the date is a Saturday.
True if the date is a Sunday.
True if the date occurs from Monday to Friday, inclusive.
True if the date is a Saturday or Sunday.
Or the ⟨test⟩ may be a comparison against a reference, which may be an ISO date in the form yyyy⟩-⟨mm⟩-⟨dd (for example, 2014-03-20) or with the year missing mm⟩-⟨dd (for example, 03-20):


2014-03-20 is in the
\pgfcalendarifdate{2014-03-20}{at most=06-last}
{first}% test true
{second}% test false
\space half of the year.


2014-03-20 is in the first half of the year.

What happens if your date isn't in the form yyyy⟩-⟨m⟩-⟨d? For example, it might be in the form m⟩/⟨d⟩/⟨yyyy. Recall from §2.1.1 Macro Definitions that the \def primitive can be used to define a macro that has a custom syntax. It's therefore possible to define a command that will parse this syntax and convert it:


(The \endparsemdydate token is just an end placeholder, not a command that needs defining.)


\parsemdydate 3/19/2014\endparsemdydate

expands to 2014-3-19. Remember that if the date is stored in a macro, for example:


then you first need to expand the macro before it can be parsed by \parsemdydate. (Recall \expandafter from §2.7.2 Iterating Over a Comma-Separated List.)


Example 38. Calculating Ages

Remember that the sample people.csv file and people SQL table included a date of birth field (labelled dob). This example computes the ages of each person in that data. This is done by first computing the Julian day number for today. Then for each person in the database, the Julian day number is computed for that person's date of birth. This number is subtracted from the Julian day number for today. This gives the total number of days since that person was born. This number is then divided by 356 to give an approximate age in years. (Recall TeX's integer arithmetic described in §2.1.3 Arithmetic.)






% Compute the Julian day number for today:

Ages as of \number\year-\number\month-\number\day\␣are
listed in Table~\ref{tab:ages}.

\bfseries Name & \bfseries Age%
    \\\Forenames\␣\Surname &
    % Compute the Julian day number for the date of birth
    % Compute \age = (\juliantoday - \julianday)/365
    \advance\age by -\julianday
    \divide\age by 365


This produces Table 7.1 and the text:

Ages as of 2014-9-3 are listed in Table 7.1.

Table 7.1: Ages
Name Age
Polly Parrot 44
Mabel Canary 47
Zöe Zebra 26
José Arara 24
Dickie Duck 62
Fred Canary 48
End of Image.

You can download or view this example. Remember that if your dates are in a different numerical format, for example, ⟨m⟩/⟨d⟩/⟨yyyy⟩, you need to convert them as described above. For example, replace



where \parsemdydate is as described above.

This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs