Hi Paul,
PowerBuilder has no system functions to do time interval calculations. Neither does PFC. I just checked PFC for PB 2017 including the DateTime service.
Basically, you need two functions:
- CalculateOverlap: returns the overlap[start; stop] between time intervals A[start; stop] and B[start; stop] using DateTime for all Start and Stop points in time
- HoursAfter: returns the distance between Start and Stop DateTimes measured in hours
- - OR - mix the two functions into one, e.g. CalculateOverlapHours. and thereby violate the single responsibility pricinple
Notes on prerequisites for calculating such intervals and durations:
- You must use DateTime instead of Time to avoid issues across midnight and for duration > 24 hours
- You must decide whether to ignore time zones or how to handle (EX: Convert to UTC)
- You must decide whether to ignore start/end daylight savings time or how to handle (EX: Convert to UTC)
- You must decide whether to ignore "leap seconds" or how to handle (EX: Convert to TAI {aka. Atomic Time} instead of UTC)
HTH /Michael
If you use SQL Server you might find the T-SQL date/time difference methods to be of use.
Start Time
End Time
Actual Duration
in seconds
SecondsAfter
return value
SecondsAfter return values
10:20:30.000'000
10:20:30.999'999
0.999'999
0
10:20:30.999'999
10:20:31.000'000
0.000'001
1
10:20:30.000'000
10:20:31.999'999
1.999'999
1
You may need a different "truncate" strategy when calculating duration in hours. /Michael
Here's some old code snippets that might help: http://nntp-archive.sybase.com/nntp-archive/action/article/%3C385_7D9D14FDB045A211003D16D785256A25.003D16E985256A25@webforums%3E
Regards,