%%
%% This is file `datetime2-calc.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% datetime2.dtx  (with options: `datetime2-calc.sty,package')
%% 
%%  datetime2.dtx
%%  Copyright 2021 Nicola Talbot
%% 
%%  This work may be distributed and/or modified under the
%%  conditions of the LaTeX Project Public License, either version 1.3
%%  of this license or (at your option) any later version.
%%  The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%%  and version 1.3 or later is part of all distributions of LaTeX
%%  version 2005/12/01 or later.
%% 
%%  This work has the LPPL maintenance status `maintained'.
%% 
%%  The Current Maintainer of this work is Nicola Talbot.
%% 
%%  This work consists of the files datetime2.dtx and datetime2.ins and the derived files datetime2.sty, datetime2-calc.sty.
%% 
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{datetime2-calc}[2021/03/21 v1.5.7 (NLCT)]
\RequirePackage{pgfkeys}
\RequirePackage{pgfcalendar}
\newcount\@dtm@julianday
\def\@dtm@parsedate#1-#2-#3\@dtm@endparsedate{%
  \pgfcalendardatetojulian{#1-#2-#3}{\@dtm@julianday}%
  \pgfcalendarjuliantodate{\@dtm@julianday}{\@dtm@year}{\@dtm@month}{\@dtm@day}%
  \pgfcalendarjuliantoweekday{\@dtm@julianday}{\count@}%
  \edef\@dtm@dow{\number\count@}%
}
\pgfcalendardatetojulian
 {\@dtm@currentyear-\@dtm@currentmonth-\@dtm@currentday}%
 {\@dtm@julianday}%
\pgfcalendarjuliantoweekday{\@dtm@julianday}{\count@}%
\edef\@dtm@currentdow{\number\count@}%
\newrobustcmd*{\DTMsavejulianday}[2]{%
  \pgfcalendarjuliantodate{#2}{\@dtm@year}{\@dtm@month}{\@dtm@day}%
  \pgfcalendarjuliantoweekday{#2}{\count@}%
  \csedef{@dtm@#1@dow}{\number\count@}%
  \cslet{@dtm@#1@year}{\@dtm@year}%
  \cslet{@dtm@#1@month}{\@dtm@month}%
  \cslet{@dtm@#1@day}{\@dtm@day}%
  \ifcsundef{@dtm@#1@hour}{\csdef{@dtm@#1@hour}{0}}{}%
  \ifcsundef{@dtm@#1@minute}{\csdef{@dtm@#1@minute}{0}}{}%
  \ifcsundef{@dtm@#1@second}{\csdef{@dtm@#1@second}{0}}{}%
  \ifcsundef{@dtm@#1@TZhour}{\csdef{@dtm@#1@TZhour}{0}}{}%
  \ifcsundef{@dtm@#1@TZminute}{\csdef{@dtm@#1@TZminute}{0}}{}%
}
\newrobustcmd*{\DTMsaveddatetojulianday}[2]{%
  \ifcsundef{@dtm@#1@year}%
  {%
     \PackageError{datetime2-calc}{Unknown date `#1'}{}%
  }%
  {%
    \pgfcalendardatetojulian
     {\csname @dtm@#1@year\endcsname
     -\csname @dtm@#1@month\endcsname
     -\csname @dtm@#1@day\endcsname}%
     {#2}%
  }%
}
\newrobustcmd*{\DTMsaveddateoffsettojulianday}[3]{%
  \ifcsundef{@dtm@#1@year}%
  {%
     \PackageError{datetime2-calc}{Unknown date `#1'}{}%
  }%
  {%
    \pgfcalendardatetojulian
     {\csname @dtm@#1@year\endcsname
     -\csname @dtm@#1@month\endcsname
     -\csname @dtm@#1@day\endcsname
     +#2}%
     {#3}%
  }%
}
\newrobustcmd*{\DTMifdate}[4]{%
  \ifcsundef{@dtm@#1@year}%
  {%
     \PackageError{datetime2-calc}{Unknown date `#1'}{}%
  }%
  {%
    \pgfcalendarifdate
     {\csname @dtm@#1@year\endcsname
     -\csname @dtm@#1@month\endcsname
     -\csname @dtm@#1@day\endcsname}%
     {#2}{#3}{#4}%
  }%
}
\newrobustcmd*{\DTMsaveddatediff}[3]{%
  \ifcsundef{@dtm@#1@year}%
  {%
     \PackageError{datetime2-calc}{Unknown date `#1'}{}%
  }%
  {%
     \ifcsundef{@dtm@#2@year}%
     {%
        \PackageError{datetime2-calc}{Unknown date `#1'}{}%
     }%
     {%
       \pgfcalendardatetojulian
        {\csname @dtm@#1@year\endcsname
        -\csname @dtm@#1@month\endcsname
        -\csname @dtm@#1@day\endcsname}%
        {#3}%
       \pgfcalendardatetojulian
        {\csname @dtm@#2@year\endcsname
        -\csname @dtm@#2@month\endcsname
        -\csname @dtm@#2@day\endcsname}%
        {\@dtm@julianday}%
       \advance#3 by -\@dtm@julianday\relax
    }%
  }%
}
\newrobustcmd*{\DTMtozulu}[2]{%
  \ifcsundef{@dtm@#1@year}%
  {%
     \PackageError{datetime2-calc}{Unknown date `#1'}{}%
  }%
  {%
    \DTMsaveaszulutime{#2}%
    {\DTMfetchyear{#1}}%
    {\DTMfetchmonth{#1}}%
    {\DTMfetchday{#1}}%
    {\DTMfetchhour{#1}}%
    {\DTMfetchminute{#1}}%
    {\DTMfetchsecond{#1}}%
    {\DTMfetchTZhour{#1}}%
    {\DTMfetchTZminute{#1}}%
  }%
}
\newrobustcmd*{\DTMsaveaszulutime}[9]{%
  \edef\@dtm@year{\number#2}%
  \edef\@dtm@month{\number#3}%
  \edef\@dtm@day{\number#4}%
  \edef\@dtm@hour{\number#5}%
  \edef\@dtm@minute{\number#6}%
  \edef\@dtm@second{\number#7}%
  \edef\@dtm@TZhour{\number#8}%
  \edef\@dtm@TZminute{\number#9}%
  \pgfcalendardatetojulian{\@dtm@year-\@dtm@month-\@dtm@day}{\@dtm@julianday}%
  \ifnum\@dtm@TZminute=0\relax
  \else
    \count@=\@dtm@minute\relax
    \ifnum\@dtm@TZhour<0\relax
      \advance\count@ by \@dtm@TZminute\relax
    \else
      \advance\count@ by -\@dtm@TZminute\relax
    \fi
    \edef\@dtm@minute{\number\count@}%
    \ifnum\count@<0\relax
      \advance\count@ by 60\relax
      \edef\@dtm@minute{\number\count@}%
      \ifnum\@dtm@hour=0\relax
       \def\@dtm@hour{23}%
       \advance\@dtm@julianday by -1\relax
      \else
        \count@ = \@dtm@hour\relax
        \advance\count@ by -1\relax
        \edef\@dtm@hour{\number\count@}%
      \fi
    \else
      \ifnum\count@>59\relax
        \advance\count@ by -60\relax
        \edef\@dtm@minute{\number\count@}%
        \count@ = \@dtm@hour\relax
        \advance\count@ by 1\relax
        \edef\@dtm@hour{\number\count@}%
        \ifnum\@dtm@hour=24\relax
          \def\@dtm@hour{00}%
          \advance\@dtm@julianday by 1\relax
        \fi
      \fi
    \fi
  \fi
  \ifnum\@dtm@TZhour=0\relax
  \else
    \count@=\@dtm@hour\relax
    \advance\count@ by -\@dtm@TZhour\relax
    \ifnum\count@<0\relax
      \advance\count@ by 24\relax
      \edef\@dtm@hour{\number\count@}%
      \advance\@dtm@julianday by -1\relax
    \else
      \ifnum\count@>23\relax
      \advance\count@ by -24\relax
      \edef\@dtm@hour{\number\count@}%
      \advance\@dtm@julianday by 1\relax
      \else
        \edef\@dtm@hour{\number\count@}%
      \fi
    \fi
  \fi
  \pgfcalendarjuliantodate{\@dtm@julianday}{\@dtm@year}{\@dtm@month}{\@dtm@day}%
  \pgfcalendarjuliantoweekday{\@dtm@julianday}{\count@}%
  \csedef{@dtm@#1@dow}{\number\count@}%
  \cslet{@dtm@#1@year}{\@dtm@year}%
  \cslet{@dtm@#1@month}{\@dtm@month}%
  \cslet{@dtm@#1@day}{\@dtm@day}%
  \cslet{@dtm@#1@hour}{\@dtm@hour}%
  \cslet{@dtm@#1@minute}{\@dtm@minute}%
  \cslet{@dtm@#1@second}{\@dtm@second}%
  \csdef{@dtm@#1@TZhour}{0}%
  \csdef{@dtm@#1@TZminute}{0}%
}
\newcommand*{\dtm@ifdianameexists}[3]{%
 \IfTrackedDialect{\languagename}%
 {%
   \ifcsdef{DTM\TrackedLanguageFromDialect{\languagename}#1}%
   {#2}%
   {#3}%
 }%
 {#3}%
}
\newrobustcmd{\DTMmonthname}[1]{%
  \ifcsdef{DTM\languagename monthname}%
  {%
    \csuse{DTM\languagename monthname}{#1}%
  }%
  {%
    \dtm@ifdianameexists{monthname}%
    {%
       \csuse{DTM\TrackedLanguageFromDialect{\languagename}monthname}{#1}%
    }%
    {%
      \dtmnamewarning{\DTMmonthname}%
      \pgfcalendarmonthname{#1}%
    }%
  }%
}
\newrobustcmd{\DTMMonthname}[1]{%
  \ifcsdef{DTM\languagename Monthname}%
  {%
    \csuse{DTM\languagename Monthname}{#1}%
  }%
  {%
    \dtm@ifdianameexists{Monthname}%
    {%
       \csuse{DTM\TrackedLanguageFromDialect{\languagename}Monthname}{#1}%
    }%
    {%
      \ifcsdef{DTM\languagename monthname}%
      {%
        \csuse{DTM\languagename monthname}{#1}%
      }%
      {%
        \dtm@ifdianameexists{monthname}%
        {%
          \csuse{DTM\TrackedLanguageFromDialect{\languagename}monthname}{#1}%
        }%
        {%
          \dtmnamewarning{\DTMMonthname}%
          \ifdef\emakefirstuc
          {%
           \emakefirstuc{\pgfcalendarmonthname{#1}}%
          }%
          {%
            \protected@edef\dtm@tmp@monthname{\pgfcalendarmonthname{#1}}%
            \expandafter\MakeUppercase\dtm@tmp@monthname
          }%
        }%
      }%
    }%
  }%
}
\newrobustcmd{\DTMshortmonthname}[1]{%
  \ifcsdef{DTM\languagename shortmonthname}%
  {%
    \csuse{DTM\languagename shortmonthname}{#1}%
  }%
  {%
    \dtm@ifdianameexists{shortmonthname}%
    {%
       \csuse{DTM\TrackedLanguageFromDialect{\languagename}shortmonthname}{#1}%
    }%
    {%
      \dtmnamewarning{\DTMshortmonthname}%
      \pgfcalendarmonthshortname{#1}%
    }%
  }%
}
\newrobustcmd{\DTMshortMonthname}[1]{%
  \ifcsdef{DTM\languagename shortMonthname}%
  {%
    \csuse{DTM\languagename shortMonthname}{#1}%
  }%
  {%
    \dtm@ifdianameexists{shortMonthname}%
    {%
       \csuse{DTM\TrackedLanguageFromDialect{\languagename}shortMonthname}{#1}%
    }%
    {%
      \ifcsdef{DTM\languagename shortmonthname}%
      {%
        \csuse{DTM\languagename shortmonthname}{#1}%
      }%
      {%
        \dtm@ifdianameexists{shortmonthname}%
        {%
           \csuse{DTM\TrackedLanguageFromDialect{\languagename}shortmonthname}%
           {#1}%
        }%
        {%
          \dtmnamewarning{\DTMshortMonthname}%
          \ifdef\emakefirstuc
          {%
           \emakefirstuc{\pgfcalendarmonthshortname{#1}}%
          }%
          {%
            \protected@edef\dtm@tmp@monthname{\pgfcalendarmonthshortname{#1}}%
            \expandafter\MakeUppercase\dtm@tmp@monthname
          }%
        }%
      }%
    }%
  }%
}
\newrobustcmd*{\DTMcomputedayofweekindex}[2]{%
  \pgfcalendardatetojulian{#1}{\@dtm@julianday}%
  \pgfcalendarjuliantoweekday{\@dtm@julianday}{\count@}%
  \edef#2{\number\count@}%
}
\def\dtmMondayIndex{0}
\def\dtmTuesdayIndex{1}
\def\dtmWednesdayIndex{2}
\def\dtmThursdayIndex{3}
\def\dtmFridayIndex{4}
\def\dtmSaturdayIndex{5}
\def\dtmSundayIndex{6}
\newrobustcmd{\DTMweekdayname}[1]{%
  \ifcsdef{DTM\languagename weekdayname}%
  {%
    \csuse{DTM\languagename weekdayname}{#1}%
  }%
  {%
    \dtm@ifdianameexists{weekdayname}%
    {%
       \csuse{DTM\TrackedLanguageFromDialect{\languagename}weekdayname}{#1}%
    }%
    {%
      \dtmnamewarning{\DTMweekdayname}%
      \pgfcalendarweekdayname{#1}%
    }%
  }%
}
\newrobustcmd{\DTMWeekdayname}[1]{%
  \ifcsdef{DTM\languagename Weekdayname}%
  {%
    \csuse{DTM\languagename Weekdayname}{#1}%
  }%
  {%
    \dtm@ifdianameexists{Weekdayname}%
    {%
       \csuse{DTM\TrackedLanguageFromDialect{\languagename}Weekdayname}{#1}%
    }%
    {%
      \ifcsdef{DTM\languagename weekdayname}%
      {%
        \csuse{DTM\languagename weekdayname}{#1}%
      }%
      {%
        \dtm@ifdianameexists{weekdayname}%
        {%
           \csuse{DTM\TrackedLanguageFromDialect{\languagename}weekdayname}{#1}%
        }%
        {%
          \dtmnamewarning{\DTMWeekdayname}%
          \ifdef\emakefirstuc
          {%
           \emakefirstuc{\pgfcalendarweekdayname{#1}}%
          }%
          {%
            \protected@edef\dtm@tmp@weekdayname{\pgfcalendarweekdayname{#1}}%
            \expandafter\MakeUppercase\dtm@tmp@weekdayname
          }%
        }%
      }%
    }%
  }%
}
\newrobustcmd{\DTMshortweekdayname}[1]{%
  \ifcsdef{DTM\languagename shortweekdayname}%
  {%
    \csuse{DTM\languagename shortweekdayname}{#1}%
  }%
  {%
    \dtm@ifdianameexists{shortweekdayname}%
    {%
       \csuse{DTM\TrackedLanguageFromDialect{\languagename}shortweekdayname}{#1}%
    }%
    {%
      \dtmnamewarning{\DTMshortweekdayname}%
      \pgfcalendarweekdayshortname{#1}%
    }%
  }%
}
\newrobustcmd{\DTMshortWeekdayname}[1]{%
  \ifcsdef{DTM\languagename shortWeekdayname}%
  {%
    \csuse{DTM\languagename shortWeekdayname}{#1}%
  }%
  {%
    \dtm@ifdianameexists{shortWeekdayname}%
    {%
       \csuse{DTM\TrackedLanguageFromDialect{\languagename}shortWeekdayname}{#1}%
    }%
    {%
      \ifcsdef{DTM\languagename shortweekdayname}%
      {%
        \csuse{DTM\languagename shortweekdayname}{#1}%
      }%
      {%
        \dtm@ifdianameexists{shortweekdayname}%
        {%
           \csuse{DTM\TrackedLanguageFromDialect{\languagename}shortweekdayname}%
           {#1}%
        }%
        {%
          \dtmnamewarning{\DTMshortWeekdayname}%
          \ifdef\emakefirstuc
          {%
           \emakefirstuc{\pgfcalendarweekdayshortname{#1}}%
          }%
          {%
            \protected@edef\dtm@tmp@weekdayname{%
              \pgfcalendarweekdayshortname{#1}}%
            \expandafter\MakeUppercase\dtm@tmp@weekdayname
          }%
        }%
      }%
    }%
  }%
}
\newrobustcmd{\DTMordinal}[1]{%
  \ifcsdef{DTM\languagename ordinal}%
  {%
    \csuse{DTM\languagename ordinal}{#1}%
  }%
  {%
    \dtm@ifdianameexists{ordinal}%
    {%
       \csuse{DTM\TrackedLanguageFromDialect{\languagename}ordinal}{#1}%
    }%
    {%
      \number#1
    }%
  }%
}
\newcommand*{\dtmnamewarning}[1]{%
 \if@dtm@warn
  \PackageWarning{datetime2-calc}%
  {Can't find underlying language macro for \MessageBreak
   \string#1\space(language: \languagename); \MessageBreak
    using pgfcalendar macro instead}%
 \fi
}
\endinput
%%
%% End of file `datetime2-calc.sty'.
