% !TeX spellcheck = en_US
% !TeX root = tikz-ext-manual.tex
% Copyright 2022 by Qrrbrbirlbel
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%

\section{Calendar: Weeknumbers and more conditionals}
\label{sec:calendar}
\begin{package}{calendar-ext}
  This package adds week numbers and more conditionals to the \pgfname\space package |pgfcalendar|.
  (Despite the code example above, this package is not set up to work with Con\TeX t.)
  \inspiration{WeekNum-Q,CalCond-Q,CalFullWeek-Q}{WeekNum-A,CalCond-A,CalFullWeek-A}
\end{package}

%This package extends the |pgfcalendar| package.

\begin{multicols}{2}

\subsection{Extensions}

The following tests are added.
\begin{itemize}
\itemcalendaroption{Jan} This test is passed by all dates that are in the month of January.
\itemcalendaroption{Feb} as above.
\itemcalendaroption{Mar} as above.
\itemcalendaroption{Apr} as above.
\itemcalendaroption{May} as above.
\itemcalendaroption{Jun} as above.
\itemcalendaroption{Jul} as above.
\itemcalendaroption{Aug} as above.
\itemcalendaroption{Sep} as above.
\itemcalendaroption{Oct} as above.
\itemcalendaroption{Nov} as above.
\itemcalendaroption{Dec} as above.
\itemcalendaroption{leap year}\opt{|=|\meta{year}}
    This test checks whether the given year is a leap year. If
    \meta{year} is omitted, it checks the year of the current date.
\itemcalendaroption{and}|=|\marg{tests}
    This test passes when all \meta{tests} pass.
\itemcalendaroption{not}|=|\marg{tests}
    This test passes when \meta{tests} do not pass.
\itemcalendaroption{week of month}|=|\meta{num}
    This test passes when the date is in \meta{num}th week of the month.
    The first week of the month start at day~1 and ends with day~7.
\itemcalendaroption{week of month'}|=|\meta{num}
    As above but counts from the last day of the month.
    For a month with 31~days, this means the ``1st'' week starts at day~25 and ends with day~31.
\itemcalendaroption{calendar week of month}|=|\meta{num}
    This test passes when the date is in \meta{num}th calendar week of the month.
    The first week starts at the first day of the month and ends at the next Sunday.
\itemcalendaroption{calendar week of month'}|=|\meta{num}
    As above but counts from the last day of the month.
\begin{codeexample}[width=5cm,preamble=\usetikzlibrary{ext.calendar-plus}]
\tikz
  \calendar[
    dates=2022-10-01 to 2022-10-31,
    week list]
    if (week of month=2) [red]
    if (calendar week of month'=2) [blue];
\end{codeexample}
\itemcalendaroption{yesterday}|=|\marg{tests}
    This test passes when the previous day passes \meta{tests}.
\itemcalendaroption{week}|=|\meta{num}
    This test passes when the current week of the year equals \marg{num}.
\end{itemize}
The shorthands for |d-| and |m-| are slightly changed so that they are
expandable. This makes it possible to use these shorthands inside of \pgfname math.
The shorthands for the week (see section~\ref{calendar:weeknumbering})
are added. These are
\begin{itemize}
\item |n-| (shortest numerical representation),
\item |n=| (shortest but added horizontal space) and
\item |n0| (leading zero when below 10).
\end{itemize}

\subsection{Week numbering (ISO~8601)}
\label{calendar:weeknumbering}
\begin{command}{\pgfcalendarjulianyeartoweek\marg{Julian day}\marg{year}\marg{week counter}}
  This command calculates the week for the \meta{Julian day} of \meta{year}.
  The \meta{week counter} must be a \TeX\space counter.

  The calculation follows the rule of ISO~8601 where the first week has that
  year's first Thursday in it.
\end{command}

Inside of |\pgfcalendar|\indexCommandO\pgfcalendar the command |\pgfcalendarcurrentweek| will be available.
\begin{command}{\pgfcalendarcurrentweek}
  This command returns the current week number (always two digits -- use shorthand |n.|
  to strip the leading zero).
\end{command}

Inside of |\ifdate|\indexCommandO\ifdate the command |\pgfcalendarifdateweek| will be available.
\begin{command}{\pgfcalendarifdateweek}
  This command returns the week number (always two digits).
\end{command}
\end{multicols}