in reply to ISO Date Week Number

Hi,

I can see at least two possible ways here:
  1. some code I found by googling:
    Use some code like the following (found here: http://www.merlyn.demon.co.uk/programs/what-cw.pl):
    #!/usr/local/bin/perl if (@ARGV != 3) { print "usage: $0 <day> <month> <year>\n"; exit; } ($day, $month, $year) = @ARGV; ($cw, $y) = calendarWeek($day, $month, $year); print "CW = $cw (in year $y)\n"; exit; #===================================================================== += # subroutines #===================================================================== += #--------------------------------------------------------------------- +- # julianDay() # # calculates the Julian Day, as described in the "Calendar FAQ" # (http://www.pauahtun.org/CalendarFAQ/cal/calendar24.html, section 2. +15.1) # #--------------------------------------------------------------------- +- sub julianDay { my ($day, $month, $year) = @_; my ($a, $y, $m); $a = int((14 - $month)/12); $y = $year + 4800 - $a; $m = $month + 12 * $a - 3; my $jd = $day + int((153 * $m + 2)/5) + 365 * $y + int($y/4) - int($y/100) + int($y/400) - 32045; return $jd; } #--------------------------------------------------------------------- +- # calendarWeek() # # returns an array consisting of calendar-week and year, where year # is the year in which the calendar-week actually falls #--------------------------------------------------------------------- +- sub calendarWeek { my ($day, $month, $year) = @_; my $jd = julianDay($day, $month, $year); my($d1, $d4, $l); $d4 = ($jd + 31741 - ($jd % 7)) % 146097 % 36524 % 1461; $l = int($d4/1460); $d1 = (($d4 - $l) % 365) + $l; my $cw = int($d1/7) + 1; if (($month == 1) && ($cw > 51)) { $year--; } elsif (($month == 12) && ($cw == 1)) { $year++; } return ($cw, $year); }
  2. Install modules somewhere, where you have write access, for example in your homedirectory or somewhere else. You then just need to tell your Perl program where to find those modules:
    1. Get the module (e.g. Date::Calc) from CPAN, untar it into a temporary folder and cd into the directory
    2. Issue the following commands:
      % perl Makefile.PL PREFIX=/home/USERNAME/perl-site # set your path acc +ordingly % make % make test % make install % make clean
    3. then, at the beginning of your program, "add" the module to your Perl distribution by adding the following line:
      use lib qw( /home/USERNAME/perl-site );
    hth,
    Sven