Skip Menu |

This queue is for tickets about the Date-Manip CPAN distribution.

Report information
The Basics
Id: 102747
Status: resolved
Priority: 0/
Queue: Date-Manip

People
Owner: Nobody in particular
Requestors: EDAVIS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: + -2 hours
Arithmetic in Perl (and other languages) allows a unary minus, e.g. % perl -E 'say 10 + -2' 8 However this isn't accepted by DateCalc: % perl -MDate::Manip -E 'say DateCalc("now", "+ -2 hours")' It should allow unary + and - on the right hand side of the binary + or - operator. This would be particularly useful when generating the calculation: DateCalc($d, "+ $h hours") where $h might be positive or negative. I understand that it works to omit the leading +, but I suggest the explicit + is a bit clearer, and if it can be given some of the time it should work all of the time.
I think I'm not yet convinced that your argument applies. If I were overloading operators, then I agree that something like this should be valid: $date1 = ... $delta = ... $date2 = $date1 + -$delta; However, that's not the format here. Let's say you wanted to implement the '+' operator as a function. Would you allow the following? $result = add(10,'+ -2'); Although it's easy to understand what you mean, I don't think that you would choose to do so. In this context, both arguments should be valid numbers, and I don't believe that '+ -2' is a valid number any more than '+ -2 hours' is a valid delta.