# Kotlin durations don't support ranges with steps. :/

**URL:** <https://discuss.kotlinlang.org/t/kotlin-durations-dont-support-ranges-with-steps/21706>\
**Category:** Uncategorized\
**Created:** [May 4, 2021, 5:42pm UTC](https://discuss.kotlinlang.org/t/kotlin-durations-dont-support-ranges-with-steps/21706 "2021-05-04T17:42:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjaminhill](https://avatars.discourse-cdn.com/v4/letter/b/57b2e6/32.png) [@benjaminhill](https://discuss.kotlinlang.org/u/benjaminhill)\
**Post date:** [May 4, 2021, 5:42pm UTC](https://discuss.kotlinlang.org/t/kotlin-durations-dont-support-ranges-with-steps/21706/1 "2021-05-04T17:42:24Z")

</div>

I was hoping this would be ok. It wasn’t. FR: Have Durations support ranges so I can do this expression.

`for(i in Duration.ZERO..maxDuration step offset) { ... }`

I think getting it to work would involve something like [https://www.netguru.com/codestories/traversing-through-dates-with-kotlin-range-expressions](https://www.netguru.com/codestories/traversing-through-dates-with-kotlin-range-expressions)

---

<div class="post-metadata">

**Author:** ![bjonnh](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/bjonnh/32/8106_2.png) [@bjonnh](https://discuss.kotlinlang.org/u/bjonnh)\
**Post date:** [May 7, 2021, 1:53am UTC](https://discuss.kotlinlang.org/t/kotlin-durations-dont-support-ranges-with-steps/21706/2 "2021-05-07T01:53:37Z")

</div>

Yes or something like that: [Custom Range Iterator](https://www.baeldung.com/kotlin/custom-range-iterator)

And then add an infix function.

---

<div class="post-metadata">

**Author:** ![Whathecode](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/whathecode/32/7494_2.png) [@Whathecode](https://discuss.kotlinlang.org/u/Whathecode)\
**Post date:** [July 25, 2024, 1:30pm UTC](https://discuss.kotlinlang.org/t/kotlin-durations-dont-support-ranges-with-steps/21706/3 "2024-07-25T13:30:20Z")

</div>

In [this generic kotlinx.interval library](https://github.com/Whathecode/kotlinx.interval/tree/develop), I add support for “intervals” (functionally speaking a superset of ranges) of datetime/durations.

I haven’t implemented progressions yet, though, but this is where I see this library evolve over time; that is the exact same use case I had before when I wrote a similar C# library. I don’t expect basic language support for ranges to easily expand to incorporate such “advanced” interval use cases any time soon.
