Datetime, language not supported

datetimelanguages

I want to use the datetime package to get the name of the months, but the package does not support one of the languages I am using. I am writing a template (with a .sty file), so I want to be able to use different languages. My question is: How can I define the name of the months for this language that is not supported?

Here is the code:

\documentclass[5p,a4paper]{elsarticle}
\usepackage[utf8]{inputenc}

\usepackage[english,nynorsk]{babel}
\usepackage{appendix}

\RequirePackage{datetime}
\RequirePackage{etoolbox}
    % Commands for how a date is displayed:
    \newdateformat{MonthYearDateFormat}{%
        \monthname[\THEMONTH], \THEYEAR
        }
    \newdateformat{DayMonthYearDateFormat}{%
        \THEDAY \ \monthname[\THEMONTH], \THEYEAR
        }
    \newdateformat{YearDateFormat}{%
        \THEYEAR
        }

    \patchcmd{\MaketitleBox}{\footnotesize\itshape\elsaddress\par\vskip36pt}{\footnotesize\itshape\elsaddress\par\parbox[b][36pt]{\linewidth}{\vfill\hfill\textnormal{\today}\hfill\null\vfill}}{}{}%
    \patchcmd{\pprintMaketitle}{\footnotesize\itshape\elsaddress\par\vskip36pt}{\footnotesize\itshape\elsaddress\par\parbox[b][36pt]{\linewidth}{\vfill\hfill\textnormal{\today}\hfill\null\vfill}}{}{}%
    
\begin{document}
\selectlanguage{nynorsk}

\begin{frontmatter}

\title{title}

\author[University]{O. Nordmann} 
\address[University]{University}

% Date:
%------------------------------------
\newdate{dateName}{19}{04}{2022}
\renewcommand*{\today}{\MonthYearDateFormat\displaydate{dateName}} 
% Options for displaying date: \MonthYearDateFormat,  \DayMonthYearDateFormat or \YearDateFormat
%

\begin{abstract}
abs

\end{abstract}

\end{frontmatter}

\appendix
\section{A}

\end{document}

This produces the error:

Package datetime Warning: No month names provided for language 'nynorsk' on input line 45.

I would prefer a solution using datetime over some other solution. I tried using datetime2, but I found it simpler to use datetime. Is there a way to define the monthnames for the language nynorsk?

Edit: The reason I used datetime and not datetime2 is because datetime2 has no command that displays the monthname of the currently selected language. As I want my template to be able to handle multiple languages, I can not define a dateformat using names specific for a language.

Also, the names are basicually the same as for those in the language option norsk (which works fine in datetime). However, I want the rest of the document to be typset in nynorsk. As such I would welcome a solution that uses the names from norsk but typsets the rest of the document in nynorsk.

Best Answer

You can add Nynorsk support yourself by patching the relevant commands in the datetime configuration file for (Bokmål) Norsk. I checked on ScriptSource and it seems that only the weekday names need changes.

\documentclass[5p,a4paper]{elsarticle}

\usepackage[english,nynorsk]{babel}
\usepackage{appendix}
\usepackage[norsk]{datetime}
\usepackage{etoolbox}

\NewCommandCopy{\monthnamenynorsk}{\monthnamenorsk}
\NewCommandCopy{\dayofweeknameidnynorsk}{\dayofweeknameidnorsk}
\NewCommandCopy{\shortdayofweeknameidnynorsk}{\shortdayofweeknameidnorsk}
\NewCommandCopy{\datenynorsk}{\datenorsk}

\patchcmd{\dayofweeknameidnynorsk}{Mandag}{Måndag}{}{}
\patchcmd{\dayofweeknameidnynorsk}{Tirsdag}{Tysdag}{}{}
\patchcmd{\dayofweeknameidnynorsk}{L\o{}rdag}{Laurdag}{}{}
\patchcmd{\shortdayofweeknameidnorsk}{Man}{Mån}{}{}
\patchcmd{\shortdayofweeknameidnorsk}{Tir}{Tys}{}{}
\patchcmd{\shortdayofweeknameidnorsk}{L\o{}r}{Lau}{}{}

% Commands for how a date is displayed:
\newdateformat{MonthYearDateFormat}{%
  \monthname[\THEMONTH], \THEYEAR
}
\newdateformat{DayMonthYearDateFormat}{%
  \THEDAY \ \monthname[\THEMONTH], \THEYEAR
}
\newdateformat{YearDateFormat}{%
  \THEYEAR
}

\patchcmd{\MaketitleBox}
  {\footnotesize\itshape\elsaddress\par\vskip36pt}
  {\footnotesize\itshape\elsaddress\par
   \parbox[b][36pt]{\linewidth}{\vfill\hfill\textnormal{\today}\hfill\null\vfill}}
  {}{}
\patchcmd{\pprintMaketitle}
  {\footnotesize\itshape\elsaddress\par\vskip36pt}
  {\footnotesize\itshape\elsaddress\par
   \parbox[b][36pt]{\linewidth}{\vfill\hfill\textnormal{\today}\hfill\null\vfill}}
  {}{}

\begin{document}

\begin{frontmatter}

\title{title}

\author[University]{O. Nordmann} 
\address[University]{University}

% Date:
%------------------------------------
\newdate{dateName}{19}{05}{2022}
\renewcommand*{\today}{\MonthYearDateFormat\displaydate{dateName}} 
% Options for displaying date: \MonthYearDateFormat,  \DayMonthYearDateFormat or \YearDateFormat
%

\begin{abstract}
abs

\begin{otherlanguage}{english}\today\end{otherlanguage}

\end{abstract}

\end{frontmatter}

\appendix
\section{A}

\end{document}

(I changed from April to May to better show the difference).

enter image description here

Related Question