我正在尝试定义一个宏,它将确定两个日期(以 7 天为一周),根据给定日期计算(定义\setmovedate
如下。为简洁起见,下面的代码仅使用#2
来自\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}
\fromdate
我理解( 的输出)中的尾随 0,fpu
但我对它们被丢弃并随后打印的事实感到困惑\pgfcalendarjuliantodate
。显然,需要一个简单的整数,但到目前为止,我这样做的尝试都是徒劳的。我可能错过了一些非常基本的东西,这很烦人。
答案1
将结果转换为整数(可能需要先四舍五入,以获得最接近的整数):
\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}