# Should Dates.Period be a subtype of Integer

**URL:** <https://discourse.julialang.org/t/should-dates-period-be-a-subtype-of-integer/23465>\
**Category:** Internals & Design\
**Tags:** proposal, dates, intervals\
**Created:** [April 24, 2019, 9:57am UTC](https://discourse.julialang.org/t/should-dates-period-be-a-subtype-of-integer/23465 "2019-04-24T09:57:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [April 24, 2019, 9:57am UTC](https://discourse.julialang.org/t/should-dates-period-be-a-subtype-of-integer/23465/1 "2019-04-24T09:57:07Z")

</div>

Because of how [IntervalSets](https://github.com/JuliaMath/IntervalSets.jl) calculates a [“duration”](https://github.com/JuliaMath/IntervalSets.jl/blob/master/src/IntervalSets.jl#L201), I went into a short rabbit hole of why aren’t all the types of Dates considered as subtypes of Integers (see [here for the instigator](https://discourse.julialang.org/t/implementing-a-zero-width-type-for-intervalsets/23444/3)).

The main reason is that periods are integers in Dates (ironically I [once](https://discourse.julialang.org/t/why-do-time-quantities-have-to-be-integers/5864/51) tried to push for float-based dates… long story short I was wrong), and we might as well have them behave like ones…

Any particular reason they’re not…?

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [April 24, 2019, 4:47pm UTC](https://discourse.julialang.org/t/should-dates-period-be-a-subtype-of-integer/23465/2 "2019-04-24T16:47:33Z")

</div>

Periods are spans between Dates/DateTimes. They are no more integers than are Chars. If you subtract two Dates you will get a number of `Days`. If you subtract two DateTimes you get a number of `Milliseconds`. Which would be your Integer? What about the other?

If you want to strip the type and isolate the corresponding Int64,  
`daycount = date1 - date2; intvalue = daycount.value`  
(which corresponds to `width` in IntervalSets, add 1 to get what corresponds to duration in IntervalSets)

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [April 24, 2019, 6:46pm UTC](https://discourse.julialang.org/t/should-dates-period-be-a-subtype-of-integer/23465/3 "2019-04-24T18:46:29Z")

</div>

Sorry for the confusion: I’m not talking about treating intervals as integers or as dates. Because `IntervalSets.duration` currently applies only to intervals who’s end-points are integer-like, and has a specific method for an interval who’s end-points are a Date(), I thought subtypes of Dates (e.g. Date, DateTime, Day, Second, Hour, Millisecond, etc) should be subtypes of `Integer`.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [April 24, 2019, 6:58pm UTC](https://discourse.julialang.org/t/should-dates-period-be-a-subtype-of-integer/23465/4 "2019-04-24T18:58:38Z")

</div>

They shouldn’t :). They do not conform to the Integer API: consider  
`Date("2019-04-24") * Date("2019-04-25"), Day(5)^Year(3)`

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [April 24, 2019, 6:59pm UTC](https://discourse.julialang.org/t/should-dates-period-be-a-subtype-of-integer/23465/5 "2019-04-24T18:59:56Z")

</div>

OK, fair enough, letting it go 🙂 Thanks!

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [April 24, 2019, 8:17pm UTC](https://discourse.julialang.org/t/should-dates-period-be-a-subtype-of-integer/23465/6 "2019-04-24T20:17:08Z")

</div>

Superfluously, let me add that the reasoning “it is represented as an integer, so why is it not an integer subtype” is the _exact opposite_ of what a type system is for.

After all, every single data type in your computer is represented the same kind of data: bits and bytes. The job of the type system is to overlay meaning on top of this representation.
