OTRS/otrs — pull request #7 by dietmarb01 (2014-01-27 16:02:03+00:00)
Title: Bugfix#10128 Calculation errors in WorkingTime and DestinationTime

see http://bugs.otrs.org/show_bug.cgi?id=10128

If you calculate WorkingTime(tStart, tStop) and then
DestinationTime(tStart, WorkingTime), the result should be
the latest moment of working time that is at or before the
given tStop, i.e.

DestinationTime( tStart, WorkingTime ( tStart, tStop ) ) <= tStop

The current implementation sometimes gives results that are
*later* than the original StopDate, which is incorrect.
Re-calculating WorkingTime(StartDate, newDestinationTime)
may in some cases show an increase in working time.

Examples:
Start: 1387410932 / 2013-12-19 00:55:32
Stop: 1388490662 / 2013-12-31 12:51:02
Dest: 1388646000 / 2014-01-02 08:00:00
Work: 65:00:00 = 234000

Start: 1387767358 / 2013-12-23 03:55:58
Stop: 1388432786 / 2013-12-30 20:46:26
Dest: 1388645160 / 2014-01-02 07:46:00
Work: 38:46:00 = 139560 --> 140400

This PR corrects the functions WorkingTime and DestinationTime
using a more robust way to advance to the next day.
The code has become simpler and is now correct down to the
second. Switching to/from daylight saving time is handled correctly.

Module tests have been extended with random tests that verify
the assertion given above.