Paul Miller

NAME

Date::Lima - A time interval format (2d4h1m4s) like convert_time() from Lima mudlib.

SYNOPSIS

    use Date::Lima qw/beek_date/;

    my $d1 = beek_date( "127:34" ); # 1h40m
    my $d2 = beek_date("2:46:40" ); # 2h46m40s
    my $d3 = beek_date( 7654321 );  # 2mo4w14h12m1s

    my $ds = rev("9h22m5s"); # 33_725

beek_date()

beek_date() takes a single argument. The argument can be a number of seconds, an hours-minutes string, or an hours-minutes-seconds string.

rev() interval2seconds()

rev() (aka interval2seconds()) does the reverse of beek_date(): converts interval format back to seconds.

TUNING CONVERSIONS

There are a few pre-built conversions you can use, but you can also fine tune this as much as you like.

    # bring in all the conversion methods along with beek_date():

    use Date::Lima qw(:all);
nomonth_conversions()

Disable the 'mo' time units.

    nomonth_conversions();

    my $d4 = beek_date( 7654321 );  # 12w4d14h12m1s
weeklargest_conversions()

Disable both the year and the month conversions.

    weeklargest_conversions();

    my $d5 = beek_date( 7654321 );  # 12w4d14h12m1s
daysmallest_conversions()

Ignore the hours, minutes and seconds

    daysmallest_conversions();
    my $days = beek_date(86400*32 + 3600*12 + 77); # 1mo2d
sidereal_conversions()

Use the sidereal year length as an important unit for y and mo.

    my $sidereal_year  = 365.256_363_051 * 24 * 60 * 60;
    my $sidereal_month = $sidereal_year / 12;

    @conversions = (
        [  y => $sidereal_year  ],
        [ mo => $sidereal_month ],

        [  w => 7*24*60*60 ],
        [  d =>   24*60*60 ],
        [  h =>      60*60 ],
        [  m =>         60 ],
    );
default_conversions()

You do not normally need to run this. It's handy for putting things back they way they were.

    daysmallest_conversions();
    my $days = beek_date(86400*32 + 3600*12 + 77); # 1mo2d

    default_conversions();
    my $interval = beek_date(86400*32 + 3600*12 + 77); # 1mo2d12h1m17s
@Date::Lima::conversions

There will obviously be some disagreement about how long a "week" or a "month" is. You can define your own in this way:

    @Date::Lima::conversions = (
        [ d => 86400 ], # days are 86400 seconds
        [ E => 1337 ], # elite time unit
        [ m => 60 ], # minutes are 60 seconds
        [ s => 1 ], # seconds are 1 second
    );

    my $weird = beek_date( 7777777 ); # 90d1E7m20s

This will not work right unless the largest units are first. It's up to you to make sure they're ordered largest to smallest.

AUTHORS

<dorn@bakhara.org> -- Updated, maintained and republished this module.

<nichus@bakhara.org> -- Wrote the initial version.

This module is now being maintained by Paul Miller <jettero@cpan.org>.

COPYRIGHT

Copyright 1997-2009 Dorn, Nichus, Paul Miller, Orien Vandenburg -- licensed under LGPL

NOTE

"convert_time()" was technically written by cowl originally, but it exists in its present form because of beek. Also, this pseudo-historical information goes back to about 1990. Seems like yesterday.

SEE ALSO

perl(1).