[NTG-context] expand date from CSV file

Jaroslav Hajtmar hajtmar at gyza.cz
Thu Dec 18 13:24:45 CET 2014


Hi Pablo,
I am sending still slightly modified version (use local variables and 
better typographic output).
It use of much variables, but at least it is clear how it works. For 
solution occurred me to use parsing function that I have been defined in 
the library, so that it can be successfully used.

Sincerely
Jaroslav Hajtmar



\usemodule[scancsv]

\def\ddmmyyyy#1#2#3{% #1 - date, #2 - old separator, #3 - new separator
\startlua
     local parsedate=thirddata.scancsv.ParseCSVLine('#1','#2');
     local day=tonumber(parsedate[1]);
     local month=tonumber(parsedate[2]);
     local year=tonumber(parsedate[3]);
     if (year<2000) then year=year+2000 end;
     tex.print(day..'#3'..month..'#3'..year);
\stoplua
}

\unexpanded\def\lineaction{
     \Name\ arrived on \ddmmyyyy{\Date}{/}{.\\,} \\
}


%     Name;Date
%     ME;11/10/14
%     You;05/02/14
%     He;15/02/2014
%     She;03/03/12
%     It;03/03/14

\setheader
  \setsep{;}
  \setfiletoscan{mail.csv}

\starttext
    \filelineaction
\stoptext




Dne 18.12.2014 9:39, Jaroslav Hajtmar napsal(a):
> Hi Pablo
>
> Here is a quick solution. However, it not treat the incorrect input 
> data, ie it requires, however, correct input, otherwise it will 
> collapse ...
>
> Jaroslav Hajtmar
>
>
>
> \usemodule[scancsv]
>
> \def\ddmmyyyy#1#2#3{% #1 - date, #2 - old separator, #3 - new separator
> \startlua
>     parsedate=thirddata.scancsv.ParseCSVLine('#1','#2');
>     day=tonumber(parsedate[1]);
>     month=tonumber(parsedate[2]);
>     year=tonumber(parsedate[3]);
>     if (year<2000) then year=year+2000 end;
>     tex.print(day..'#3'..month..'#3'..year);
> \stoplua
> }
>
> \unexpanded\def\lineaction{
>     \Name\ arrived on \ddmmyyyy{\Date}{/}{.} \\
> }
>
>
> %     Name;Date
> %     ME;11/10/14
> %     You;05/02/14
> %     He;15/02/2014
> %     She;03/03/12
> %     It;03/03/14
>
> \setheader
>  \setsep{;}
>  \setfiletoscan{mail.csv}
>
> \starttext
>    \filelineaction
> \stoptext
>
>
>
>
>
> Dne 17.12.2014 22:20, Pablo Rodriguez napsal(a):
>> Dear list,
>>
>> I have the following sample:
>>
>>      \usemodule[scancsv]
>>
>>      \unexpanded\def\lineaction{
>>      \Name\ arrived on \Date\\
>>      }
>>
>>      \setheader
>>      \setsep{;}
>>      \setfiletoscan{mail.csv}
>>
>>      \starttext
>>          \filelineaction
>>      \stoptext
>>
>> that reads data from mail.csv:
>>
>>      Name;Date
>>      ME;11/10/14
>>      You;05/02/14
>>      He;15/02/2014
>>      She;03/03/12
>>      It;03/03/14
>>
>> My question is simple (and not related to CSV data import): how can I
>> define a command (ConTeXt or Lua) that changes date format from DD/MM/YY
>> to DD/MM/YYYY when required?
>>
>> Many thanks for your help,
>>
>>
>> Pablo
>
> ___________________________________________________________________________________ 
>
> If your question is of interest to others as well, please add an entry 
> to the Wiki!
>
> maillist : ntg-context at ntg.nl / 
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________



More information about the ntg-context mailing list