%\iffalse
%
% File dates.dtx
% Copyright (C) 1996 by Frank Bennett. All rights reserved.
%
% IMPORTANT NOTICE:
%
% You are not allowed to change this file. You may however copy
% this file to a file with a different name and then change the
% copy if (a) you do not charge for the modified code, (b) you
% acknowledge the author(s) in the new file, if it
% is distributed to others, and (c) you attach these same
% conditions to the new file.
%
% You are not allowed to distribute this file alone. You are not
% allowed to take money for the distribution or use of this file
% (or a changed version) except for a nominal charge for copying
% etc.
%
% You are allowed to distribute this file under the condition that
% it is distributed with all of its contents, intact.
%
% For error reports, or offers to help make this a more powerful,
% friendlier, and altogether more thrilling package, please contact me on
% fb@soas.ac.uk
%
%<*dtx>
\ProvidesFile{dates.dtx}
%
%
% \end{macrocode}
%
% \section{The Demo File}
%
% \begin{macrocode}
%<*demo>
\documentclass{minimal}
\usepackage{dates}
\begin{document}
\makeatletter
%%
%% We invoke the \dateread command.
%%
\dateread
%%
%% We tell it to report a few details to the terminal.
%%
{\message{\theshorttext}%
\message{\theday/\the\dates@month/\the\dates@year}%
\ifx\thelongtext\dates@empty%
\else%
\message{\thelongtext}%
\fi}
%%
%% The following are ranges.
%%
december 10 1995 {^^JStart of First}
to jan 10 1996 {End of First}
december 10 1996 {^^JStart of Second}
to jan 10 1997 {End of Second^^J}
%%
%% The following are specific dates (obviously)
%%
February 18 1997 {^^JFrank's Next Birthday}
[The best presents come in small packages.^^JIt
would be a terrific present for someone to make
this one smaller.]
February 18 1998 {^^JFrank's Next Birthday But One}
%%
%% These are a couple of recursive dates.
%%
Every Monday {^^JMonday Coffee}
Every Third Tuesday {^^JMeeting}
%
%% Here is a sample function definition, which gives
%% the phases of the moon within the ranges. The code
%% was ripped off from the calendar package for plain
%% TeX
%%
function \moonsinit \moonsincrement
{
\newcount\moonno
\newif\ifsign
\def\firstmoon{\moonno=\dates@year
\multiply\moonno by123685
\divide\moonno by10000
\multiply\moonno by4\advance\moonno by-1
\loop\moondate\relax
\ifnum\dates@date<\dates@subrange@start
\advance\moonno by1\repeat}
%% Compute date for cycle quarter MOONNO
\def\moondate{{\count0=\moonno
\lin 202.126.369+0.\count0=\count1
\count6=0
\lin 0.2.319+2907.\sin\fac{3}
\divide\count6 by1000
\lin 365.249.86+7593.\id\fac{1}
\divide\count6 by10\count7 =\count6
\ifodd\moonno\quarters
\else\fullornew\fi\global\dates@date=\count7}
\jdttol}
%% Correction for full and new moon
\def\fullornew{\count6=0
\lin -393.0.0+0.
\divide\count1 by100000000
\advance\count6 by\count1
\lin 0.628.300+6269.\sin
\multiply\count6 by\count4
\lin -7.-700.-369+ 928.\sin\fac{ -74}
\lin 0. 628. 300+ 6269.\sin\fac{ 1734}
\lin 1. 256. 600+12539.\sin\fac{ 21}
\lin 8. 328. 670+ 5341.\sin\fac{-4068}
\lin 8. 538. 220+-4597.\sin\fac{ 10}
\lin 8. 956. 970+11610.\sin\fac{ -51}
\lin 16. 238. 589+-5526.\sin\fac{ -4}
\lin 16. 657. 340+10682.\sin\fac{ 161}
\lin 16. 866. 890+ 743.\sin\fac{ 104}
\lin 17. 285. 640+16951.\sin\fac{ 50}
\lin 17. 495. 190+ 7013.\sin\fac{ 4}
\lin 24. 986. 10+16023.\sin\fac{ -4}
\lin 25. 195. 560+ 6084.\sin\fac{ -6}
\divide\count6 by10000
\advance\count7 by\count6 }
%% Correction for quarters
\def\quarters{\lin -393.0.0+0.
\divide\count1 by100000000
\count6 =\count1 \lin 0.628.300+6269.
\sin\multiply\count6 by\count4
\lin -16. -29. -40+-4413.\sin\fac{ 40}
\lin -7.-700.-369+ 928.\sin\fac{ -47}
\lin -7. -72. -69+ 7198.\sin\fac{ -30}
\lin 0. 628. 300+ 6270.\sin\fac{ 1721}
\lin 1. 256. 600+12539.\sin\fac{ 21}
\lin 8. 328. 670+ 5341.\sin\fac{-6280}
\lin 8. 538. 220+-4598.\sin\fac{ 21}
\lin 8. 956. 970+11611.\sin\fac{ -119}
\lin 16. 238. 589+-5526.\sin\fac{ -4}
\lin 16. 657. 340+10682.\sin\fac{ 89}
\lin 16. 866. 890+ 743.\sin\fac{ 79}
\lin 17. 285. 640+16952.\sin\fac{ 3}
\lin 17. 495. 190+ 7013.\sin\fac{ 3}
\lin 24. 986. 10+16023.\sin\fac{ -4}
\lin 25. 195. 560+ 6085.\sin\fac{ -6}
\count8=\count6\count6=28000
\lin 628. 300. 373+ 6270.\cos\fac{ -4}
\lin 8. 328. 670+ 5341.\cos\fac{ 3}
\count2=\moonno
\advance\count2 by-1\divide\count2 by2
\ifodd\count2\multiply\count6 by-1 \fi
\advance\count6 by\count8
\divide\count6 by10000
\advance\count7 by\count6 }
%% Events for phases.
%% Uses PHASE (local).
\def\phase{{\count0=\moonno
\count1=\moonno
\divide\count0 by4\multiply\count0 by4
\advance\count1 by-\count0\relax
\global\edef\themoon{\ifcase\count1
New Moon\or First Quarter\or
Full Moon\or Last Quarter\fi}}}
\gdef\moonsinit{%
\firstmoon
\dates@month=12\dates@day=31\dates@fix\advance\dates@date by1
\count1=\dates@date
\moondate
\phase
\caldate}
\gdef\moonsincrement{%
\advance\moonno by 1
\moondate\phase
\caldate}
}
{\themoon}
\end{document}
%
% \end{macrocode}
%
%\iffalse
% \begin{macrocode}
%% \section{Date Syntax}
%%
%% \subsection{General Rules}
%%
%% The rules themselves are explained here first. If you
%% want to cut to the chase, have a look at the examples
%% and experiment a bit with the demo file. It's all
%% pretty straightforward.
%%
%% The parser is indifferent to extra spaces and blank
%% lines in dates. It will read a string word by word,
%% and classify each word as a time, a day of the month,
%% the name of a month, a year or a special function.
%% With two exceptions, strings beginning in a number must not mix numbers and
%% other characters --- this will produce a low-level
%% error from \TeX, and at the moment I can't think of
%% an economical way of protecting against this.
%%
%% Any string
%% beginning in a number is interpreted as either a
%% time, a day of the month or a year. A string
%% containing a colon (the ":" character) is assumed
%% to be a time of day. "AM" and "PM" are not recognized;
%% you should use 24-hour format when specifying
%% times. A numeric string containing a hyphen is assumed
%% to be a range of times. In this instance, a colon
%% is not necessary if the time is given in whole-hours.
%% Pure numeric strings are construed as a day of the month
%% if less than 32, or as a year if greater than 31.
%%
%% Character strings are interpreted on the basis of their
%% first three characters; the rest are ignored. Case is
%% also irrelevant. Months and days of the week (used for
%% defining recursive dates, described below) as well as certain
%% special functions are specified as character strings.
%% Any word that does not match an existing function
%% will be ignored.
%%
%% Dates are always terminated by a short description
%% of the date, which must be in curly braces.
%% The description should contain plain text only;
%% do not put macros (like "\LaTeX") here.
%%
%% Dates will be processed until "\dateread" encounters
%% "\end{<"\meta{environment name}">}", or the string
%% "\relax{}". At the "\end" of an environment,
%% the processing of the current date will be completed,
%% and the "\end" will be executed. "\relax{}" will
%% cause processing to end silently without doing
%% anything on the last item (which is the "\relax{}" itself).
%%
%% \subsection{Specific Dates}
%%
%% Applying the above rules, the following is a valid
%% list of dates. The use of "\dateread" is explained
%% below.
%%
%% \begin{quote}
%% \begin{verbatim}
%% \begin{quote}
%% \dateread{\message{\theshorttext}}
%% Jan 1 1996{New Year's Day}
%% 1 January 1996 at 10:00
%% {New Year Bash}"\\
%% 1996
%% jan 1 8-20:30
%% {New Year Cleaning. Rats.}"
%% \end{quote}
%% \end{verbatim}
%% \end{quote}
%%
%% Note that the parser is indifferent to word order,
%% and that commas should not be used to separate
%% words.\footnote{In fact, commas do no harm if
%% they follow a string of three or more letters, but
%% it is best to keep things simple and clean.}
%%
%% \subsection{Recursive Dates}
%%
%% \subsubsection{Ranges}
%%
%% Any recursive dates (such as "Every" "Monday") must
%% be preceded by one or more range specifications,
%% which fix the time period or periods within which to
%% recurse.
%% A range is simply two specific dates separated by the
%% word "to". You may specify multiple ranges;
%% effect will be given to each of them individually.
%%
%% The following is a valid range specification:
%%
%% \begin{quote}
%% \begin{verbatim}
%% February 1 1996 {Start First Period}
%% to April 1 1996 {End First Period}
%% November 3 1996 {Start Second Period}
%% to December 24 1996 {End Second Period}
%% \end{verbatim}
%% \end{quote}
%%
%% \subsubsection{Shorthand Dates}
%%
%% Two types of recursive date can be entered in a
%% human-readable syntax. Entries of both types
%% begin with the word "every". To put an event
%% on every occurence of a day of the week within
%% a specified set of subranges, simply indicate the day
%% of the week, followed by a short description
%% in curly braces.
%%
%% \begin{quote}
%% \begin{verbatim}
%% Every Monday {Monday!}
%% \end{verbatim}
%% \end{quote}
%%
%% To put an event at 14-day intervals, beginning
%% with the first occurrence of a specified day
%% of the week within each subrange, add the
%% word "other".
%%
%% \begin{quote}
%% \begin{verbatim}
%% Every other Monday 7:00 {Monday Morning Exercise}
%% \end{verbatim}
%% \end{quote}
%%
%% To place an event on the "N"th occurrence of
%% a specified day of the week within each month, within
%% subrange, add "first", "second" or "third".
%%
%% \begin{quote}
%% \begin{verbatim}
%% Every third Monday 8:00-9:00
%% {Monday Morning Meeting}
%% \end{verbatim}
%% \end{quote}
%%
%% \subsubsection{Suppressing the Action}
%%
%% There are two ways of suppressing the user-defined action.
%% To quickly comment out an entry, put the word "rem" in
%% front of it. The date will be read, but the action
%% in the argument to "\dateread" will not be performed.
%% This can be used, for example, to suppress the appearance
%% of a range in the output text.
%%
%% The second method uses a toggle, and is meant for use by
%% style authors. Setting:
%%
%% \begin{quote}
%% "\dates@suppress@globaltrue"
%% \end{quote}
%%
%% \noindent will cause the user action to be suppressed
%% throughout the invocation of "\dateread". In order for
%% the action to be performed on the next invocation,
%% the toggle must be set to "false" in the external
%% code that calls the parser.
%%
%% \subsubsection{Functions}
%%
%% It is possible to specify dates within the subranges
%% using an arbitrary formula. Entries of this type
%% begin with the word "function". This is followed
%% by two control strings, a block of \LaTeX{} code in
%% curly braces, and the usual short description, also in
%% curly braces.
%%
%% The first control string is the name of a
%% user-defined macro that will find the position
%% of the first desired date after the start of the
%% range. The second is the name of a macro to
%% use in incrementing afterward. The block of
%% \LaTeX{} code contains the definitions of these
%% and any subsidiary macros.
%%
%% The following will place an entry on every date within
%% the specified subranges.
%%
%% \begin{quote}
%% \begin{verbatim}
%% Function \myinit \myincrement
%% {\def\myinit{%
%% \dates@date=\dates@subrange@start}
%% \def\myincrement{%
%% \advance\dates@date by 1\relax}
%% }
%% {A Day}
%% \end{verbatim}
%% \end{quote}
%%
%% See the code commentary section of the Dates package for information
%% on macros that can be used for manipulating dates.
% \end{macrocode}
%
% \section{The Installation File}
% \begin{macrocode}
%<*installer>
\def\batchfile{dates.ins}
\input docstrip.tex
\keepsilent
\preamble
This file is part of the Dates package.
Copyright (C) 1996 Frank Bennett, Jr.
All rights reserved.
------------------------------------------
This is a generated file.
IMPORTANT NOTICE:
You are not allowed to change this file. You may however copy
this file to a file with a different name and then change the
copy if (a) you do not charge for the modified code, (b) you
acknowledge the author(s) in the new file, if it
is distributed to others, and (c) you attach these same
conditions to the new file.
You are not allowed to distribute this file alone. You are not
allowed to take money for the distribution or use of this file
(or a changed version) except for a nominal charge for copying
etc.
You are allowed to distribute this file under the condition that
it is distributed with all of its contents, intact.
For error reports, or offers to help make this a more powerful,
friendlier, and better package, please contact me on
`fb' at soas.ac.uk
\endpreamble
\generate{\file{dates.sty} {\from{dates.dtx}{style}}
}
\preamble
This file is part of the Dates package,
Copyright (C) 1996 Frank Bennett, Jr.
All rights reserved.
------------------------------------------
This file is provided for demonstration purposes; feel free
to edit it in any way whatsoever.
------------------------------------------
\endpreamble
\postamble
\endpostamble
\generate{\file{demo.tex}{\from{dates.dtx}{demo}}
}
\preamble
\endpreamble
\let\WritePreamble\@gobble
\let\WritePostamble\@gobble
\generate{\file{datesynt.tex}{\from{dates.dtx}{syntax}}
}
\Msg{***********************************************************}
\Msg{*}
\Msg{* To finish the installation, you have to move the following}
\Msg{* file into a directory searched by TeX:}
\Msg{*}
\Msg{* \space\space dates.sty}
\Msg{*}
\Msg{***********************************************************}
}
%
% \end{macrocode}
%\fi
% \Finale \PrintChanges