%%
%% This is file `luapersian-persiancal.sty',
%% generated with the docstrip utility.
%%   ______________________________________
%%   Copyright © 2011  Vafa Khalighi
%% 
%%   License information appended.
%% 
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luapersian-persiancal}[2011/08/01 v0.1 provides Persian calendar]

\newif\ifluapersian@leap \newif\ifluapersian@kabiseh
\newcount\luapersian@i  \newcount\luapersian@y  \newcount\luapersian@m  \newcount\luapersian@d
\newcount\luapersian@latini    \newcount\luapersian@persiani
\newcount\luapersian@latinii   \newcount\luapersian@persianii
\newcount\luapersian@latiniii  \newcount\luapersian@persianiii
\newcount\luapersian@latiniv   \newcount\luapersian@persianiv
\newcount\luapersian@latinv    \newcount\luapersian@persianv
\newcount\luapersian@latinvi   \newcount\luapersian@persianvi
\newcount\luapersian@latinvii  \newcount\luapersian@persianvii
\newcount\luapersian@latinviii \newcount\luapersian@persianviii
\newcount\luapersian@latinix   \newcount\luapersian@persianix
\newcount\luapersian@latinx    \newcount\luapersian@persianx
\newcount\luapersian@latinxi   \newcount\luapersian@persianxi
\newcount\luapersian@latinxii  \newcount\luapersian@persianxii
                       \newcount\luapersian@persianxiii

\newcount\luapersian@temp
\newcount\luapersian@temptwo
\newcount\luapersian@tempthree
\newcount\luapersian@yModHundred
\newcount\luapersian@thirtytwo
\newcount\luapersian@dn
\newcount\luapersian@sn
\newcount\luapersian@mminusone

\def\persiantoday{%
\luapersian@y=\year \luapersian@m=\month \luapersian@d=\day
\luapersian@temp=\luapersian@y
\divide\luapersian@temp by 100\relax
\multiply\luapersian@temp by 100\relax
\luapersian@yModHundred=\luapersian@y
\advance\luapersian@yModHundred by -\luapersian@temp\relax
\ifodd\luapersian@yModHundred
   \luapersian@leapfalse
\else
   \luapersian@temp=\luapersian@yModHundred
   \divide\luapersian@temp by 2\relax
   \ifodd\luapersian@temp\luapersian@leapfalse
   \else
      \ifnum\luapersian@yModHundred=0%
         \luapersian@temp=\luapersian@y
         \divide\luapersian@temp by 400\relax
         \multiply\luapersian@temp by 400\relax
         \ifnum\luapersian@y=\luapersian@temp\luapersian@leaptrue\else\luapersian@leapfalse\fi
      \else\luapersian@leaptrue
      \fi
   \fi
\fi
\luapersian@latini=31\relax
\ifluapersian@leap
  \luapersian@latinii = 29\relax
\else
  \luapersian@latinii = 28\relax
\fi
\luapersian@latiniii = 31\relax
\luapersian@latiniv  = 30\relax
\luapersian@latinv = 31\relax
\luapersian@latinvi = 30\relax
\luapersian@latinvii = 31\relax
\luapersian@latinviii = 31\relax
\luapersian@latinix = 30\relax
\luapersian@latinx = 31\relax
\luapersian@latinxi = 30\relax
\luapersian@latinxii = 31\relax
\luapersian@thirtytwo=32\relax
\luapersian@temp=\luapersian@y
\advance\luapersian@temp by -17\relax
\luapersian@temptwo=\luapersian@temp
\divide\luapersian@temptwo by 33\relax
\multiply\luapersian@temptwo by 33\relax
\advance\luapersian@temp by -\luapersian@temptwo
\ifnum\luapersian@temp=\luapersian@thirtytwo\luapersian@kabisehfalse
\else
   \luapersian@temptwo=\luapersian@temp
   \divide\luapersian@temptwo by 4\relax
   \multiply\luapersian@temptwo by 4\relax
   \advance\luapersian@temp by -\luapersian@temptwo
   \ifnum\luapersian@temp=\z@\luapersian@kabisehtrue\else\luapersian@kabisehfalse\fi
\fi
\luapersian@tempthree=\luapersian@y                 % Number of Leap years
\advance\luapersian@tempthree by -1
\luapersian@temp=\luapersian@tempthree              % T := (MY-1) div 4
\divide\luapersian@temp by 4\relax
\luapersian@temptwo=\luapersian@tempthree           % T := T - ((MY-1) div 100)
\divide\luapersian@temptwo by 100\relax
\advance\luapersian@temp by -\luapersian@temptwo
\luapersian@temptwo=\luapersian@tempthree           % T := T + ((MY-1) div 400)
\divide\luapersian@temptwo by 400\relax
\advance\luapersian@temp by \luapersian@temptwo
\advance\luapersian@tempthree by -611       % Number of Kabise years
\luapersian@temptwo=\luapersian@tempthree           % T := T - ((SY+10) div 33) * 8
\divide\luapersian@temptwo by 33\relax
\multiply\luapersian@temptwo by 8\relax
\advance\luapersian@temp by -\luapersian@temptwo
\luapersian@temptwo=\luapersian@tempthree           %
\divide\luapersian@temptwo by 33\relax
\multiply\luapersian@temptwo by 33\relax
\advance\luapersian@tempthree by -\luapersian@temptwo
\ifnum\luapersian@tempthree=32\advance\luapersian@temp by 1\fi % if (SY+10) mod 33=32 then Inc(T);
\divide\luapersian@tempthree by 4\relax     % T := T - ((SY+10) mod 33) div 4
\advance\luapersian@temp by -\luapersian@tempthree
\advance\luapersian@temp by -137            % T := T - 137  Adjust the value
\luapersian@persiani=31
\advance\luapersian@persiani by -\luapersian@temp                 % now 31 - T is the persiani
\luapersian@persianii = 30\relax
\ifluapersian@kabiseh
  \luapersian@persianiii = 30\relax
\else
  \luapersian@persianiii = 29\relax
\fi
\luapersian@persianiv  = 31\relax
\luapersian@persianv   = 31\relax
\luapersian@persianvi  = 31\relax
\luapersian@persianvii = 31\relax
\luapersian@persianviii= 31\relax
\luapersian@persianix  = 31\relax
\luapersian@persianx   = 30\relax
\luapersian@persianxi  = 30\relax
\luapersian@persianxii = 30\relax
\luapersian@persianxiii= 30\relax
\luapersian@dn= 0\relax
\luapersian@sn= 0\relax
\luapersian@mminusone=\luapersian@m
\advance\luapersian@mminusone by -1\relax
\luapersian@i=0\relax
\ifnum\luapersian@i < \luapersian@mminusone
\loop
\advance \luapersian@i by 1\relax
\advance\luapersian@dn by \csname luapersian@latin\romannumeral\the\luapersian@i\endcsname
\ifnum\luapersian@i<\luapersian@mminusone \repeat
\fi
\advance \luapersian@dn by \luapersian@d
\luapersian@i=1\relax
\luapersian@sn = \luapersian@persiani
\ifnum \luapersian@sn<\luapersian@dn
\loop
\advance \luapersian@i by 1\relax
\advance\luapersian@sn by \csname luapersian@persian\romannumeral\the\luapersian@i\endcsname
\ifnum \luapersian@sn<\luapersian@dn \repeat
\fi
\ifnum \luapersian@i < 4
   \luapersian@m = 9 \advance\luapersian@m by \luapersian@i
   \advance \luapersian@y by -622\relax
\else
   \luapersian@m = \luapersian@i \advance \luapersian@m by -3\relax
   \advance \luapersian@y by -621\relax
\fi
\advance\luapersian@sn by -\csname luapersian@persian\romannumeral\the\luapersian@i%
\endcsname
\ifnum\luapersian@i = 1
  \luapersian@d = \luapersian@dn \advance \luapersian@d by 30 \advance\luapersian@d by -\luapersian@persiani
\else
  \luapersian@d = \luapersian@dn \advance \luapersian@d by -\luapersian@sn
\fi
\bgroup\textdir TLT\number\luapersian@d\egroup\space%
\persianmonth{\luapersian@m}\space\bgroup\textdir TLT\number\luapersian@y\egroup%
}
\def\persianmonth#1{\ifcase#1\or فروردین\or
اردیبهشت\or
خرداد\or تیر\or
مرداد\or
شهریور\or مهر\or
آبان\or آذر\or
دی\or بهمن\or
اسفند\fi}
%% 
%% Copyright © 2011  Vafa Khalighi <vafa018@gmail.com>
%% 
%% It may be distributed and/or modified under the LaTeX Project Public License,
%% version 1.3c or higher (your choice). The latest version of
%% this license is at: http://www.latex-project.org/lppl.txt
%% 
%% This work is “author-maintained” (as per LPPL maintenance status)
%% by Vafa Khalighi.
%% 
%% 
%% 
%%
%% End of file `luapersian-persiancal.sty'.
