将 (n) 个工作日添加到特定日期

将 (n) 个工作日添加到特定日期

我的g-brief遗嘱中包含类似“我已注意到您答复的截止日期为十个工作日,直到……”的内容。

是否有一个软件包或方法可以通过n编程将工作日(即周一至周五,不要让假期等使事情变得过于复杂)添加到今天的日期?

我找到了一个近似解datenumadvdate包中:

\setdatetoday
\addtocounter{datenumber}{10}
\setdatebynumber{\thedatenumber}

但这“仅”*添加了天数,而不考虑一天是工作日还是休息日(即周末)。

*在谦卑中“我自己不可能做任何类似的事情(所以我很感激),但它并不完全符合我的需要,可能需要进行调整”-方式。

答案1

以下是使用该pgfcalendar包的解决方案(pgf捆。)

\documentclass{article}

\usepackage{pgfkeys,pgfcalendar}

\newcount\julianday
\newcount\daycount
\newcount\weekday

\newcommand*{\adddays}[2]{%
  \pgfcalendardatetojulian{#1}{\julianday}%
  \daycount=#2\relax
  \loop
    \advance\julianday by 1\relax
    \pgfcalendarjuliantoweekday{\julianday}{\weekday}%
    \ifnum\weekday<5\relax
      % It's a weekday (Mon-Fri)
      \advance\daycount by -1\relax
    \fi
  \ifnum\daycount > 0
  \repeat
  \pgfcalendarjuliantodate{\julianday}{\thisyear}{\thismonth}{\thisday}%
  \thisyear-\thismonth-\thisday
}

\begin{document}

10 working days from
\the\year-\the\month-\the\day\ (today):
\adddays{\year-\month-\day}{10}

\end{document}

得出的结果为:

2014-4-16(今日)起10个工作日:2014-04-30

您可以调整此设置以将节假日考虑进去:

\documentclass{article}

\usepackage{pgfkeys,pgfcalendar}
\usepackage{etoolbox}

\newcount\julianday
\newcount\daycount
\newcount\weekday

\newcommand*{\holiday}[2]{%
  \pgfcalendardatetojulian{#1}{\julianday}%
  \csdef{holiday-\number\julianday}{#2}%
}

\newcommand*{\adddays}[2]{%
  \pgfcalendardatetojulian{#1}{\julianday}%
  \daycount=#2\relax
  \loop
    \advance\julianday by 1\relax
    \pgfcalendarjuliantoweekday{\julianday}{\weekday}%
    \ifnum\weekday<5\relax
      % It's a weekday (Mon-Fri)
      \ifcsdef{holiday-\number\julianday}%
      {% It's a holiday
      }%
      {% Not a holiday
        \advance\daycount by -1\relax
      }%
    \fi
  \ifnum\daycount > 0
  \repeat
  \pgfcalendarjuliantodate{\julianday}{\thisyear}{\thismonth}{\thisday}%
  \thisyear-\thismonth-\thisday
}

\holiday{2014-04-21}{Easter Monday}
\holiday{2014-05-05}{Early May Bank Holiday}

\begin{document}

10 working days from
\the\year-\the\month-\the\day\ (today):
\adddays{\year-\month-\day}{10}

\end{document}

得出的结果为:

自 2014-4-16(今日)起 10 个工作日:2014-05-01

相关内容