Re: Calendar utility function: Improvement request
Hans Meine <meine <at> informatik.uni-hamburg.de>
2009-08-03 07:43:34 GMT
Hi again!
On Friday 06 February 2009 18:59:16 Hans Meine wrote:
> On Saturday 31 January 2009 21:52:59 Hans Meine wrote:
> > 2) I'd like to render the number of each week (i.e. in order to be able
> > to differentiate between "even and odd weeks"), but there's no
> > \pgfcalendarcurrentweek. Could this be added?
>
> I now implemented this myself!
Thanks to the other macros I found in
> pgfcalendar.code.tex, I could teach myself how to implement the computation
> (after doing some research on how the week number is usually defined).
>
> Attached you find a patch that adds \pgfcalendarjuliantoweek which computes
> a week number according to ISO 8601 (i.e. week 1 is the week of the year's
> first thursday). Also, it adds \pgfcalendarcurrentweek as a "frontend"
> macro for easy typesetting.
I forgot to ask about inclusion in PGF. AFAIK, my implementation should fit
well into the current codebase.
My posting in Feb. contained the following (unanswered) questions though:
> Q1: I have now used \counter1-\counter4 since that fits well with the
> numbered formulas, and \pgfutil <at> tempcnta for (very) temporary purposes. Is
> that reasonable?
> Q2: Do I really need all the \relax'es? (I do not know much about their
> purpose, and nothing in this context.)
> Q3: The nested scope is to get local counters, right?
Also, I suggested further features:
> Next I plan to add ifdate-conditionals like
> "even week" or "odd week", which should be easy.
>
> It would also be cool to have a function that computes the easter date, in
> order to mark holidays in your calendar.
Also, I sent patches for various typos/spelling mistakes in the documentation.
In February, I sent these as separate files, now I will simply attach a
complete "cvs diff".
Have a nice day,
Hans
? install.sh
? doc/generic/pgf/version-for-pdftex/en/pgfmanual.pdf
? doc/generic/pgf/version-for-pdftex/en/plots
Index: doc/generic/pgf/text-en/pgfmanual-en-library-calendar.tex
===================================================================
RCS file: /cvsroot/pgf/pgf/doc/generic/pgf/text-en/pgfmanual-en-library-calendar.tex,v
retrieving revision 1.10
diff -u -3 -p -r1.10 pgfmanual-en-library-calendar.tex
--- doc/generic/pgf/text-en/pgfmanual-en-library-calendar.tex 22 Jan 2008 00:02:42 -0000 1.10
+++ doc/generic/pgf/text-en/pgfmanual-en-library-calendar.tex 3 Aug 2009 07:43:22 -0000
@@ -50,7 +50,7 @@ environments (similar to, say, the |\dra
This has the same effect as saying |[name=|\meta{name}|]|. The
effect of providing a \meta{name} is explained later. Note
- alreadys that \emph{a calendar is not a node} and the \meta{name}
+ already that \emph{a calendar is not a node} and the \meta{name}
is \emph{not the name of a node}.
\item |at (|\meta{coordinate}|)|
Index: doc/generic/pgf/text-en/pgfmanual-en-library-chains.tex
===================================================================
RCS file: /cvsroot/pgf/pgf/doc/generic/pgf/text-en/pgfmanual-en-library-chains.tex,v
retrieving revision 1.3
diff -u -3 -p -r1.3 pgfmanual-en-library-chains.tex
--- doc/generic/pgf/text-en/pgfmanual-en-library-chains.tex 12 Feb 2008 23:41:58 -0000 1.3
+++ doc/generic/pgf/text-en/pgfmanual-en-library-chains.tex 3 Aug 2009 07:43:23 -0000
@@ -20,7 +20,7 @@
\subsection{Overview}
\emph{Chains} are sequences of nodes that are -- typically -- arranged
-in an o row or a column and that are -- typically -- connected by
+in an a row or a column and that are -- typically -- connected by
edges. More generally, they can be used to position nodes of a
branching network in a systematic manner. For the positioning of nodes
in rows and columns you can also use matrices, see
Index: doc/generic/pgf/text-en/pgfmanual-en-pgfcalendar.tex
===================================================================
RCS file: /cvsroot/pgf/pgf/doc/generic/pgf/text-en/pgfmanual-en-pgfcalendar.tex,v
retrieving revision 1.11
diff -u -3 -p -r1.11 pgfmanual-en-pgfcalendar.tex
--- doc/generic/pgf/text-en/pgfmanual-en-pgfcalendar.tex 31 Jul 2007 14:31:59 -0000 1.11
+++ doc/generic/pgf/text-en/pgfmanual-en-pgfcalendar.tex 3 Aug 2009 07:43:23 -0000
@@ -113,7 +113,7 @@ This section describes the package |pgfc
To convert a Julian day number to an ISO-date you use code like the
following:
\begin{verbatim}
-\pgfcalendardatetojulian{2454115}{\myyear}{\mymonth}{\myday}
+\pgfcalendarjuliantodate{2454115}{\myyear}{\mymonth}{\myday}
\edef\isodate{\myyear-\mymonth-\myday}
\end{verbatim}
The above code sets |\isodate| to
@@ -295,13 +295,14 @@ This section describes the package |pgfc
All textual representations of week days or months (like ``Monday'' or
``February'') are wrapped with |\translate| commands from the
|translator| package (it this package is not loaded, no translation
-takes place). Furthermore, the |pgfcalendar| package will try to load
+takes place). Furthermore, the |pgfcalendar| package will try to load
the |translator-months-dictionary|, if the |translator| package is
loaded.
The net effect of all this is that all dates will be translated to the
current language setup in the |translator| package. See the
-documentation of this package for more details.
+documentation of this package for more details (hint: try something
+like |\usepackage[german]{babel,translator}| before loading \pgfname).
@@ -335,7 +336,7 @@ documentation of this package for more d
\medskip
\textbf{Information about the current date.}
- Inside the \meta{rendering code}, different macros can be access:
+ Inside the \meta{rendering code}, different macros can be accessed:
\begin{itemize}
\item |\pgfcalendarprefix|
Index: doc/generic/pgf/text-en/pgfmanual-en-pgfkeys.tex
===================================================================
RCS file: /cvsroot/pgf/pgf/doc/generic/pgf/text-en/pgfmanual-en-pgfkeys.tex,v
retrieving revision 1.13
diff -u -3 -p -r1.13 pgfmanual-en-pgfkeys.tex
--- doc/generic/pgf/text-en/pgfmanual-en-pgfkeys.tex 16 May 2009 17:59:27 -0000 1.13
+++ doc/generic/pgf/text-en/pgfmanual-en-pgfkeys.tex 3 Aug 2009 07:43:23 -0000
@@ -222,7 +222,7 @@ continue with the next subsection.
\end{command}
\begin{command}{\pgfkeyslet\marg{full key}\marg{macro}}
- Performs a |\let| statement so the the \meta{full key} pionts to the
+ Performs a |\let| statement so that the \meta{full key} points to the
contents of \meta{macro}.
\begin{codeexample}[]
\def\helloworld{Hello, world!}
@@ -329,7 +329,7 @@ let us have a quick look at the command
\end{command}
\begin{command}{\pgfkeysalso\marg{key list}}
- This command has execatly the same effect as |\pgfkeys|, only the
+ This command has exactly the same effect as |\pgfkeys|, only the
default path is not modified before or after the keys are being
set. This command is mainly intended to be called by the code that
is being processed for a key.
Index: doc/generic/pgf/text-en/pgfmanual-en-tikz-shapes.tex
===================================================================
RCS file: /cvsroot/pgf/pgf/doc/generic/pgf/text-en/pgfmanual-en-tikz-shapes.tex,v
retrieving revision 1.39
diff -u -3 -p -r1.39 pgfmanual-en-tikz-shapes.tex
--- doc/generic/pgf/text-en/pgfmanual-en-tikz-shapes.tex 9 Dec 2008 00:12:10 -0000 1.39
+++ doc/generic/pgf/text-en/pgfmanual-en-tikz-shapes.tex 3 Aug 2009 07:43:25 -0000
@@ -1368,7 +1368,8 @@ library and the |matrix| library. The fi
creating ``chains of nodes'' and, more generally, ``flows.'' The
second allows you to arrange multiple nodes in rows and columns. These
methods for positioning nodes are described in two separate
-Sections~\ref{section-matrices} and~\ref{section-chains}.
+Sections~\ref{section-matrices} (matrices) and~\ref{section-chains}
+(chains).
\subsection{Fitting Nodes to a Set of Coordinates}
Index: generic/pgf/utilities/pgfcalendar.code.tex
===================================================================
RCS file: /cvsroot/pgf/pgf/generic/pgf/utilities/pgfcalendar.code.tex,v
retrieving revision 1.11
diff -u -3 -p -r1.11 pgfcalendar.code.tex
--- generic/pgf/utilities/pgfcalendar.code.tex 23 Jul 2007 21:23:14 -0000 1.11
+++ generic/pgf/utilities/pgfcalendar.code.tex 3 Aug 2009 07:43:26 -0000
@@ -53,10 +53,10 @@
% accumulate between different calls, which is often desirable and
% useful.
%
-% Inside #4 code, different macros can be access:
+% Inside #4 code, different macros can be accessed:
%
% \pgfcalendarprefix
-% The parameter #1. This prefix is recomended for nodes inside the
+% The parameter #1. This prefix is recommended for nodes inside the
% calendar, but you have to use it yourself explicitly.
%
% \pgfcalendarbeginiso
@@ -81,10 +81,10 @@
% Year of day to be checked
%
% \pgfcalendarcurrentmonth
-% Month of day to be chjeck
+% Month of day to be checked
%
% \pgfcalendarcurrentday
-% Day of monath of day to be checked
+% Day of month of day to be checked
%
%
% Inside the \pgfcalendar macro the macro \ifdate is available, which
@@ -125,6 +125,10 @@
{\pgfcalendarcurrentyear}{\pgfcalendarcurrentmonth}{\pgfcalendarcurrentday}%
\pgfcalendarjuliantoweekday{\pgfcalendarcurrentjulian}{\pgfutil <at> tempcntb}%
\edef\pgfcalendarcurrentweekday{\the\pgfutil <at> tempcntb}%
+ \def\pgfcalendarcurrentweek{% (no \edef here, since the week number
+ \pgfcalendarjuliantoweek{% is a more expensive computation)
+ \pgfcalendarcurrentjulian}{\pgfutil <at> tempcntb}%
+ \the\pgfutil <at> tempcntb}%
% Render:
#4%
% Advance day:
@@ -584,6 +588,74 @@
+% Returns the week of the year (according to ISO 8601) as a number
+% between 0 (last week - i.e. 52 or 53 - of previous year) and 53.
+%
+% #1 = a Julian day number
+% #2 = a counter into which the week number should be put.
+%
+% Example:
+%
+% \pgfcalendardatetojulian{2006-01-10}{\mycount}
+% \pgfcalendarjuliantoweek{\mycount}{\myweekday}
+
+% Formula used:
+% 1) d4 = (J+31741 - (J mod 7)) mod 146097 mod 36524 mod 1461
+% 2) L = d4/1460
+% 3) d1 = ((d4-L) mod 365) + L
+% 4) week number = d1/7+1
+
+\def\pgfcalendarjuliantoweek#1#2{%
+ {%
+ \count1=#1\relax%
+ % 1) d4 = -(J mod 7)..
+ \count2=\count1\relax%
+ \divide\count2by7\relax%
+ \multiply\count2by7\relax%
+ \advance\count2by-\count1\relax%
+ % .. + 31741 + J:
+ \advance\count2by31741\relax%
+ \advance\count2by\count1\relax%
+ % .. mod 146097:
+ \pgfutil <at> tempcnta=\count2\relax%
+ \divide\count2by146097\relax%
+ \multiply\count2by-146097\relax%
+ \advance\count2by\pgfutil <at> tempcnta\relax%
+ % .. mod 36524:
+ \pgfutil <at> tempcnta=\count2\relax%
+ \divide\count2by36524\relax%
+ \multiply\count2by-36524\relax%
+ \advance\count2by\pgfutil <at> tempcnta\relax%
+ % .. mod 1461:
+ \pgfutil <at> tempcnta=\count2\relax%
+ \divide\count2by1461\relax%
+ \multiply\count2by-1461\relax%
+ \advance\count2by\pgfutil <at> tempcnta\relax%
+ \expandafter%
+ % 2) L = d4/1460:
+ \count3=\count2\relax%
+ \divide\count3by1460\relax%
+ % 3) d1 = (d4-L) ..
+ \count4=\count2\relax%
+ \advance\count4by-\count3\relax%
+ % .. mod 365::
+ \pgfutil <at> tempcnta=\count4\relax%
+ \divide\count4by365\relax%
+ \multiply\count4by-365\relax%
+ \advance\count4by\pgfutil <at> tempcnta\relax%
+ % .. + L:
+ \advance\count4by\count3\relax%
+ % 4) week number = d1/7+1
+ #2=\count4\relax%
+ \divide#2by7\relax%
+ \advance#2by1\relax%
+ \expandafter%
+ }%
+ \expandafter#2\the#2\relax%
+}
+
+
+
% Returns the day of week as a number between 0 = Monday and 6 =
% Sunday
%
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
pgf-users mailing list
pgf-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pgf-users