[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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