summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/advdate/advdate.sty
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/advdate/advdate.sty
Initial commit
Diffstat (limited to 'macros/latex/contrib/advdate/advdate.sty')
-rw-r--r--macros/latex/contrib/advdate/advdate.sty151
1 files changed, 151 insertions, 0 deletions
diff --git a/macros/latex/contrib/advdate/advdate.sty b/macros/latex/contrib/advdate/advdate.sty
new file mode 100644
index 0000000000..e7e362181b
--- /dev/null
+++ b/macros/latex/contrib/advdate/advdate.sty
@@ -0,0 +1,151 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Advance Date Package for LaTeX2e %%
+%% (C) Z. Wagner -- Ice Bear Soft, 20 Oct 1996, <wagner@mbox.cesnet.cz> %%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Copyright 1996 Zdenek Wagner %%
+%% %%
+%% 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 Zdenek Wagner. %%
+%% %%
+%% This work consists of all files listed in manifest.txt. %%
+%% %%
+%% This licence information was added 2010/11/22 by %%
+%% Clea F. Rees with the permission of Zdenek Wagner. %%
+%% %%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% This package contains macros which can add specified number of days %%
+%% to the current date (as specified in \today) and print it. Some other %%
+%% macros are also provided. It is intended for use e.g. in invoices %%
+%% payable within 14 days from today etc. %%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Macros with one default argument [in square brackets] %%
+%% \AdvanceDate Default: [1] %%
+%% Advances date the specified number of days and sets the result %%
+%% to \today %%
+%% \DayAfter Default: [1] %%
+%% Advances date by call to \AdvanceDate, prints \today and restores %%
+%% the oroginal value of \today %%
+%% \SaveDate Default: [\s@v@dT@d@y] %%
+%% Saves \today into the specified macro %%
+%% \SetDate Default: [\s@v@dT@d@y] %%
+%% Sets the date stored in \today. The argument must be in form: %%
+%% [dd/mm/yyyy] and may be present in a macro because the argument %%
+%% is always expanded before use. The value saved by \SaveDate can %%
+%% be used here. %%
+%% %%
+%% Macros with one mandatory argument %%
+%% \ThisDay sets \day %%
+%% \ThisMonth sets \month %%
+%% \ThisYear sets \year %%
+%% \AdvMonth advances \month and fixes it %%
+%% \AdvYear advances \year %%
+%% %%
+%% Macros without arguments %%
+%% \FixMonth fixes \today so that 0 < \month < 13 %%
+%% \FixDate fixes \today so that it is valid %%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{advdate}[1996/10/20 Advance Date Package]
+
+% KH code
+
+\newcount\r@k \newcount\un@r
+\newcount\m@l \m@l31
+\newcount\m@s \m@s30
+\newcount\M@s
+
+\newcommand\is@LeapYear[1][\year]{\r@k#1\un@r\r@k
+ \divide\r@k4\multiply\r@k4\advance\r@k-\un@r
+ \ifnum\r@k=0%
+ \divide\un@r100\r@k\un@r\multiply\un@r100\advance\un@r-#1%
+ \ifnum\un@r=0%
+ \un@r\r@k \divide\un@r4\multiply\un@r4\advance\un@r-\r@k
+ \un@r\ifnum\un@r=0 29\else 28\fi
+ \else
+ \un@r 29%
+ \fi
+ \else
+ \un@r 28%
+ \fi
+ \r@k 337\advance\r@k\un@r}
+
+\newcommand\m@sic{\ifcase \month \or \m@l \or \un@r \or \m@l \or \m@s \or \m@l \or \m@s
+ \or \m@l \or \m@l \or \m@s \or \m@l \or \m@s \or \m@l \fi}
+
+\newcommand\FixMonth{%
+ \L@@p \ifnum\month<1 \advance\year\m@ne \advance\month12 \is@LeapYear \repeat
+ \L@@p \ifnum\month>12 \advance\year\@ne \advance\month-12 \is@LeapYear \repeat}
+
+\newcommand\FixDate{%
+ \FixMonth \is@LeapYear
+ \l@@p \ifnum\day<1 \Pr@vD@y \repeat
+ \l@@p \M@s\m@sic \ifnum\day>\M@s \N@xtD@y \repeat
+}
+
+% We need a nested \loop and the user might call the macros from his/her \loop
+
+\def\L@@p#1\repeat{\def\It@r@te{#1\relax \expandafter\It@r@te\fi}\It@r@te
+ \let\It@r@te\relax}
+
+\def\l@@p#1\repeat{\def\it@r@te{#1\relax \expandafter\it@r@te\fi}\it@r@te
+ \let\it@r@te\relax}
+
+\def\Pr@vD@y{%
+ \ifnum\day<-366
+ \ifnum\month>2
+ \advance\day\r@k \advance\year\m@ne \is@LeapYear
+ \else
+ \advance\year\m@ne \is@LeapYear \advance\day\r@k
+ \fi
+ \else
+ \advance\month\m@ne \FixMonth
+ \advance\day\m@sic
+ \fi}
+
+\def\N@xtD@y{%
+ \ifnum\day>366
+ \ifnum\month>2
+ \advance\year\@ne \is@LeapYear \advance\day-\r@k
+ \else
+ \advance\day-\r@k \advance\year\@ne \is@LeapYear
+ \fi
+ \else
+ \advance\day-\M@s \advance\month\@ne \FixMonth
+ \fi}
+
+\newcommand\AdvanceDate[1][\@ne]{\advance\day#1 \FixDate}
+
+\newcommand\DayAfter[1][\@ne]{{\AdvanceDate[#1]\today}}
+
+\newcommand\SaveDate[1][\s@v@dT@d@y]{%
+ \expandafter \expandafter \expandafter \expandafter
+ \expandafter \expandafter \expandafter \edef
+ \expandafter \expandafter \expandafter \expandafter
+ \expandafter \expandafter \expandafter #1\expandafter
+ \expandafter \expandafter \expandafter
+ \expandafter \expandafter \expandafter
+ {\expandafter \expandafter \expandafter \number
+ \expandafter \expandafter \expandafter \day
+ \expandafter \expandafter \expandafter /\expandafter \number
+ \expandafter \month \expandafter /\number \year}}
+
+\newcommand\SetDate[1][\s@v@dT@d@y]{\edef\d@t@{#1}%
+ \expandafter\t@d@y\d@t@\t@d@y\FixDate}
+
+\def\t@d@y#1/#2/#3\t@d@y{\day#1 \month#2 \year#3 \relax}
+
+\newcommand\ThisDay[1]{\day#1 \relax}
+\newcommand\ThisMonth[1]{\month#1 \relax}
+\newcommand\ThisYear[1]{\year#1 \relax}
+\newcommand\AdvMonth[1]{\advance\month#1 \FixMonth}
+\newcommand\AdvYear[1]{\advance\year#1 \relax}