You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to subtract a period object created by hms() from another I find it gives faulty results. Searching to see if I had misused period subtraction I found this post on Stackoverflow by Dirk Eddelbuettel which seems to suggest that subtraction of periods is legit.
Example of expected correct result when the subtrahend is less than the minuend:
Perhaps it would be easier to understand and use if there was a default automatic rollover from seconds -> minutes -> hours when doing additions and subtractions like when you construct a period using hms(...,roll=TRUE).
Here is another situation but somewhat contrived. Since lubridate can create hms/period objects with a greater amount of HH:MM:SS than the conventional 23:59:59 another subtraction inconsistency as compared to addition arises:
and then the overflow seconds can be corrected by adding another hms() call, although somewhat inconveniently in comparison to the otherwise sleek syntax in lubridate:
You seem to be bothered mostly by negative components which are there to accommodate negative periods. In your last example hms("13:15:15") - hms("14:25:95") needs to be negative. So in order to "fix" your problem one would need to check if the period is negative in absolute sense and convert all components to negatives or positives accordingly. This might work for hms parts but not for large periods that include months and years. So, when you roll do you stop at days, weeks or go further to months and years? Add to this the extra computational burden on every operation and it simply becomes way too much trouble for little bang.
Note that your problem is primarily about presentation. All arithmetic operations will work just fine on those because they represent the same period.
As to the final NA and warning, it's a misuse of hms which is a parsing function. The outer call converts to character and then parses them back. It might be a bug in the parser though. I will check.
Hi!
When I try to subtract a period object created by hms() from another I find it gives faulty results. Searching to see if I had misused period subtraction I found this post on Stackoverflow by Dirk Eddelbuettel which seems to suggest that subtraction of periods is legit.
Example of expected correct result when the subtrahend is less than the minuend:
Unclear result when subtracting and the minute or second subtrahend part is greater than the minuend:
while "correct" it would be much nicer if the result of the subtraction as with addition is expressed as
another example
where you would expect
[1] "44M 45S"
Perhaps it would be easier to understand and use if there was a default automatic rollover from seconds -> minutes -> hours when doing additions and subtractions like when you construct a period using hms(...,roll=TRUE).
Here is another situation but somewhat contrived. Since lubridate can create hms/period objects with a greater amount of HH:MM:SS than the conventional 23:59:59 another subtraction inconsistency as compared to addition arises:
Addition is ok:
and then the overflow seconds can be corrected by adding another hms() call, although somewhat inconveniently in comparison to the otherwise sleek syntax in lubridate:
with subtraction:
In any case, I would like to thank you so much for lubridate which has made working with dates and times so much easier!
The text was updated successfully, but these errors were encountered: