I have defined an array of ISO-dates. Next, I need to convert the dates to Julian days.
As the following code shows, this is possible using the \foreach
statement + \pgfcalendardatetojulian
(method 1).
However, I would love to get it by invoking the first and last element of the array, in order to easily compute long periods of time (method 2). Unfortunately, it does not work.
How can I archive this?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calendar}
\pgfkeys{/pgf/calendar/method one/.code={
\newcount\n
\foreach \d in \holiday{
\pgfcalendardatetojulian{\d}{\n}
\ifnum \pgfcalendarcurrentjulian = \n
\global\pgfcalendarmatchestrue
\fi
}}}
\pgfkeys{/pgf/calendar/method two/.code={
\newcount\first \pgfcalendardatetojulian{\holiday[0]}{\first} \advance \first -1
\newcount\last \pgfcalendardatetojulian{\holiday[1]}{\last} \advance \last +1
\ifnum \pgfcalendarcurrentjulian > \first
\ifnum \pgfcalendarcurrentjulian < \last
\global\pgfcalendarmatchestrue
\fi\fi
}}
\begin{document}
\def\holiday{2021-1-1, 2021-1-10}
\begin{tikzpicture}
\calendar[dates=2021-01-01 to 2021-01-last, style = week list]
% if (method one) [red]; % this works
if (method two) [red]; % this doesn't
\end{tikzpicture}
\end{document}