2

I need to get the time Interval in such a way that exclude the time interval of offline mode. Let me explain you in a time line.

Example:

A: |---------------------------------------------------------------------------| B: |----| |-------------| C: |--------------| D: |===| |====================| |====================| 

`A` is the time line. `B` is a offline time of `B` `C` is a offline time of `C` notice that they are overlapping with `B` `D` is the time to be billed. 

All I have the Timestamps. I ran out of all the solutions. I wonder if anyone can guide me if there is a way out. Or can suggest me if there is other way around.

Thanks.

2
  • what output do you need? Commented Jun 4, 2013 at 8:20
  • The Interval like 16hr 15min Commented Jun 4, 2013 at 8:24

1 Answer 1

3
  1. Sort the timestamps temporally;
  2. maintain the "total time offline" accumulator and an integer counter;
  3. go through the list of events one by one;
  4. if the counter is currently zero, add the difference of current timestamp and previous timestamp to the accumulator;
  5. if the current event is "went offline", increment counter; otherwise decrement the counter.

This should give you the appropriate time in the accumulator.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.