develooper Front page | perl.datetime | Postings from January 2003

Re: Picking up the ball

Thread Previous | Thread Next
Dave Rolsky
January 13, 2003 11:41
Re: Picking up the ball
Message ID:
On Mon, 13 Jan 2003, Jean Forget wrote:

> > If it is renamed to DateTime::Calendar::FrenchRevolution, it'll have to
> > deal with hhmmss.  It's that simple.
> Well, it is not *that* simple. In addition to creating a new
> calendar, Fabre d'Eglantine and Romme changed the duration of
> the hour, minute and second, so each day would be split into
> 10 hours, each hour into 100 minutes and each minute into 100
> seconds. Which unit should my module deal with?
> "Anglo-Babylonian" sexagesimal second or decimal second?

When I say it has to "deal with hhmmss", I mean you have to be prepared to
convert from the standard representation (probably rata die) days/seconds
to _your_ representation of days/seconds.  So if you wrote
DateTime::Calendar::FrenchRevolution, you'd offer a method called ->hour
(or maybe ->fr_hour to really distinguish from A-B hours), that'd return
the French Revolution hour for the datetime in question.

No DateTime::Calendar module will be required to offer an explicit
conversion to Gregorian, and in fact I'd strongly _discourage_ this.  If a
user wants to know the Gregorian equivalent for a FR datetime, they create
a Gregorian object _from_ the FR object.  Here's some example code:

  my $dt = DateTime->new( year => 1789, month => 7, day => 14,
                          hour => 12 );

  my $fr_dt = DateTime::Calendar::FrenchRevolution->from_object( $dt );

  $fr_dt->set( hour => 6 ); # that's a FR hour!

  my $new_dt = DateTime->from_object( $fr_dt );

  # sometime after noon on 1789-07-14

Does that make sense?

Internally, DateTime::Calendar::FrenchRevoluion might do this:

  sub from_object
      my ( $class, $dt ) = @_;

      die "Vive la revolution!" unless $dt->can('rata_die');

      my $self = bless {}, $class;

      @{ $self }{ 'rd_days', 'rd_seconds', 'rd_nanoseconds' } = $dt->rata_die;

      return $self;

  sub hour
      my $self = shift;

      # convert from RT seconds to FR hour

      return $hour;

Piece o' cake ;)


House Absolute Consulting

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About