The datenumber.sty package v0.02

Jörg-Michael Schröder

                                schrj020@mail.uni-mainz.de

2001/08/06

Abstract This package provides commands to convert a date into a number. Turned around a date can be calculated also by a number. Additionally there are commands for incrementing and decrementing a date. Leap years and the Gregorian calendar reform are considered.

Contents

1 Start year 1 2 Counters 1 3 Macros 1

3.1 Macros which operate with defined counters . . . . . . . . . . . . . . . . . . . . . . 1 3.2 Macros which operate with your own counters . . . . . . . . . . . . . . . . . . . . . 2 3.3 Month . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 3.4 Weekday . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

4 Language 2 5 Examples 3 6 Other 4

1 Start year

The start of the counting is determined with \setstartyear{year} (standard 1800). The first day of the start year gets the number 1. The value of startyear must be greater 0. It may not be larger than the year of a date to be calculated. If the difference of date and startyear is large, the calculation can last for a long time. The correct setting of the weekdays is guaranteed only if the value of startyear is 1800, 1900 or 2000.

2 Counters

There are five counters defined datenumber: number of the day

dateyear: year
datemonth: month
dateday: day

datedayname: weekday: 1–7 (Monday–Sunday)

3 Macros

3.1 Macros which operate with defined counters

All counters specified above are updated by these macros. \datedayname and \datemonthname are also updated.

\setdatenumber{year}{month}{day}: Sets the counter datenumber to a value, which corresponds to the date.

\setdatebynumber{number}: Sets the counters dateyear, datemonth, and dateday to values,

which corresponds to the number.

\nextdate: Sets the counters dateyear, datemonth, and dateday to the next date.

\prevdate: Sets the counters dateyear, datemonth, and dateday to the previous date.

\setdate{year}{month}{day}: Sets the counters dateyear, datemonth, and dateday to year,
     month, and day.

\setdatetoday: Sets the counters dateyear, datemonth, and dateday to the current date.

\datemonthname: typesets the month (see section 3.3).

\datedayname: typesets the weekday (see section 3.4).

\datedate: typesets the date, corresponding to the counters dateyear, datemonth, dateday.

3.2 Macros which operate with your own counters

Only the counters you specified are updated by these macros. \datedayname and \datemonthname are not updated.

\setmydatenumber{numbercount}{year}{month}{day}: Sets the counter numbercount to a

value, which corresponds to the date.

\setmydatebynumber{number}{yearcount}{monthcount}{daycount}: Sets  the  counters

yearcount, monthcount, and daycount to values, which corresponds to the number.

\mynextdate{yearcount}{monthcount}{daycount}: Sets the counters yearcount, monthcount,

and daycount to the next date.

\mynextdate{yearcount}{monthcount}{daycount}: Sets the counters yearcount, monthcount,

and daycount to the previous date.

3.3 Month

The command \datemonthname typesets the month. It is updated by macros described in section 3.1. You can do this by your own saying \setmonthname{number}.

3.4 Weekday

To typeset the weekday say \datedayname. This command is updated by macros described in section 3.1. You can do this by your own saying \setmonthname{number} (1 for Monday and 7 for Sunday). You can also write \setdaynamebynumber{number}, were number is the number of a date. If startyear is set to 1800, 1900 or 2000 the calculation of the weekday will work.

4 Language

The language options english, USenglish (standard), french, spanish, german, and ngerman

are supported. Say \dateselectlanguage{language} to select a language. For other lan-

guages: Create a file datenumbermylanguage.ldf. Copy the text from datenumberdummy.ldf.

Replace every “dummy” with “mylanguage” and change the months and weekdays. Say

\usepackage{datenumber} \input{datenumbermylanguage.ldf} in your document.

5 Examples

\setdate{2002}{1}{1}%
\thedatenumber

Result: 73780

\setdatetoday
\addtocounter{datenumber}{10}%
\setdatebynumber{\thedatenumber}%
In 10 days is \datedate

Result: In 10 days is August 18, 2001

\newcounter{dateone}\newcounter{datetwo}%
\newcommand{\daydifftoday}[3]{%
  \setmydatenumber{dateone}{\the\year}{\the\month}{\the\day}%
  \setmydatenumber{datetwo}{#1}{#2}{#3}%
  \addtocounter{datetwo}{-\thedateone}%
  \thedatetwo
}
There is still \daydifftoday{\the\year}{12}{25} days to Christmas.

Result: There is still 139 days to Christmas.

\newcommand{\sd}{%
\ifcase\thedatedayname \or
    Mon\or Tue\or Wed\or Thu\or
    Fri\or Sat\or Sun\fi
}%
\newcommand{\pnext}{%
\thedateyear/%
\ifnum\value{datemonth}<10 0\fi
\thedatemonth/%
\ifnum\value{dateday}<10 0\fi
\thedateday%
\nextdate
}
\setdate{2001}{9}{29}%
\[\begin{tabular}{lll}
\sd & \pnext & Abc\\
\sd & \pnext & Def\\
\sd & \pnext & Ghi\\
\sd & \pnext & Jkl\\
\end{tabular}\]

Result:

Sat 2001/09/29 Abc
Sun 2001/09/30 Def
Mon 2001/10/01 Ghi
Tue 2001/10/02 Jkl

6 Other

• leap year test

    The \the\year\ is
    \ifleapyear{\the\year} a \else no \fi leap year.

Result: The 2001 is no leap year.

• date test

    The 29.2.1900 is
    \ifvaliddate{1900}{2}{29} a \else no \fi valid date.

Result: The 29.2.1900 is no valid date.^{1}

1There are programs, which have another opinion about that. Search for ”Gregorian calendar” in order to get more information about leap years and October 5, 1582