MenoData / Time4J

Advanced date, time and interval library for Java with sun/moon-astronomy and calendars like Chinese, Coptic, Ethiopian, French Republican, Hebrew, Hijri, Historic Christian, Indian National, Japanese, Julian, Korean, Minguo, Persian, Thai, Vietnamese
GNU Lesser General Public License v2.1
424 stars 62 forks source link

Support for Duration.in(Collection<Unit>) #899

Closed kashike closed 4 years ago

kashike commented 4 years ago

Hi there! A bit of a simple request, but do you think you could add a Collection-variant of Duration.in(U)? It is nicer to pass around a collection instead of an array in my code, so I made a helper method to do this, but figured I am probably not the only one.

public static <U extends IsoUnit> TimeMetric<U, Duration<U>> in(Collection<U> units)

MenoData commented 4 years ago

Sure, I can do it, maybe with a small wildcard limit modification on the collection parameter.

Just one question: Have you also noticed the possibility to simply pass all necessary units as var-arg-array instead of first collecting them? For example:

Duration<IsoUnit> duration =
      Duration.in(DAYS, HOURS, MINUTES).between(start, end);
kashike commented 4 years ago

Yes, but in my case I have a pre-existing Set of the units I want to use, and am converting them to an array manually. Passing an array around is not that nice, especially since mutable.

MenoData commented 4 years ago

Ok, I have committed some code changes for the next release v5.6. I cannot yet say when it will be released because I still need some time for finishing the old Hindu calendar but your RFE is on the road. Thanks for feedback.

kashike commented 4 years ago

Thank you for the speedy addition, @MenoData!