# Negative Duration

**URL:** <https://internals.rust-lang.org/t/negative-duration/14055>\
**Category:** libs\
**Created:** [February 14, 2021, 6:39pm UTC](https://internals.rust-lang.org/t/negative-duration/14055 "2021-02-14T18:39:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![polomsky](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/polomsky/32/7781_2.png) [@polomsky](https://internals.rust-lang.org/u/polomsky)\
**Post date:** [February 14, 2021, 6:40pm UTC](https://internals.rust-lang.org/t/negative-duration/14055/1 "2021-02-14T18:40:00Z")

</div>

Hello. I have read conversation about duration at [Duration::zero() -\> Duration::ZERO by workingjubilee · Pull Request #78216 · rust-lang/rust · GitHub](https://github.com/rust-lang/rust/pull/78216) and I would like to share some ideas how to improve it.

I see two usecases for Duration

1. I need some value for thread::sleep and similar methods - clearly negative duration makes no sense there and should

2. And there is another kind of duration, when I want calculate difference between two timestamps surely here I need negative durations. The problem of MIN duration can be solved the same way as for real numbers. There is smallest positive non zero value, which could be applied to duration too if needed, and similar value exists for negative real number - so could be also for duration - but for "smallest negative" duration (negative and closest to zero) I see no usecase.

These two usecases can be covered by single type in case of 1.1. or 1.3. (preferably 1.3.) or by two types, in case of 1.1.

To prevent BC break, another type should be introduced, e.g. TimeDifference with some nice conversion to Duration and back.

---

<div class="post-metadata">

**Author:** ![jhpratt](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jhpratt/32/11640_2.png) [@jhpratt](https://internals.rust-lang.org/u/jhpratt)\
**Post date:** [February 14, 2021, 10:07pm UTC](https://internals.rust-lang.org/t/negative-duration/14055/2 "2021-02-14T22:07:24Z")

</div>

What's wrong with using crates here?

---

<div class="post-metadata">

**Author:** ![polomsky](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/polomsky/32/7781_2.png) [@polomsky](https://internals.rust-lang.org/u/polomsky)\
**Post date:** [February 14, 2021, 10:29pm UTC](https://internals.rust-lang.org/t/negative-duration/14055/3 "2021-02-14T22:29:03Z")

</div>

Good question. Actually it did not occur to me that it does not have to be part of standard library.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [May 15, 2021, 10:29pm UTC](https://internals.rust-lang.org/t/negative-duration/14055/4 "2021-05-15T22:29:26Z")

</div>

Closed on May 15, 2021, 10:29pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
