Re: Constructor validation of parameters

2003-07-29 Thread Eugene van der Pijll
Dan Sully schreef:
 To get the beginning and ending times of a month:
 
 2002-12-01 00:00:00
 2002-12-31 23:59:59
 
 How would one do this with = 0.13 releases?

TIMTOWTDI:

my $dt2 = DateTime-new( month = $month, year = 2002)
  -add( months = 1 )
  -truncate( to = 'month' )
  -subtract( seconds = 1 );

my $dt3 = DateTime-last_day_of_month( month = $month, year = 2002)
  -add( days = 1, seconds = -1 );

But note that the month of December does not end at 2002-12-31T23:59:59!
It doesn't even end at 2002-12-31T23:59:59.9, the last moment in
2002 that DateTime can represent. The ending time of 2002-12 is
2003-01-01T00:00:00.

Eugene


Re: Constructor validation of parameters

2003-07-29 Thread Dave Rolsky
On Tue, 29 Jul 2003, Dan Sully wrote:

 0.13 2003-05-05

 [ IMPROVEMENTS ]

 - DateTime now does more validation of parameters given to
   constructors and to the set() method, so bogus values like a month of
   13 are a fatal error.

 I'm not entirely sure I'd call this an improvement.

This has been beaten to death in the archives, but once again for the
record, it's going to stay like this.

 my $month = 12;

 my $dt1 = DateTime-new('month' = $month, 'year' = 2002);

 print join(' ', $dt1-ymd(), $dt1-hms()) . \n;

 

 my $dt2 = DateTime-new('month' = $month + 1, 'year' = 2002, 'second' = 
 -1);

 print join(' ', $dt2-ymd(), $dt2-hms()) . \n;

 To get the beginning and ending times of a month:

 2002-12-01 00:00:00
 2002-12-31 23:59:59

 How would one do this with = 0.13 releases?

 my $dt1 = DateTime-new( month = $month, year = 2002 );

 my $dt2 = $dt1-clone-add( months = 1 )-subtract( seconds = 1 );

There are several variations on the above that'd work.

 This seems like useful functionality to me.

No, it seems like a way to encourage people to write really weird code
that doesn't really demonstrate their _intent_.  The next person after you
to read the code you posted will be sitting there think second = -1,
WTF?.  If they read the code above, they'll think datetime math, ok.


-dave

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


Re: Constructor validation of parameters

2003-07-29 Thread Dan Sully
* Eugene van der Pijll [EMAIL PROTECTED] shaped the electrons to say...

 TIMTOWTDI:
 
 my $dt2 = DateTime-new( month = $month, year = 2002)
   -add( months = 1 )
   -truncate( to = 'month' )
   -subtract( seconds = 1 );
 
 my $dt3 = DateTime-last_day_of_month( month = $month, year = 2002)
   -add( days = 1, seconds = -1 );

Which yield 

2002-12-01 00:00:-01
2003-01-01 00:00:-01

respectivly. Not quite correct.

-D
-- 
It's the wrong trousers Gromit, and they've gone wrong!


Re: Constructor validation of parameters

2003-07-29 Thread Dave Rolsky
On Tue, 29 Jul 2003, Dan Sully wrote:

 * Dave Rolsky [EMAIL PROTECTED] shaped the electrons to say...

   my $dt1 = DateTime-new( month = $month, year = 2002 );
 
   my $dt2 = $dt1-clone-add( months = 1 )-subtract( seconds = 1 );
 
  There are several variations on the above that'd work.

 Which yet again yields: 2003-01-01 00:00:-01

 Sorry for not reading the archives. I have no problem using something else
 (this is new code anyways, and it seemed intuitive to me, if a bit wierd.)

 All I'm looking for now is something that works.

Well, obviously this is a bug in the DateTime code, as that's not what
_anyone_ would expect as a result, right?


-dave

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


Re: Constructor validation of parameters

2003-07-29 Thread Dave Rolsky
On Tue, 29 Jul 2003, Dan Sully wrote:

 * Dave Rolsky [EMAIL PROTECTED] shaped the electrons to say...

  Well, obviously this is a bug in the DateTime code, as that's not what
  _anyone_ would expect as a result, right?

 Just checking to make sure that I'm not the only anyone here. =)

Ah, looks like a bug in the pure Perl version of the code.

I'll fix it and release a new version soon.


-dave

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


Re: Constructor validation of parameters

2003-07-29 Thread Dan Sully
* Eugene van der Pijll [EMAIL PROTECTED] shaped the electrons to say...

 This solution, OTOH, should work:
 
 my $dt3 = DateTime-last_day_of_month( month = $month, year = 2002)
   -add( days = 1 )
   -subtract( seconds = 1 );
 
 And it does. (DT version 0.1402, perl 5.8.0, linux)

It's broken with 0.1402 under Solaris 8 (SPARC).

Works fine on HP-UX 11.00 and 11i

-D
-- 
Have the appropriate amount of fun.


Re: Constructor validation of parameters

2003-07-29 Thread Dan Sully
* Dave Rolsky [EMAIL PROTECTED] shaped the electrons to say...

 _If_ it can't find finite() or isfinite() macros/functions, a piece that
 can be done in XS is done in Perl (_normalize_tai_seconds).  Are you
 running on Win32 or HPUX?  I know on both those platforms it ends up using
 the Perl version of that method.

It works on HPUX.

Broken on Solaris 8

-D
-- 
Dondi5 I must keep track of all this cheese


Re: Constructor validation of parameters

2003-07-29 Thread Dan Sully
* Dave Rolsky [EMAIL PROTECTED] shaped the electrons to say...

  It's broken with 0.1402 under Solaris 8 (SPARC).
 
  Works fine on HP-UX 11.00 and 11i
 
 Try 0.15

Works great. Thanks for the fast response.

-D
-- 
faisal my life is collapsing to what will soon be NEGATIVE INTEGER degrees of 
separation.