- TUNING CONVERSIONS
- SEE ALSO
Date::Lima - A time interval format (2d4h1m4s) like convert_time() from Lima mudlib.
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() takes a single argument. The argument can be a number of seconds, an hours-minutes string, or an hours-minutes-seconds string.
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(); my $d4 = beek_date( 7654321 ); # 12w4d14h12m1s
Disable both the year and the month conversions.
weeklargest_conversions(); my $d5 = beek_date( 7654321 ); # 12w4d14h12m1s
Ignore the hours, minutes and seconds
daysmallest_conversions(); my $days = beek_date(86400*32 + 3600*12 + 77); # 1mo2d
Use the sidereal year length as an important unit for
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 ], );
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
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.
<email@example.com> -- Updated, maintained and republished this module.
<firstname.lastname@example.org> -- Wrote the initial version.
This module is now being maintained by Paul Miller
Copyright 1997-2009 Dorn, Nichus, Paul Miller, Orien Vandenburg -- licensed under LGPL
"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.