What's the rationale behind making DateInterval an IEnumerable<LocalDate>?

Skip to first unread message


May 8, 2020, 1:16:20 PM5/8/20
to Noda Time
I'm asking since it causes me a headache right now, where a library (NHibernate) treats every non-string IEnumerable in a way that is not compatible with what I want to do (LINQ expression building). While it certainly can be said to be a shortcoming of  NHibernate, I can see the same issue developing elsewhere (mostly serialization). The "non-string IEnumerable" check is not elegant, but there's not much else to do if you want to blindly check the characteristics of something, unfortunate as that is,

Even so, a specifically two valued struct/class doesn't strike me as an IEnumerable candidate. It's more a Tuple, if anything. Anyone care to educate/agree/disagree?

Best regards

Jon Skeet

May 8, 2020, 1:22:28 PM5/8/20
to Noda Time
It's not just a tuple of two arbitrary values - it's a range with a very natural sequence of "every date in the range".

I believe it's useful to be able to write:

foreach (var date in new DateInterval(start, end))

Note that the regular Interval doesn't implement IEnumerable<Instant> because there isn't any natural sequence - it would make sense to take "each second in the interval" or "each minute in the interval" for example. But as DateInterval is between discrete values (dates) it represents an obvious sequence.

I'm sorry to hear that NHibernate wants to do unfortunate things automatically with it, but I think overall it's better to have the functionality than not - and I certainly don't think it's worth breaking backward compatibility by removing it for 3.0.



You received this message because you are subscribed to the Google Groups "Noda Time" group.
To unsubscribe from this group and stop receiving emails from it, send an email to noda-time+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/noda-time/bf715f66-3513-4b74-ae97-0f9043dfbb17%40googlegroups.com.


May 8, 2020, 2:02:06 PM5/8/20
to Noda Time
Ok, I can see the elegance in that, although an "AsRangeOfDates" method would be more discoverable, IMHO. 

Thanks for your swift response. 

To unsubscribe from this group and stop receiving emails from it, send an email to noda...@googlegroups.com.
Reply all
Reply to author
0 new messages