0

I'm trying to define a macro that will determine two dates (in weeks of 7 days), calculated from a given date (defined by \setmovedate below. For brevity the code below uses only #2 from \movetasks:

\documentclass{article}

\usepackage{tikz}
\usepackage[papersize={5.5in,8.5in}]{geometry}
\usepackage{xparse}
\usepackage{pgfcalendar}
\usetikzlibrary{fpu}

\newcounter{testit}

\makeatletter
\NewDocumentCommand{\setmovedate}{m}{%
    \pgfcalendardatetojulian{#1}{\@tempcnta}
}

\NewDocumentCommand{\movetasks}{mm}{%
    %% Commenting-out the \pgfkeys lines gives 'dimension too large' error
    \pgfkeys{/pgf/fpu=true}
    \pgfkeys{/pgf/fpu/output format=fixed}% Turn on the fp engine
    \pgfmathsetmacro{\fromdate}{add(\the\@tempcnta,-7*#2)}\fromdate\ trailing 0's from fpu\\
    \pgfcalendarjuliantodate{\fromdate}{\moveyear}{\movemonth}{\moveday} Ejects 0's from fpu\\
    \moveyear-\movemonth-\moveday\ is correct
    \pgfkeys{/pgf/fpu=false}
}
\makeatother

\begin{document}

\setmovedate{2019-10-15}

\movetasks{2}{3}

\end{document}

fpu and pgfcalendar

I understand the trailing 0's in \fromdate (the output from fpu) but I'm puzzled by the fact that they are discarded by \pgfcalendarjuliantodate and subsequently printed. Clearly, a simple integer is required, but my attempts to do this have, thus far, proved futile. I'm probably missing something very basic which is annoying.

5

Convert the result to an integer (perhaps you need to round first, to get the nearest integer):

\documentclass{article}

\usepackage{tikz}
\usepackage[papersize={5.5in,8.5in}]{geometry}
\usepackage{xparse}
\usepackage{pgfcalendar}
\usetikzlibrary{fpu}

\newcounter{testit}

\makeatletter

\NewDocumentCommand{\setmovedate}{m}{%
    \pgfcalendardatetojulian{#1}{\@tempcnta}%
}

\NewDocumentCommand{\movetasks}{mm}{%
    %% Commenting-out the \pgfkeys lines gives 'dimension too large' error
    \pgfkeys{/pgf/fpu=true}
    \pgfkeys{/pgf/fpu/output format=float}% Turn on the fp engine
    \pgfmathsetmacro{\fromdate}{int(add(\the\@tempcnta,-7*#2))}%
    \pgfmathfloattoint{\fromdate}%<---
    \pgfcalendarjuliantodate{\pgfmathresult}{\moveyear}{\movemonth}{\moveday}%
    \moveyear-\movemonth-\moveday\ is correct
    \pgfkeys{/pgf/fpu=false}
}
\makeatother

\begin{document}

\setmovedate{2019-10-15}

\movetasks{2}{3}

\end{document}

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.