RFC: Date::EzDate 
Author Message
 RFC: Date::EzDate

EzDate was motivated by a desire to encapsulate all properties and
methods for date calculations into a single easy-to-use-object with
easy-to-understand properties. An EzDate object represents a single
point in time and exposes all properties of that point such as hour,
minute, day of month, weekday, days since the epoch, days in the
month, etc.

The real power of EzDate is that you can assign to (almost) any of
those properties and EzDate will automatically rework the other
properties to produce a new valid date with the property you just
assigned.  Properties that can be kept the same with the new value
aren't changed, while those that logically must change to accomodate
the new value are recalculated.  For example, incrementing epochday
(number of days since the epoch) by one (thereby moving the date
forward one day) does not change the hour or minute but does change
the day of week.

POD and source are avilable at
http://www.*-*-*.com/

I'm waiting to find out if I can use the namespace Date::EzDate.  Once
I have a namespace I'll post EzDate to CPAN.

The inevitable question is "why not use Date::Manip?".  My own answer
is that I have just never found Date::Manip's interface intuitive.
Obviously that's a subjective argument, but for example, here's
Date::Manip's own suggested routine for finding out which is the later
of two dates:

  $date1=&ParseDate($string1);
  $date2=&ParseDate($string2);
  $flag=&Date_Cmp($date1,$date2);

  if ($flag<0) {
    # date1 is earlier
  } elsif ($flag==0) {
    # the two dates are identical
  } else {
    # date2 is earlier
  }

It just doesn't seem intuitive to me that to compare two dates you
need a special routine and a place to store its results.  Here's how
you'd do it in EzDate:

  $date1=Date::EzDate->new($string1);
  $date1=Date::EzDate->new($string2);

  if ($date1->{'epochsec'} < $date2->{'epochsec'}) {
    # date1 is earlier
  } elsif ($date1->{'epochsec'} == $date2->{'epochsec'}) {
    # the two dates are identical
  } else {
    # date2 is earlier
  }

I find the EzDate version easier to understand because I can see what
I'm working with: epochsec.  If I wanted to know if they are on the
same day, but don't care if they're the same hour:min:sec, the code is
almost the same... we just work with a different granularity:

  if ($date1->{'epochday'} < $date2->{'epochday'}) {
    # date1 is earlier
  } elsif ($date1->{'epochday'} == $date2->{'epochday'}) {
    # the two dates are on the same day
  } else {
    # date2 is earlier
  }

I have similar reasons for not using the other Date:: modules: they
just seem so complicated.

EzDate has many features.  Here are a few:

 use Date::EzDate;
 my $mydate = Date::EzDate->new('April 11 2001, 9:06:26 am');

 # output some date information
 print $mydate->{'full'}, "\n";  # e.g. output:  09:06:26 Wed Apr 11,
2001

 # go to next day
 $mydate->{'epochday'}++;

 # go to Monday of same week, but be lazy and don't spell out
 # the whole day or case it correctly
 $mydate->{'weekdaylong'} = 'MON';

 print $mydate->{'full'}, "\n";  # e.g. output:  09:06:26 Mon Apr 09,
2001

 # go to previous year
 $mydate->{'year'}--;

 print $mydate->{'full'}, "\n";  # e.g. output:  09:06:26 Sun Apr 09,
2000

-Miko



Tue, 20 Apr 2004 07:01:26 GMT  
 RFC: Date::EzDate

Quote:

> EzDate was motivated by a desire to encapsulate all properties and
> methods for date calculations into a single easy-to-use-object with
> easy-to-understand properties. An EzDate object represents a single
> point in time and exposes all properties of that point such as hour,
> minute, day of month, weekday, days since the epoch, days in the
> month, etc.

> The real power of EzDate is that you can assign to (almost) any of
> those properties and EzDate will automatically rework the other
> properties to produce a new valid date with the property you just
> assigned.  Properties that can be kept the same with the new value
> aren't changed, while those that logically must change to accomodate
> the new value are recalculated.  For example, incrementing epochday
> (number of days since the epoch) by one (thereby moving the date
> forward one day) does not change the hour or minute but does change
> the day of week.

> POD and source are avilable at
> http://www.idocs.com/cgi-bin/pt2/showpod.pl?id=2753980254

> I'm waiting to find out if I can use the namespace Date::EzDate.  Once
> I have a namespace I'll post EzDate to CPAN.

> The inevitable question is "why not use Date::Manip?".  My own answer
> is that I have just never found Date::Manip's interface intuitive.
> Obviously that's a subjective argument, but for example, here's
> Date::Manip's own suggested routine for finding out which is the later
> of two dates:

[...]

> It just doesn't seem intuitive to me that to compare two dates you
> need a special routine and a place to store its results.  Here's how
> you'd do it in EzDate:

>   $date1=Date::EzDate->new($string1);
>   $date1=Date::EzDate->new($string2);

>   if ($date1->{'epochsec'} < $date2->{'epochsec'}) {
>     # date1 is earlier
>   } elsif ($date1->{'epochsec'} == $date2->{'epochsec'}) {
>     # the two dates are identical
>   } else {
>     # date2 is earlier
>   }

I think if you want simple usage, then Date::Calc::Object is the way
to go. There <, >, == are overloaded, so you can use just

    $date1 < $date2    # compares date only

or

    $date1 lt $date2   # compares date and time

Regards,
        Slaven

--

    BBBike - Routenplaner fr Radfahrer in Berlin
    WWW version:     http://www.bbbike.de
    Perl/Tk version: http://bbbike.sourceforge.net



Tue, 20 Apr 2004 17:06:52 GMT  
 RFC: Date::EzDate

Quote:

> EzDate was motivated by a desire to encapsulate all properties and
> methods for date calculations into a single easy-to-use-object with
> easy-to-understand properties. An EzDate object represents a single
> point in time and exposes all properties of that point such as hour,
> minute, day of month, weekday, days since the epoch, days in the
> month, etc.

There's a *wealth* of OO date/time modules on CPAN that do all that
"EzDate" does and probably more. Off the top of my head:

Date::Calc::Object
Time::Piece/Time::Object
Class::Date

etc.



Fri, 23 Apr 2004 20:21:10 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ANN: Date::EzDate 1.02

2. ANNOUNCE: Date::EzDate

3. RFC: How to name date objects module?

4. RFC: How to name date objects module?

5. RFC: Math::Date and Math::Currency

6. RFC Date

7. RFC: Yet another date/time manipulation package

8. rfc date conversion

9. RFC: How to name date objects module?

10. Need program to calculate dates between 2 dates

11. Where are the Date::Parse and Date::Format pm's located

12. How to date/time convert to numeric date format in DOS perl

 

 
Powered by phpBB® Forum Software