Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

isoxdate.sty: formatting ISO dates according to en-US and ru-RU conventions

4 views
Skip to first unread message

Ivan Shmakov

unread,
Aug 31, 2012, 2:46:52 PM8/31/12
to
Archive-name: isoxdate-sty-is
Last-modified: 2012-08-31 00:00

A brief search for a LaTeX facility to convert ISO 8601 dates
(e. g., 2012-08-31) into various "national" formats didn't
reveal much, so I've ended up with writing the following
simplistic code.

Hopefully, it may be useful to someone else, too. (Though I'm
not that sure that I've got everything right, and I guess
there're quite a few more date formats that I may need to
consider for this code.)

%% Examples
\usepackage {isoxdate}
...
\selectxdatefmt {}%
\xdate {2012-08-31}% => 2012-08-31
\selectxdatefmt {iso}%
\xdate {2012-08-31}% => 2012-08-31
\selectxdatefmt {enus}%
\xdate {2012-08-31}% => 08/31/2012
\selectxdatefmt {ru}%
\xdate {2012-08-31}% => 31.08.2012
\xdate [] {2012-08-31}% => 2012-08-31
\xdate [iso] {2012-08-31}% => 2012-08-31
\xdate [enus] {2012-08-31}% => 08/31/2012
\xdate [ru] {2012-08-31}% => 31.08.2012

%%% isoxdate.sty -*- LaTeX -*-
\NeedsTeXFormat {LaTeX2e}
\ProvidesPackage {isoxdate} [%
2012/08/31 0.1 ISO 8601 to national conventions conversion]

%%% Ivan Shmakov, 2012
%% This code is in the public domain. This applies worldwide.
%%
%% If it's not legally possible, the MirOS license may be used instead.

%%% Code:

\newcommand \isoxdate@ [3] {#1-#2-#3}
\newcommand \isoxdate@enus [3] {#2/#3/#1}
\newcommand \isoxdate@ru [3] {#3.#2.#1}
\let \isoxdate@iso \isoxdate@

\def \xdate@#1-#2-#3\endxdate@ {%
{#1} {#2} {#3}}

\let \cur@xdate \isoxdate@
\newcommand \selectxdatefmt [1] {%
\expandafter \let \expandafter \cur@xdate
\csname isoxdate@#1\endcsname
}

\newcommand \@xdate [1] {%
\expandafter \cur@xdate \xdate@ #1\endxdate@}
\newcommand \xdate [2] [\relax] {%
\ifx \relax #1%
\@xdate {#2}%
\else {%
\selectxdatefmt {#1}%
\@xdate {#2}}%
\fi
}

\endinput
%%% Emacs trailer
%% Local variables:
%% fill-column: 72
%% indent-tabs-mode: nil
%% End:
%%% isoxdate.sty ends here

--
FSF associate member #7257 http://sfd.am-1.org/
0 new messages