97jaz / gregor

Date and time library for Racket
45 stars 10 forks source link

time-period-between expects datetime-provider? #44

Open nick-chandoke opened 4 years ago

nick-chandoke commented 4 years ago

The example expression (time-period-between (time 10 30) (time 11 00) '(seconds)) fails because seconds-between (and any other *-between functions) require datetime-provider?, as per their contracts. Thus time-period-between fails for all time-provider? that aren't datetime-provider?, regardless of fields. An easy fix is providing datetimes with dummy year, month, and date, e.g. (time-period-between (datetime 1 1 1 10 30) (datetime 1 1 1 11 00) '(seconds)), but at this point time-period-between is identical to period-between.

97jaz commented 4 years ago

Yeah, I obviously had some muddled thinking here. This is a real design flaw.

Unfortunately, a (regrettabl) part of gregor's design is that you're allowed to ask for the period between two objects of different concrete types. So, for example, you can ask for the number of seconds between, say, a datetime and a moment, which is really not a good idea.

That's the real reason between functions don't work on times. An arbitrary choice of date would fail when confronted by a case using a real date. You'd probably then want to use the date of the object you're being compared to, and I bet I considered that at some point.

These days I'm convinced that between functions should require the right and left hand sides to be the same type of temporal object.

But, as for now, you're right that time-period-between doesn't live up to its contract. Hmm...