# Parsing String to Dates.CompoundPeriod

**URL:** https://discourse.julialang.org/t/parsing-string-to-dates-compoundperiod/25484
**Category:** General Usage
**Created:** [June 20, 2019, 1:46pm UTC](https://discourse.julialang.org/t/parsing-string-to-dates-compoundperiod/25484 "2019-06-20T13:46:28Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![cchderrick](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cchderrick](https://discourse.julialang.org/u/cchderrick)
#### Post date: [June 21, 2019, 3:06pm UTC](https://discourse.julialang.org/t/parsing-string-to-dates-compoundperiod/25484/7 "2019-06-21T15:06:47Z")

</div>

hmm… interesting. I would also have thought it is implemented, given `+`, and `-` are already implemented.

Well, here is my attempt, using differences.

```julia
function duration_gt(x::Dates.CompoundPeriod, y::Dates.CompoundPeriod)
    d = y-x
    # probably bad assumption that the first period is always 
    # the lower time resolution and canonicalized?
    first(d.periods).value < 0 
end
duration_gt(x::Dates.CompoundPeriod, y::Dates.Period) = duration_gt(x,Dates.CompoundPeriod(y))
duration_gt(x::Dates.Period, y::Dates.CompoundPeriod) = duration_gt(Dates.CompoundPeriod(x),y)
duration_gt(x::Dates.Period, y::Dates.Period) = duration_gt(Dates.CompoundPeriod(x),Dates.CompoundPeriod(y))

```

Some quick test cases:

```julia
julia> W1D1 = Week(1)+Day(1)
1 week, 1 day

julia> S2 = Second(2)
2 seconds

julia> MS300 = Microsecond(300)
300 microseconds

julia> duration_gt(W1D1,S2)
true

julia> duration_gt(S2,W1D1)
false

julia> duration_gt(S2,MS300)
true

julia> duration_gt(MS300,S2)
false

```

I think it is not implemented, because `Year` and `Month` are not fixed duration, it doesn’t work with CompoundPeriond with `Month` or `Year` in it.

---

_[View the full topic](https://discourse.julialang.org/t/parsing-string-to-dates-compoundperiod/25484)._
