#2202 Difference between two Times doesn't generate Duration?

lel4866 Mon 11 Nov 2013

Am I missing something?

I can't say:

Time a

Time b

Duration c := a - b

SlimerDude Mon 11 Nov 2013

The Time delta is only known if both the times are on the same day. Essentially, a diff is only valid for DateTime objects

It depends on which day the times a and b are on. If they're on the same day then you could say:

Time a := ...; Time b := ...
Date today := Date.now
Duration c := a.toDateTime(today) - b.toDateTime(today)

If a and b are on different days then you need that date information to know if the duration is +'ve or -'ve.

brian Tue 12 Nov 2013

Yeah its really designed that differences in time are done with a DateTime and not just a Time. I've quite a ton of time based code, I definitely think that is typically how you want it to work. But if you really want to subtract two Times, then you can do this:

fansh> a := Time(13, 0)
13:00:00
fansh> b := Time(5, 0)
05:00:00
fansh> a.toDuration - b.toDuration
8hr

Login or Signup to reply.