[Omaha.pm] Class::Date truncate()

Jay Hannah jhannah at omnihotels.com
Thu Dec 29 11:15:13 PST 2005


Used Class::Date's truncate() for the first time today. 

print $arrival;  # 2005-11-07 12:57:39
print $depart;   # 2005-12-21 00:00:00
print ($depart - $arrival)->day;  # 43.4599652777778

Whoah. We only deal in integer lengths of stay ("how many nights is the
guest staying?"), so that fraction is interesting, but unhelpful. 

Call truncate() on your Class::Date objects and the time drops away.

$arrival = $arrival->truncate;    # 2005-11-07 00:00:00
$depart = $depart->truncate;      # 2005-12-21 00:00:00
print ($depart - $arrival)->day;  # 44

j



More information about the Omaha-pm mailing list