5

The date format is wrong when datetime and datenumber are used at the same time, datenumber being loaded after datetime.

As can be tested with the following MWE:

\documentclass{article}
\usepackage{datetime}
\usepackage[english]{datenumber}
\begin{document}
\section{Package datenumber}
\begin{itemize}
  \item \setdate{2015}{1}{21}
    \datedate
  \item \setdate{2015}{1}{22}
    \datedate
  \item \setdate{2015}{1}{23}
    \datedate
  \item \setdate{2015}{1}{31}
    \datedate
\end{itemize}

\section{Package datetime}
\begin{itemize}
\item \newdate{21}{21}{1}{2015}
  \displaydate{21}
\item \newdate{22}{22}{1}{2015}
  \displaydate{22}
\item \newdate{23}{23}{1}{2015}
  \displaydate{23}
\item \newdate{31}{31}{1}{2015}
  \displaydate{31}
\end{itemize}
\end{document}
  • when datenumber is not loaded, datetime displays the ordinal for 21, 22, 23 and 31 as 21st, 22nd, 23rd and 31st, as expected with UKenglish;

  • when datetime is not loaded, datenumber displays the ordinal for 21, 22, 23 and 31 as 21st, 22nd, 23rd and 31st, as (almost) expected with UKenglish;

  • when datenumber and datetime are loaded in this order, the error:

     ! You can't use `the character 2' after \advance.
     <argument> 2
                 015
     l.9 \item \setdate{2015}{1}{21}
    

    already reported in datetime and datenumber package conflict? arises;

  • when datetime and datenumber are loaded in this order, the ordinal for 21, 22, 23 and 31 are displayed as:

    • 21st, 22nd, 23rd and 31st by datenumber, as (almost) expected with UKenglish;
    • 21th, 22th, 23th and 31th by datetime, and that's wrong.

2 Answers 2

5

Both packages define a \@modulo macro. More precisely datetime requires package fmtcount and get it from there, while datenumber gives its own definition.

$ latexdef -p datetime @modulo

\@modulo:
macro:#1#2->\@DT@modctr =#1\relax \divide \@DT@modctr by #2\relax \multiply \@DT@modctr by #2\relax \advance #1 by -\@DT@modctr 

$ latexdef -p datenumber @modulo

\@modulo:
macro:#1#2->\@nom =#1\relax \@den =#2\relax \divide \@nom by \@den \multiply \@nom by \@den \@den =#1\advance \@den by -\@nom 

This is presumably the source of the incompatibility.

Wrap the loading of datenumber as:

\makeatletter
\let\@modulo@SAVED\@modulo
\usepackage[english]{datenumber}
\let\DATENUMBER@modulo\@modulo
\def\setdaynamebynumber#1{%
  \@tempcnta=#1\relax
  \ifnum\the@startyear=1800\advance \@tempcnta by 1\fi
  \ifnum\the@startyear=1900\advance \@tempcnta by 6\fi
  \ifnum\the@startyear=2000\advance \@tempcnta by 4\fi
  \DATENUMBER@modulo{\the\@tempcnta}{7}%
  \setcounter{datedayname}{\the\@den}%
  \addtocounter{datedayname}{1}%
  \setdayname{\thedatedayname}%
}
\def\ifleapyear#1{%#1 year
  \ifnum#1>1500
    \DATENUMBER@modulo{#1}{100}%
    \ifnum\@den=0
      \DATENUMBER@modulo{#1}{400}%
    \else
      \DATENUMBER@modulo{#1}{4}%
    \fi
  \else
    \DATENUMBER@modulo{#1}{4}%
  \fi
  \ifnum\@den=0
}
\let\@modulo\@modulo@SAVED
\makeatother

It then doesn't matter if you load it before or after datetime.

3

Define own modulo functions:

\documentclass{article}
\usepackage[english]{datenumber}
\makeatletter 
\let\dn@modulo\@modulo
\makeatother
\usepackage{datetime}
\makeatletter 
\let\dt@modulo\@modulo
\makeatother

\begin{document}
\section{Package datenumber}
\makeatletter 
\let\@modulo\dn@modulo
\makeatother
\begin{itemize}
  \item \setdate{2015}{1}{21}
    \datedate
  \item \setdate{2015}{1}{22}
    \datedate
  \item \setdate{2015}{1}{23}
    \datedate
  \item \setdate{2015}{1}{31}
    \datedate
\end{itemize}

\makeatletter 
\let\@modulo\dt@modulo
\makeatother
\section{Package datetime}
\begin{itemize}
\item \newdate{21}{21}{1}{2015}
  \displaydate{21}
\item \newdate{22}{22}{1}{2015}
  \displaydate{22}
\item \newdate{23}{23}{1}{2015}
  \displaydate{23}
\item \newdate{31}{31}{1}{2015}
  \displaydate{31}
\end{itemize}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .