[lug] Perl days/dates

Atkinson, Chip CAtkinson at Circadence.com
Wed Nov 15 09:14:23 MST 2000


My ultimate goal is to make a table on a web page that resembles a calendar
that extends from the current day back 30 days.  I need to find what day of
the week that start day is.  

> -----Original Message-----
> From: Tkil [mailto:tkil at scrye.com]
> Sent: Tuesday, November 14, 2000 8:13 PM
> To: lug at lug.boulder.co.us
> Subject: Re: [lug] Perl days/dates
> 
> 
> 
> um.  may i ask again exactly what you're trying to do?  :)
> 
> given this description:
> >>>>> "Chip" == Atkinson, Chip <CAtkinson at Circadence.com> writes:
> 
> Chip> I'm writing a perl script to figure out the day of the week
> Chip> based on a given date.  The numeric value for the day of the
> Chip> week seems rather odd in that the week starts with Friday.  Does
> Chip> anyone know about this?  Here's the script in its entirety.
> 
> Chip> use vars qw (@months @days $i);
> Chip> use vars qw ($sec $min $hours $mday $mon $year);
> Chip> use vars qw ($TIME $WEEKDAY @datestuff);
> 
> why not just use "my"?  and, on a stylistic note, i prefer to declare
> at point of use...

Because I'm more or less self-taught :-)  There is no compelling reason
other than that.

> 
> Chip> @days = ("Fri", "Sat",
> Chip>          "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
> 
> as efm pointed out, this is weird.
> 
> you can either use the sane interface to timelocal and localtime, or
> if you insist on abusing things, take a look at
> 
>    http://slinky.scrye.com/~tkil/perl/Weekday.pm

That is pretty cool.  I might have to use it.

> 
> a version using Time::Local and localtime might look like:
> 
>    sub day_of_week
>    {
>      my ($year, $month, $day) = @_;
> 
>      $year  -= 1900;
>      $month -= 1;
> 
>      my $time_t = timelocal(0, 0, 0, $day, $month, $year);
> 
>      my ($dow) = (localtime($time_t))[6];
>      return $dow;
>    }
> 
> depending on how flexible you need to be about date parsing, you might
> also look at the CPAN modules Date::Parse, Date::Calc, and Date::Manip
> (all of which have different strengths, quite a bit of overlap, and
> might be more than you need in this case).

I'm trying to avoid additional modules if possible so there's less stuff
that the QA people have to deal with installing on their boxes.

> 
> can you describe your actual need more clearly?

Hopefully I was able to do that above.  After playing with it a bit more
last night I think that there must be some strange error on my part, and I'm
investigating it a bit more right now.  

Thanks for the help.  I'll post what the problem was if I find it.

> 
> t.
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> 




More information about the LUG mailing list