ANNOUNCE: DateTime 0.1702

2003-09-18 Thread Dave Rolsky
0.1702  2003-09-18

- Added truncate( to => 'week' ).  Suggested by Flavio Glock.



-dave

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


Re: Some examples for the FAQ

2003-09-18 Thread Dave Rolsky
On Sat, 13 Sep 2003 [EMAIL PROTECTED] wrote:

> > For example, the Wednesday of the current week is:
> >
> >  my $today = DateTime->today;
> >
> >  my $wednesday = $today - ( $today->day_of_week - 3 );
>
> How about adding a 'week' parameter
> to the 'truncate' method:
>
>   print DateTime->today
> ->truncate( to => 'week' )
> ->add( days => 2 )->ymd;

An excellent idea, especially since I just realized I need this for
something else I'm working on ;)


-dave

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


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

2003-09-18 Thread Flavio S. Glock
Hill, Ronald wrote:
> 
> > sub jan1{
> >  my $y =  shift;
> >  my $m = 1; $d = 1;
>   ^^
> why is that there? and I don't understand why you set $m to 1
> and then set it to 11?
> 
> >  $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.
> >}

More info here:

  http://www.merlyn.demon.co.uk/zeller-c.htm

  http://www.cpan.org/scripts/date_and_time/zeller.date.pl

- Flavio S. Glock


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

2003-09-18 Thread Hill, Ronald
Hi Syamala,


> Here is a simple solution (unless you  are bent on doing
> it in a longer way using the class in ref.)

The project I have started on is using DateTime for other things, so I 
figured I would use it here as well. Besides I don't think what I 
wrote is doing it the long way, granted I did screw up by passing
in params to a method that was ignoring it. But I still got
what I wanted. 

> sub jan1{
>  my $y =  shift;
>  my $m = 1; $d = 1;
  ^^
why is that there? and I don't understand why you set $m to 1
and then set it to 11?

>  $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;
>}

Ron Hill


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

2003-09-18 Thread Dave Rolsky
On Thu, 18 Sep 2003, Syamala Tadigadapa wrote:

> Here is a simple solution (unless you  are bent on doing it in a longer way
> using a date time class.)

Yeah, because letting others do the repeated work for you would be silly.

> 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.
> }

Into how many projects will you copy this code?  And it's not even
well-factored!  At least take the leap year part and put it in a separate
subroutine.  Or let me guess, that'd decrease performance too much?


-dave

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