Re: RE: figuring out the number of sundays in a given year

2003-09-21 Thread rickmeasham
Jerry Wilcox [EMAIL PROTECTED] wrote:
 I'm not sure about the count in a year, but
I frequently need to 
 determine how many of a given day of the
week fall in a given month 
 of the year, or, more precisely, given that
today is Saturday, 
 September 20, I need to figure out whether
today is the first, 
 second, third, fourth, or fifth Saturday of
the month. I've worked 
 out code using existing methods to tell me
what I need to know, and 
 I'm not sure that an entirely new method is
warranted here.

Jerry: There's two functionality in the above.

First: How many of a particular DOW are in a
period. This is just a matter of dividing the
total days by seven then adding one if
needed. If a function were added for this,
then I imagine its more a part of
DateTime::Span rather than DateTime itself.

Secondly you ask about getting the weekday of
the month. There's already a function in
DateTime for this:
$dt-weekday_of_month();

Test it with this:
perl -MDateTime -e 'print DateTime-new( year
= 2003, month = 9, day =
20)-weekday_of_month()'



Re: RE: figuring out the number of sundays in a given year

2003-09-21 Thread Joshua Hoblitt
 First: How many of a particular DOW are in a
 period. This is just a matter of dividing the
 total days by seven then adding one if
 needed. If a function were added for this,
 then I imagine its more a part of
 DateTime::Span rather than DateTime itself.

I already said this. :)

 Secondly you ask about getting the weekday of
 the month. There's already a function in
 DateTime for this:
 $dt-weekday_of_month();

Yes - but if we add the above functionality to DT::Span I think we should also have 
weekday_of_span() or a similar method for finding your location relativity to the 
start of the span (and not just the current month).

-J

--


RE: figuring out the number of sundays in a given year

2003-09-20 Thread Jerry Wilcox
At 11:40 PM -0500 9/19/03, Dave Rolsky wrote:
  DateTime-day_count_in_year( year = 1999, day = 4 );
I think this is what was originally meant.

What would people need this info for?

I'm not sure about the count in a year, but I frequently need to 
determine how many of a given day of the week fall in a given month 
of the year, or, more precisely, given that today is Saturday, 
September 20, I need to figure out whether today is the first, 
second, third, fourth, or fifth Saturday of the month. I've worked 
out code using existing methods to tell me what I need to know, and 
I'm not sure that an entirely new method is warranted here.

Jerry
--
Jerry Wilcox - University of California, Office of the President
Manager Payroll/Personnel Services -- Information Resources  Communications
415 20th Street (3rd Floor)
Oakland, CA 94612 -- 510-987-0516 -- FAX 510-763-5597
``The lyf so short, the craft so long to lerne.'' - Chaucer


RE: figuring out the number of sundays in a given year

2003-09-20 Thread Joshua Hoblitt
 I'm not sure about the count in a year, but I frequently need to
 determine how many of a given day of the week fall in a given month
 of the year, or, more precisely, given that today is Saturday,
 September 20, I need to figure out whether today is the first,
 second, third, fourth, or fifth Saturday of the month. I've worked
 out code using existing methods to tell me what I need to know, and
 I'm not sure that an entirely new method is warranted here.

To generalize:

You want to know how many of a given day occur in a range and at what position in that 
range a given datetime is?

This sounds like something that should operate on a DT::Span object.

-J

--


RE: figuring out the number of sundays in a given year

2003-09-20 Thread Bruce Van Allen
On 9/20/03 Joshua Hoblitt wrote:

 I'm not sure about the count in a year, but I frequently need to
 determine how many of a given day of the week fall in a given month
 of the year, or, more precisely, given that today is Saturday,
 September 20, I need to figure out whether today is the first,
 second, third, fourth, or fifth Saturday of the month. I've worked
 out code using existing methods to tell me what I need to know, and
 I'm not sure that an entirely new method is warranted here.

To generalize:

You want to know how many of a given day occur in a range and at what 
position in that range a given datetime is?

This sounds like something that should operate on a DT::Span object.


It's a recurrence set. -count is how many, index in set array (+1) is position.

  - Bruce

__bruce__van_allen__santa_cruz__ca__


Re: figuring out the number of sundays in a given year

2003-09-19 Thread Ron Hill
Hi Dave  Josh,

Dave Rolsky [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Wed, 17 Sep 2003, Hill, Ronald wrote:

[snipped]


 Josh is confused because you're passing arguments to the day_of_week
 method.  These arguments are completely ignored by DateTime.pm!


 -dave
Ok, I see I can just do
my $dow = $dt2-day_of_week(
  year  = $dt-year,
 );

and get what I want, which is the dow for jan 1
Hmn!!
But the questions is should I code like that. Doing  something like this
does not seem very intuitive.

Ron




Re: figuring out the number of sundays in a given year

2003-09-19 Thread RIck Measham
Syamala Tadigadapa wrote:
 Here is a simple solution

... I'd hate to see your complex solution ...

Rick


Re: figuring out the number of sundays in a given year

2003-09-19 Thread Dave Rolsky
On Wed, 17 Sep 2003, Ron Hill wrote:

 Ok, I see I can just do
 my $dow = $dt2-day_of_week(
   year  = $dt-year,
  );

The day_of_week() method DOES NOT TAKE ARGUMENTS!

I don't know what you think the code above does, but I can tell you that
all it does is return the day of the week for the $dt2 objcet, and ignores
everything else.


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/


Re: figuring out the number of sundays in a given year

2003-09-19 Thread Joshua Hoblitt
 The day_of_week() method DOES NOT TAKE ARGUMENTS!

I wonder if it's worth the overhead of checking for extraneous parameters on all 
methods?

-J

--


Re: figuring out the number of sundays in a given year

2003-09-19 Thread Dave Rolsky
On Fri, 19 Sep 2003, Joshua Hoblitt wrote:

  The day_of_week() method DOES NOT TAKE ARGUMENTS!

 I wonder if it's worth the overhead of checking for extraneous
 parameters on all methods?

I'd rather try to keep accessors as quick as possible.


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/


Re: figuring out the number of sundays in a given year

2003-09-17 Thread Joshua Hoblitt
Hi Ron,

I'm a bit confused by your parameters to day_of_week().

This is the actual implementation from DateTime.pm

sub day_of_week { $_[0]-{local_c}{day_of_week} }

-J

--
 script=

 use strict;
 use warnings;
 use DateTime;

 my $dt = DateTime-new( year = 2001 );
 my $num = number_of_sundays($dt);
 print $num;

 sub number_of_sundays {

 my ($dt) = @_;
 my $dt2 = $dt-clone();

 if ( $dt-is_leap_year ) {

 my $dow = $dt2-day_of_week(
   year  = $dt-year,
   month = 1,
   day   = 1,
 );
 return 53 if ( $dow == 7 or $dow == 6 );

 }
 else {

 my $dow = $dt2-day_of_week(
   year  = $dt-year,
   month = 1,
   day   = 1,
 );
 return 53 if ( $dow == 7 );
 }

 return 52;
 }



RE: figuring out the number of sundays in a given year

2003-09-17 Thread Hill, Ronald
Hi Josh,

 
 Hi Ron,
 
 I'm a bit confused by your parameters to day_of_week().
 
 This is the actual implementation from DateTime.pm
 
 sub day_of_week { $_[0]-{local_c}{day_of_week} }
 
 -J
 

I compute the number of days in the current year 
I figure out the day of week for january the first
and if this is (365 days in the year and Sunday or 7 in datetime) or
(Saturday 
6 in datetime or Sun and a leap year)  then I return 53 sundays as the
number of sundays
else  I return 52 as the number of sundays.

I checked the docs for datetime and used them
F:\scriptsperldoc DateTime|grep day_of_week
File STDIN:
  $dow= $dt-day_of_week;   # 1-7 (Monday is 1) - also dow, wday
_0. So for example, this class provides both day_of_week() and
day_of_week_0() methods.
The day_of_week_0() method still treats Monday as the first day of the
* day_of_week, wday, dow

Am I missing something?

Thanks

Ron Hill


RE: figuring out the number of sundays in a given year

2003-09-17 Thread Dave Rolsky
On Wed, 17 Sep 2003, Hill, Ronald wrote:

 I checked the docs for datetime and used them
 F:\scriptsperldoc DateTime|grep day_of_week
 File STDIN:
   $dow= $dt-day_of_week;   # 1-7 (Monday is 1) - also dow, wday
 _0. So for example, this class provides both day_of_week() and
 day_of_week_0() methods.
 treats Monday as the first day of the
 * day_of_week, wday, dow

 Am I missing something?

Josh is confused because you're passing arguments to the day_of_week
method.  These arguments are completely ignored by DateTime.pm!


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/


Re: figuring out the number of sundays in a given year

2003-09-17 Thread Syamala Tadigadapa
Here is a simple solution (unless you  are bent on doing it in a longer way 
using a date time class.)

sub jan1{
 my $y =  shift;
 my $m = 1; $d = 1;
 $m = 11; $y--;
 my $c = int($y / 100); $yy = $y %100;
 my $z = ( 1 + $yy + int($yy/4) + int($c/4) - 2*$c) % 7;
 $z += 7 if $z  0;
 return $z;   # 0 == Sun day.  6 == Sat. day.
}
sub sundays{
my $year = shift;
my $j1st = jan1($year);
return 53 if $j1st == 0 || ($j1st == 6  jan1($year+1) == 1);
   return 52;
}
_
Try MSN Messenger 6.0 with integrated webcam functionality! 
http://www.msnmessenger-download.com/tracking/reach_webcam