<div dir="ltr">I agree that it would be weird for Duration.MIN not to be the true minimum Duration value, and that weirdness outweighs the quirk whereby Duration.MIN.negated() throws an exception.<div><br></div><div>[It's much too late to do anything about it now, of course, but I would argue that it would have been better for Duration values to be completely symmetrical about zero. I think the parallel with Long.MIN_VALUE (etc) doesn't really work. There, the use of two's complement and the fact that every bit pattern is a valid long value together force there to be one more negative value than positive. That leads to all sorts of problems, like Math.abs sometimes being negative. I don't think the same considerations apply to Duration.]</div><div><br></div><div>Although I gave some use cases for Duration.MAX earlier, I'm not actually aware of any for Duration.MIN. That's partly because Google's internal Durations class defines a public MAX but not a MIN. (Partly out of concern that MIN could be misconstrued to mean the smallest positive Duration, like Double.MIN_VALUE.) So I think it would be an option to define just MAX.</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sun, 12 Oct 2025 at 15:26, Stephen Colebourne <<a href="mailto:scolebourne@joda.org">scolebourne@joda.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Just noting that the conceptual definition of Duration.MAX and MIN<br>
have been in use since Java 8, and I disagree with any change to the<br>
current definition.<br>
<br>
You cannot successfully negate Long.MIN_VALUE, so there is no<br>
requirement that edge cases like this support negation.<br>
<br>
Stephen<br>
<br>
<br>
On Wed, 8 Oct 2025 at 21:29, Pavel Rappo <<a href="mailto:pavel.rappo@gmail.com" target="_blank">pavel.rappo@gmail.com</a>> wrote:<br>
><br>
> In another thread, there's a question on whether we can define<br>
> Duration.MIN such that it's not the exact minimum, but rather the<br>
> minimum "negatable minimum"? Put differently, can we define<br>
> Duration.MIN as Duration.MAX.negated(), where Duration.MAX is<br>
> Duration.ofSeconds(Long.MAX_VALUE, 999_999_999)? What are the concerns<br>
> with this, if any?<br>
><br>
> -Pavel<br>
><br>
> On Wed, Sep 3, 2025 at 1:49 PM Pavel Rappo <<a href="mailto:pavel.rappo@gmail.com" target="_blank">pavel.rappo@gmail.com</a>> wrote:<br>
> ><br>
> > Couldn't recall or quickly find if this was asked before.<br>
> ><br>
> > I come across this quite often: there doesn’t seem to be a readily<br>
> > available maximum value for java.time.Duration -- a value that<br>
> > represents the longest possible duration.<br>
> ><br>
> > I assume there are plenty of homegrown constants out in the wild<br>
> > addressing this. Don’t get me wrong: it’s not hard to create one. The<br>
> > issue, in my experience, is that it takes time and sometimes<br>
> > experimentation.<br>
> ><br>
> > Unless one reads the Javadoc carefully, it’s not obvious that the<br>
> > maximum duration can be constructed as follows:<br>
> ><br>
> >     Duration.of(Long.MAX_VALUE, 999_999_999);<br>
> ><br>
> > Naturally, one might first try using IDE autocomplete. For example,<br>
> > creating a Duration from Long.MAX_VALUE of a large unit -- millennia,<br>
> > centuries, decades, etc. -- only to run into ArithmeticException. Only<br>
> > when reaching seconds does it finally work:<br>
> ><br>
> >     Duration.ofSeconds(Long.MAX_VALUE);<br>
> ><br>
> > or<br>
> ><br>
> >     Duration.of(Long.MAX_VALUE, ChronoUnit.SECONDS);<br>
> ><br>
> > Of course, there’s no practical difference between<br>
> > Duration.of(Long.MAX_VALUE, 999_999_999) and<br>
> > Duration.ofSeconds(Long.MAX_VALUE). We’re talking about durations on<br>
> > the order of 292 billion years, after all. The exact value isn’t the<br>
> > problem. The problem is that the values are inconsistent, and arriving<br>
> > to them is error-prone. Adding a constant to java.time.Duration would<br>
> > simplify things.<br>
> ><br>
> > -Pavel<br>
</blockquote></div>