我想比较两个日期,比如今天的日期和截止日期。我将截止日期信息(以数字字符串的形式)存储在宏\dueday
、\duemonth
和 中。我使用来自包的\duemonth
以下内容:etoolbox
\newcommand{\dueday}{6}
\newcommand{\duemonth}{5} % May
\newcommand{\dueyear}{2012}
\ifboolexpr{
(test {\ifnumcomp{\dueyear}{>}{\year}})
or (test {\ifnumcomp{\dueyear}{=}{\year}} and test {\ifnumcomp{\duemonth}{>}{\month}})
or (test {\ifnumcomp{\dueyear}{=}{\year}} and test {\ifnumcomp{\duemonth}{=}{\month}} and test {\ifnumcomp{\dueday}{>}{\day}})
}
{Not due yet}
{Due immediately}
它确实有效,但我正在寻找一种基于 TeX 的解决方案,也许可以更有效地完成此操作而不必使用etoolbox
。
答案1
这可以通过一系列纯数字(\ifnum
)测试来实现,其中布尔逻辑由仅使用 0/1 的“外部”测试表示:
\def\dueday{6}
\def\duemonth{5} % May
\def\dueyear{2012}
\def\notdue{Not due yet}
\def\duenow{Due immediately}
\ifnum
\ifnum\dueyear>\year
0 %
\else
\ifnum\duemonth>\month
0 %
\else
\ifnum\dueday>\day
0 %
\else
1 %
\fi
\fi
\fi
> 0 %
\expandafter\duenow
\else
\expandafter\notdue
\fi
\bye