On 2 Sep 2004, at 2:21 PM, Dave Rolsky wrote:
On Thu, 15 Jul 2004, Michael G Schwern wrote:
How do I get the DateTime::Format modules to return My::DateTime objects
instead of DateTime?

Doesn't look like anyone ever responded. There is no way to do this currently. You can always just jam the method into the DateTime namespace. That's pretty ugly though.

I guess we could make all the DT::Format modules take a class parameter.

But isn't My::DateTime just another DateTime::Calendar::* really?

It'd be really ugly to do stuff like:
  $dt = $strptime->parse_datetime( $string, asa => 'My::DateTime' );

So you should do it yourself:
  $dt = My::DateTime->from_object(
    $strptime->parse_datetime( $string )
  );

The :Format modules should honor My::DateTime when given them though. (he says, hoping his do)
$http->format_datetime(
My:DateTime->now()
);




The thing that I think that needs to be addressed more is the ability to subclass DateTime and DateTime::Duration. Both have ->isa() in them rather than ->can().

  sub _add_overload
    ....
    if ( UNIVERSAL::isa( $d2, 'DateTime' ) ) {
        $d2->add_duration($d1);
        return;
    }


Should be *something* like: sub _add_overload .... if ( $d2->can('add_duration') ) { $d2->add_duration($d1); return; }


(That's not a patch. I haven't tried it. It's just the concept)
If changes like that were made, then you could subclass DateTime and still have it interact correctly with DT:D


Cheers!
Rick



Senior Developer
PrintSupply - Print Procurement & Supply Management
18 Greenaway Street VIC 3105
Tel: (03) 9850 3255
Fx: (03) 9850 3277
http://www.printsupply.com.au/




Reply via email to