brick / date-time

Date and time library for PHP
MIT License
337 stars 30 forks source link

Negative Duration #72

Closed solodkiy closed 1 year ago

solodkiy commented 1 year ago

Right now value in Duration object could be negative. (-1 sec)

I don't really get this concept (negative duration, negative distance etc). Could you, please, give some examples when negative Duration is really helps?

gnutix commented 1 year ago

We use this in our application for the following example : let's say an employee should be at his workplace from 8 am to 17 pm. That's a Duration::ofHours(9). Yet the employee is expected to work only 8 hours during that time and have at least one hour of break. As we sometimes don't know when the employee will take it and can't plan for it (imagine a store when you take your break when there's no customer), we apply a Duration::ofHours(-1) adjustment on the schedule to obtain the correct day's work duration, which is Duration::ofHours(8).

Hope this helps.

BenMorel commented 1 year ago

Thanks for providing a use case, @gnutix!

Plus, the upstream Java implementation also allows negative durations, so I think it's fine as it is.