1. Paul Shue
  2. PowerBuilder
  3. Monday, 9 April 2018 15:40 PM UTC

How can you determine the overlap in hours between two time intervals?  

time interval 1: (starttime1 and endtime1) and time interval 2:  (starttime2 and endtime2)

What is the overlap between these 2 different intervals.

Michael Kramer Accepted Answer Pending Moderation
  1. Monday, 9 April 2018 23:28 PM UTC
  2. PowerBuilder
  3. # 1

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

Comment
  1. Matthew Balent
  2. Tuesday, 10 April 2018 18:03 PM UTC
When I tackled this issue in a scheduling window I needed to calculate the days between dates and then the difference in the times.



If you use SQL Server you might find the T-SQL date/time difference methods to be of use.



 

  1. Helpful
  1. Michael Kramer
  2. Tuesday, 10 April 2018 20:14 PM UTC
I noted an unexpected behavior in PowerBuilder's SecondsAfter function: It truncates to full seconds before calculating difference in seconds.









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

  1. Helpful
  1. Govinda Lopez @Appeon
  2. Tuesday, 10 April 2018 22:45 PM UTC
Hi All,



 



Here's some old code snippets that might help: http://nntp-archive.sybase.com/nntp-archive/action/article/%3C385_7D9D14FDB045A211003D16D785256A25.003D16E985256A25@webforums%3E



 



Regards,

  1. Helpful
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Monday, 9 April 2018 15:46 PM UTC
  2. PowerBuilder
  3. # 2

see: SecondsAfter ( time1, time2 )

then divide the seconds to get  hours

 

Comment
  1. Paul Shue
  2. Monday, 9 April 2018 17:17 PM UTC
I am seeking a way to calculate the overlap between 2 distinct time intervals:



time interval 1: (starttime1 and endtime1) and time interval 2:  (starttime2 and endtime2)



What is the overlap between these 2 different intervals.



Thanks for you prompt response

  1. Helpful
  1. Kim Berghall
  2. Monday, 9 April 2018 18:17 PM UTC
I think you have to take the max of the start times and the min of the end times and then do a diff between those. if the max is less than the min then there is no overlap.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.