Make Period IComparable<Period> #69

Closed
GoogleCodeExporter opened this Issue Mar 15, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@GoogleCodeExporter
I'd like to be able to compare periods for sorting etc.

Clearly this is tricky when months and years are involved, and clearly there's 
no way to create an IAlmostComparableSortOf interface, but it seems likely that 
there is a "common-sense" (or useful) answer to most of the problems:

   4 weeks is less than 1 month (nearly always)
   4 weeks is never more than 1 month (always)
   12 months is equal to 1 year (in most cases)
   52 weeks is less than a whole year (always)
   etc.

And even when there isn't, it's still useful to present an 'almost certainly 
sorted' list to a user instead of not being able to show anything.

Original issue reported on code.google.com by HighTech...@gmail.com on 19 Apr 2012 at 3:42

@GoogleCodeExporter

This comment has been minimized.

Show comment
Hide comment
@GoogleCodeExporter

GoogleCodeExporter Mar 15, 2015

I don't want to provide something which is "sorta right". If you want to do so, 
you can certainly implement IComparer<Period> yourself. If enough people ask 
for this, we can try to nail down *exactly* what rules would satisfy demand, 
but I'm very reluctant to put it in now.

Original comment by jonathan.skeet on 19 Apr 2012 at 6:09

  • Changed state: WontFix
I don't want to provide something which is "sorta right". If you want to do so, 
you can certainly implement IComparer<Period> yourself. If enough people ask 
for this, we can try to nail down *exactly* what rules would satisfy demand, 
but I'm very reluctant to put it in now.

Original comment by jonathan.skeet on 19 Apr 2012 at 6:09

  • Changed state: WontFix
@GoogleCodeExporter

This comment has been minimized.

Show comment
Hide comment
@GoogleCodeExporter

GoogleCodeExporter Mar 15, 2015

Scratch that - I've thought of a way of making it a decent comparer that I 
won't be unhappy with.

I'm not actually going to make Period implement IComparable<Period>, but I'll 
provide a method to create an IComparer<Period> *with a given "base" 
LocalDateTime*. The result of comparing two periods will be the result of 
(baseDateTime + period1).CompareTo(baseDateTime + period2).

Original comment by jonathan.skeet on 19 Apr 2012 at 7:29

  • Changed state: Accepted
Scratch that - I've thought of a way of making it a decent comparer that I 
won't be unhappy with.

I'm not actually going to make Period implement IComparable<Period>, but I'll 
provide a method to create an IComparer<Period> *with a given "base" 
LocalDateTime*. The result of comparing two periods will be the result of 
(baseDateTime + period1).CompareTo(baseDateTime + period2).

Original comment by jonathan.skeet on 19 Apr 2012 at 7:29

  • Changed state: Accepted
@GoogleCodeExporter

This comment has been minimized.

Show comment
Hide comment
@GoogleCodeExporter

GoogleCodeExporter Mar 15, 2015

Fixed in revision 914423e47fb8 in terms of adding a CreateComparer method. 
Hopefully this will be enough for you.

Original comment by jonathan.skeet on 19 Apr 2012 at 9:16

  • Changed state: Fixed
Fixed in revision 914423e47fb8 in terms of adding a CreateComparer method. 
Hopefully this will be enough for you.

Original comment by jonathan.skeet on 19 Apr 2012 at 9:16

  • Changed state: Fixed

@malcolmr malcolmr added the wontfix label Mar 15, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment