1

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}
2
  • Both methods work for me !!! Sep 28, 2021 at 18:38
  • @HafidBoukhoulda, it looks like it works, but it should compute every day between 2021-1-1 and 2021-1-10, not only the first day of that period.
    – e_moro
    Sep 28, 2021 at 20:28

1 Answer 1

0

I don't know if this ok

\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
if (between =2021-1-1 and 2021-1-10) [red];
\end{tikzpicture}
        
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.