Dave Rolsky wrote:
This seems like something that'd be a nice add-on constructor for DateTime.pm. Maybe we need some DateTime::Constructor::* modules or something, because I sure don't want dozens of constructors in the core code.

We *are* missing a namespace but I'm not sure that it's ::Constructor:: .. this problem seems similar to the GPS one. I started playing with that the other day, and couldn't work out where if fit:

1. ::Format:: These modules are for inputting datetimes in a string format and retrieving them in the same format. The GPS format is just a different way of representing dates (in weeks and seconds since a given epoch)
2. ::Calendar:: These are for non-Gregorian datetimes. GPS is gregorian.
3. ::Event:: A gps datetime isn't an event

So now I come back to DateTime::Decorated that I started back in June to deafening silence... Unless I get any objections I'll get it ready to go, and release GPS and WeekConstructor at the same time.

my $DateTimeGPS = DateTime::Decorated( with => 'GPS' );

my $dt = $DateTimeGPS->from_gps( week => 87, second => 23456 );

# Internally, this is a standard DateTime, but the decorator has
# given us a new constructor. Likewise, we now have extra accessors:

print $dt->gps_week;   # 87
print $dt->gps_second; # 23456

# and a couple of setters:

$dt->set_gps_week( 88 );
$dt->set_gps_second( 0 );

SIMILARLY:

my $DateTimeWeek = DateTime::Decorated( with => 'WeekConstructor' );

my $dt = $DateTimeWeek->from_week( year => 2005, week => 48 );

AND COMBINING TOO

my $DateTime2 = DateTime::Decorated(with => ['GPS', 'WeekConstructor']);

my $dt = $DateTime2->from_week( year => 2005, week => 48 );

print join('G', $dt->gps_week, $dt->gps_second);

__END__

Cheers!
Rick Measham


--
 "War is God's way of teaching Americans geography."
                             -- Ambrose Bierce

Reply via email to