用于计算下一个工作日的包或宏?

用于计算下一个工作日的包或宏?

现有包中是否有一个包或宏可以计算下一个工作日或n从今天算起的第 1 个工作日(考虑到节假日列表)还是任意一个日期?(如果没有,我想我最终会编写一些代码并发布在 CTAN 上)

答案1

我不知道有哪个软件包可以做到这一切,但是日历包非常强大。以下 MWE 处理下一个工作日(假设没有整整一周的假期)

\documentclass{article}
\usepackage{pgfkeys}
\usepackage{pgfcalendar}
\usepackage{etoolbox}
\newif\ifholiday
\def\holidays{2016-09-12, 2016-09-16, 2016-09-20, 2016-09-21, 2016-09-23, 2016-09-26}
\newcount\nextjulianday
\newcount\julianholiday
\newcommand{\isholiday}[2]{%
    \holidayfalse%
    \def\do##1{%
        \pgfcalendardatetojulian{##1}{\julianholiday}%
        \ifnumequal{\the\julianholiday}{\the\nextjulianday}{\holidaytrue}{}%
    }%
    \docsvlist{#1}%
}
\newcommand{\nextbusinessday}[1]{\begingroup%
    \pgfcalendardatetojulian{#1}{\nextjulianday}%
    \advance\nextjulianday 1\relax%
    \loop
        \expandafter\isholiday\expandafter{\holidays}{\the\nextjulianday}%
        \ifholiday%
            \advance\nextjulianday 1\relax%
            \repeat%
    \pgfcalendarjuliantodate{\the\nextjulianday}{\theyear}{\themonth}{\theday}%
    \pgfcalendarifdate{\theyear-\themonth-\theday}{Saturday}{%
        \advance\nextjulianday 1\relax%
        \pgfcalendarjuliantodate{\the\nextjulianday}{\theyear}{\themonth}{\theday}%
    }{}%
    \pgfcalendarifdate{\theyear-\themonth-\theday}{Sunday}{%
        \advance\nextjulianday 1\relax%
        \pgfcalendarjuliantodate{\the\nextjulianday}{\theyear}{\themonth}{\theday}%
    }{}%
    \loop
        \expandafter\isholiday\expandafter{\holidays}{\the\nextjulianday}%
        \ifholiday%
            \advance\nextjulianday 1\relax%
            \repeat%
    \pgfcalendarjuliantodate{\the\nextjulianday}{\theyear}{\themonth}{\theday}%
    \theyear-\themonth-\theday
\endgroup}
\begin{document}
Holidays:

\def\do#1{#1\par}
\expandafter\docsvlist\expandafter{\holidays}

\def\do#1{2016-09-#1 -- \nextbusinessday{2016-09-#1}\par}
\docsvlist{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30}
\end{document}

应该可以扩展该方法来处理第 n 个工作日。

相关内容