summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/calcage/calcage.sty
blob: 61c7fc4ea74c548a45f1e539bc42c95e93593abd (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
%% See file 'calcage.dtx' for copyright and licence.
\NeedsTeXFormat{LaTeX2e}[1998/12/01]
\ProvidesPackage{calcage}
    [2012/09/09 v0.90 Calculate the age in years]
\RequirePackage{fnumprint}[2012/08/27]
\RequirePackage{
  datenumber,
  fp,
  calc,
  xkeyval,
  kvoptions,
  xifthen,
}
\DeclareStringOption{year}
\DeclareStringOption{month}
\DeclareStringOption{day}
\DeclareStringOption{precision}[3]
\DeclareBoolOption{positive}
\DeclareBoolOption{printyear}
\DeclareBoolOption{yearsuffix}
\DeclareBoolOption{numberstring}
\ProcessLocalKeyvalOptions*
\edef\calcage@options{\@ptionlist{\@currname.\@currext}}
%% ^^A \renewcommand{\calcage@options}{precision=4,printyear=false}
%% ^^A Package xkeyval Error: `precision=4' undefined in families `calcage'.
\ifcase\value{fnumprint@language}\or
  \newcommand{\calcage@yearWord}{Jahr}
  \newcommand{\calcage@yearPluralSuffix}{e}
  \newcommand{\calcage@yearSuffix}{n}
\or
  \newcommand{\calcage@yearWord}{year}
  \newcommand{\calcage@yearPluralSuffix}{s}
  \newcommand{\calcage@yearSuffix}{}
\fi
\newcounter{calcage@today}\newcounter{calcage@ageindays}
\newcounter{calcage@myyear}\newcounter{calcage@leapyears}
\newcommand{\calcage}[4][]{%
  \setkeys{calcage}{precision=0, positive=true, printyear=true,
    yearsuffix=false, numberstring=true,
    year=\the\year, month=\the\month, day=\the\day, \calcage@options, #1}%
  \setmydatenumber{calcage@today}{\calcage@year}{\calcage@month}{\calcage@day}%
  \setmydatenumber{calcage@ageindays}{#2}{#3}{#4}%
  \setcounter{calcage@myyear}{#2}%
  \setcounter{calcage@leapyears}{0}%
  \ifthenelse{\equal{#2}{\calcage@year}}{}{%
    \ifthenelse{\value{calcage@myyear}<\calcage@year}{%
      \loop%
        \stepcounter{calcage@myyear}%
        \ifleapyear{\thecalcage@myyear}\stepcounter{calcage@leapyears}\fi%
        \ifnum\value{calcage@myyear}<\calcage@year%
      \repeat%
    }{%
      \loop%
        \ifleapyear{\thecalcage@myyear}\addtocounter{calcage@leapyears}{-1}\fi%
        \addtocounter{calcage@myyear}{-1}%
        \ifnum\value{calcage@myyear}>\calcage@year%
      \repeat%
    }%
  }%
  \setcounter{calcage@ageindays}{\value{calcage@today}
    - \value{calcage@ageindays} - \value{calcage@leapyears}}%
  \ifthenelse{\boolean{calcage@positive} \AND \value{calcage@ageindays} < 0}{%
    \setcounter{calcage@ageindays}{\value{calcage@ageindays} * -1}%
  }{}%
  \FPdiv\calcage@age{\thecalcage@ageindays}{365}%
  \FPtrunc\calcage@age{\calcage@age}{\calcage@precision}%
  \ifthenelse{\boolean{calcage@numberstring}
    \AND \equal{\calcage@precision}{0}}%
    {\fnumprint[ein]{\calcage@age}}{\numprint{\calcage@age}}%
  \ifthenelse{\boolean{calcage@printyear}}{%
    ~\calcage@yearWord%
    \ifthenelse{\equal{\calcage@age}{1} \OR \equal{\calcage@age}{-1}}{}{%
      \calcage@yearPluralSuffix%
      \ifthenelse{\boolean{calcage@yearsuffix}}{\calcage@yearSuffix}{}%
    }%
  }{}%
}
\endinput
%%
%% End of file `calcage.sty'.