ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Taco Hoekwater <taco@elvenkind.com>
Subject: Re: Week number
Date: Sat, 30 Dec 2006 15:00:24 +0100	[thread overview]
Message-ID: <459670F8.5020106@elvenkind.com> (raw)
In-Reply-To: <45941026$0$4168$ba624c82@nntp02.dk.telia.net>


Hi all,


I just posted this (the result of a rainy morning in Dordrecht, NL)
to comp.text.tex. Someone here might be interested as well.

Best, Taco

-------------

Mads Munch Hansen wrote:
> Hi all, and merry Christmas :)
> 
> Is there a way to have LaTeX print the current week number, like the
> \date command?

I was feeling a bit bored today, so I came up with this. It is a
plain e-TeX input file instead of a LaTeX package, but it should
run without problems.

Watch out: Dec 29 can be week 1 of the next year; and Jan 3 can be
week 53 of the previous year.

Best wishes, Taco


%% calendarweek.tex
%% 2006 (C) Taco Hoekwater, public domain
%%
%%  Usage:
%%   \calendarweek{30}{12}{2006}
%%

\def\Expr#1{\the\numexpr #1\relax}

\def\Modulonumber#1#2{\Expr{#2-((((#2+(#1/2))/#1)-1)*#1)}}
\def\Divisionnumber#1#2{\Expr{(2*#2-#1)/(2*#1)}}

\def\Mod#1#2{\Modulonumber{\Expr{#2}}{\Expr{#1}}}
\def\Div#1#2{\Divisionnumber{\Expr{#2}}{\Expr{#1}}}

\def\Jday#1#2#3%
    {\Expr{#1+\Div{((153*(\Expr{#2+(12*(\Div{14-#2}{12}))-3}))+2)}
     {5}+365*(\Expr{#3+4800-(\Div{14-#2}{12})})+
      (\Div{\Expr{#3+4800-(\Div{14-#2}{12})}}{4})-
      (\Div{\Expr{#3+4800-(\Div{14-#2}{12})}}{100})+
      (\Div{\Expr{#3+4800-(\Div{14-#2}{12})}}{400})-32045 }}

\def\cwhlp#1#2#3%
    {\Expr{\Mod {\Mod {\Mod {\Expr
     {\Jday{#1}{#2}{#3}+31741-\Mod{\Jday{#1}{#2}{#3}}{7}}}%
     {146097}}{36524}}{1461}}}

\def\calendarweek#1#2#3%
  {\Expr{\Expr{\Div{\Expr{\Mod{\cwhlp{#1}{#2}{#3}-
	\Expr{\Div{\cwhlp{#1}{#2}{#3}}{1460}}}{365}+
         \Expr{\Div{\cwhlp{#1}{#2}{#3}}{1460}}}}{7} +1}}}

\endinput

       reply	other threads:[~2006-12-30 14:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <45941026$0$4168$ba624c82@nntp02.dk.telia.net>
2006-12-30 14:00 ` Taco Hoekwater [this message]
2006-12-30 15:51   ` store counter or variable and reread again Thomas Engel
2006-12-30 16:56     ` Aditya Mahajan
2006-12-30 19:19       ` Peter Münster
2006-12-30 21:30         ` Aditya Mahajan
2006-12-30 22:35           ` Hans Hagen
2006-12-30 23:19             ` Aditya Mahajan
2006-12-30 23:51               ` Aditya Mahajan
2006-12-31  8:21                 ` Thomas Engel
2006-12-31 17:52                   ` Aditya Mahajan
2007-01-01 22:28                 ` Hans Hagen
2007-01-01  8:11               ` Peter Münster
2007-01-01 11:17                 ` Aditya Mahajan
2007-01-01 15:35                   ` Peter Münster
2007-01-01 22:14                     ` Hans Hagen
2007-01-02 18:38                       ` Peter Münster
2007-01-04 16:43                         ` Hans Hagen
2006-12-30 21:34   ` Week number Aditya Mahajan
2006-12-30 22:28     ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=459670F8.5020106@elvenkind.com \
    --to=taco@elvenkind.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).