RFR:JDK-8141452:Convert between TimeUnit and ChronoUnit

Stephen Colebourne scolebourne at joda.org
Fri Jan 29 17:37:40 UTC 2016


In the ideal fix, all methods that take the combination (long,
TimeUnit) would be supplemented by an override that takes (Duration).
eg. Future.get(long, TimeUnit) has an additional get(Duration).
However, this is a lot of work, might be unpopular and would be slower
for j.u.concurrent use.

The proposal is minimal, allowing the conversion to occur more easily.
The Duration.of(long, TemporalUnit) could then be used to create a
Duration.

I'll note again that the alternative to this would be to make TimeUnit
implement TemporalUnit. Whether that is less confusing is an open
question.

The specific question asked is whether there should be a
TimeUnit::toDuration(long) method. I'm not overly fussed, as I think
there are probably enough alternatives.

Stephen


On 29 January 2016 at 17:24, Martin Buchholz <martinrb at google.com> wrote:
> I propose that we the jsr166 maintainers take over this change (sorry
> for butting in!), pushing it into openjdk from jsr166 CVS.
> The tests as they are written today won't work because
> TimeUnit/Basic.java is not a testng test.
> But I don't think we should fix that - instead, tests for these
> methods should be added to our tck tests (I can do that).
> Coincidentally, I am close to committing our tck tests to openjdk.
>
> As for the new API - the simple changes in the webrev are perfectly
> fine, but I expected to see some additional conversions.  TimeUnit is
> for expressing elapsed time durations (even though j.u.c. doesn't have
> a separate class for that), so I vaguely expect conversions to/from
> Duration.  But we won't do anything unless date/time experts
> (Stephen?) think it's a good idea.
>
>
> On Fri, Jan 29, 2016 at 8:46 AM, Martin Buchholz <martinrb at google.com> wrote:
>> I missed that this was modifying jsr166 files - looking now...
>>
>> On Fri, Jan 29, 2016 at 7:12 AM, Chris Hegarty <chris.hegarty at oracle.com> wrote:
>>> On 29/01/16 14:52, Roger Riggs wrote:
>>>>
>>>> Hi Nadeesh,
>>>>
>>>> Looks fine,
>>>>
>>>> Thanks, Roger
>>>>
>>>>
>>>> On 1/27/2016 11:34 AM, nadeesh tv wrote:
>>>>>
>>>>> Hi all,
>>>>>
>>>>> Thanks for the suggestions.
>>>>> Please see the updated webrev
>>>>> http://cr.openjdk.java.net/~ntv/8141452/webrev.01/
>>>
>>>
>>> +1  This looks fine.
>>>
>>> Martin, Doug,
>>>
>>>   I assume you are ok to accept this small change in
>>> java.util.concurrent.TimeUnit.
>>>
>>> -Chris.
>>>
>>>
>>>>> Regards,
>>>>> Nadeesh TV
>>>>>
>>>>> On 1/25/2016 10:24 PM, Roger Riggs wrote:
>>>>>>
>>>>>> Hi Stephen, Nadeesh,
>>>>>>
>>>>>> TimeUnit.toChronoUnit is a static method.  It seems redundant to have
>>>>>> to pass an instance to a static method of its type.
>>>>>>      cu = TimeUnit.toChronoUnit(TimeUnit.SECONDS);
>>>>>>
>>>>>> Instead of:
>>>>>>    TimeUnit tu = TimeUnit.SECONDS;
>>>>>>     ChronoUnit  cu = tu.toChronoUnit();
>>>>>>
>>>>>>
>>>>>> Minor edits please:
>>>>>>
>>>>>> in @param and @return use the type name when referring to the type.
>>>>>> For example, TimeUnit vs timeUnit (the parameter).
>>>>>>
>>>>>> in @throws, use the parameter name instead of "the unit";
>>>>>> For example,
>>>>>> + * @throws IllegalArgumentException if timeUnit cannot be converted
>>>>>> Thanks, Roger
>>>>>>
>>>>>> On 1/25/2016 11:06 AM, nadeesh tv wrote:
>>>>>>>
>>>>>>> Hi all,
>>>>>>>
>>>>>>> Please see the updated webrev
>>>>>>> http://cr.openjdk.java.net/~ntv/8141452/webrev.00/
>>>>>>>
>>>>>>> --
>>>>>>> Thanks and Regards,
>>>>>>> Nadeesh TV
>>>>>>>
>>>>>>>
>>>>>>> On 1/25/2016 9:01 PM, Stephen Colebourne wrote:
>>>>>>>>
>>>>>>>> Typo "TimeUnitequivalent"
>>>>>>>> Otherwise looks good.
>>>>>>>> thanks
>>>>>>>> Stephen
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 25 January 2016 at 15:25, nadeesh tv <nadeesh.tv at oracle.com> wrote:
>>>>>>>>
>>>>>>>>> Hi all,
>>>>>>>>>
>>>>>>>>> Please review a fix for conversion between Chronounit and Timeunit
>>>>>>>>>
>>>>>>>>> Bug ID : https://bugs.openjdk.java.net/browse/JDK-8141452
>>>>>>>>>
>>>>>>>>> webrev: http://cr.openjdk.java.net/~ntv/8141452/webrev.00/
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Thanks and Regards,
>>>>>>>>> Nadeesh TV
>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>> --
>>>>> Thanks and Regards,
>>>>> Nadeesh TV
>>>>>
>>>>
>>>



More information about the core-libs-dev mailing list