Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Period IComparable<Period> #69

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

Make Period IComparable<Period> #69

GoogleCodeExporter opened this issue Mar 15, 2015 · 3 comments
Labels

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants