I don't have a 'semi-exact' mode in Date::Manip... but what you're really saying is: convert an exact delta to a semi-approximate one.
This is of course different from coming up with an semi-approximate delta from two dates (which is what I was doing... I should have noticed that it wasn't exactly what the OP was doing, but I got ahead of myself after noticing I couldn't use 'semi' mode in the older DateCalc).
In any case, you can do the following:
use Date::Manip;
my $dt1='2016080100:00:00';
my $dt2='2016123100:00:00';
my $exact= DateCalc($dt1,$dt2);
my $semi = DateCalc($dt1,$dt2,'semi');
print "Exact : $exact\n";
print "Semi : $semi\n";
my $delta = ParseDateDelta($exact,'semi');
print "Exact->Semi: $delta\n";
print "\n";
use Date::Manip::Date;
my $date1 = new Date::Manip::Date;
my $date2 = $date1->new_date();
$date1->parse($dt1);
$date2->parse($dt2);
my $delt_x = $date1->calc($date2);
my $delt_s = $date1->calc($date2,'semi');
my $val = $delt_x->value();
print "New Exact : $val\n";
$val = $delt_s->value();
print "New Semi : $val\n";
$delt_x->convert('semi');
$val = $delt_x->value();
print "New Ex->Se: $val\n";
which yields:
Exact : 0:0:0:0:3649:0:0
Semi : 0:0:21:5:0:0:0
Exact->Semi: 0:0:21:5:1:0:0
New Exact : 0:0:0:0:3649:0:0
New Semi : 0:0:21:5:0:0:0
New Ex->Se: 0:0:21:5:1:0:0
So you can see how to convert an exact delta to a semi-approximate one using either the old or new interfaces.
|