# How can I parse a \`UnitfulQuantity\` to return a unit describing only the \`Time\` dimension?

**URL:** <https://discourse.julialang.org/t/how-can-i-parse-a-unitfulquantity-to-return-a-unit-describing-only-the-time-dimension/58780>\
**Category:** General Usage\
**Tags:** question, unitful\
**Created:** [April 7, 2021, 5:48pm UTC](https://discourse.julialang.org/t/how-can-i-parse-a-unitfulquantity-to-return-a-unit-describing-only-the-time-dimension/58780 "2021-04-07T17:48:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cadojo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cadojo/32/25328_2.png) [@cadojo](https://discourse.julialang.org/u/cadojo)\
**Post date:** [April 7, 2021, 5:48pm UTC](https://discourse.julialang.org/t/how-can-i-parse-a-unitfulquantity-to-return-a-unit-describing-only-the-time-dimension/58780/1 "2021-04-07T17:48:47Z")

</div>

I have a function where I want to parse a `Unitful.Quantity` argument provided by the user for **only the `Time` dimensioned unit**. For example…

```julia
f(1u"km/s") # should return u"s"
f(1u"km/d") # should return u"d"

```

Is this supported? I have some `parameters` crimes below that get me _close_, but the retuned value is of type `Unitful.Unit{:Second, 𝐓}`, not `Unitful.FreeUnits{(s,), 𝐓, nothing}`.

```julia
julia> using Unitful
julia> function crime(vel::Unitful.Velocity)
  # Flip the units so `Time` is in the numerator
  TL = inv(unit(vel))

 # Now we need to find which index (1 or 2) contains the Time unit
 timeaxis = findfirst(T -> T isa Unitful.Dimension{:Time}, collect(typeof(typeof(TL).parameters[2]).parameters[1]))

 # Now that we have the proper index, let's select the time unit
 timeunit = typeof(TL).parameters[1][timeaxis]
end

julia> crime(1u"m/s") |> typeof
Unitful.Unit{:Second, 𝐓}

julia> u"m" / crime(1u"m/s")
ERROR: MethodError: no method matching /(::Unitful.FreeUnits{(m,), 𝐋, nothing}, ::Unitful.Unit{:Second, 𝐓})
Closest candidates are:
  /(::Unitful.Units, ::Union{Dates.Day, Dates.Hour, Dates.Microsecond, Dates.Millisecond, Dates.Minute, Dates.Nanosecond, Dates.Second, Dates.Week}) at /Users/joey/.julia/packages/Unitful/PcVKX/src/dates.jl:91
  /(::Unitful.Units, ::Unitful.MixedUnits) at /Users/joey/.julia/packages/Unitful/PcVKX/src/logarithm.jl:111
  /(::Unitful.Units, ::Unitful.AbstractQuantity) at /Users/joey/.julia/packages/Unitful/PcVKX/src/quantities.jl:51
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[10]:1

julia> 

```

---

<div class="post-metadata">

**Author:** ![cadojo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cadojo/32/25328_2.png) [@cadojo](https://discourse.julialang.org/u/cadojo)\
**Post date:** [April 7, 2021, 6:17pm UTC](https://discourse.julialang.org/t/how-can-i-parse-a-unitfulquantity-to-return-a-unit-describing-only-the-time-dimension/58780/2 "2021-04-07T18:17:04Z")

</div>

> [@cadojo](#):
>
> ```julia
> julia> using Unitful
> julia> function crime(vel::Unitful.Velocity)
> # Flip the units so `Time` is in the numerator
> TL = inv(unit(vel))
> 
> # Now we need to find which index (1 or 2) contains the Time unit
> timeaxis = findfirst(T -> T isa Unitful.Dimension{:Time}, collect(typeof(typeof(TL).parameters[2]).parameters[1]))
> 
> # Now that we have the proper index, let's select the time unit
> timeunit = typeof(TL).parameters[1][timeaxis]
> end
> 
> julia> crime(1u"m/s") |> typeof
> 
> ```

Alright I think I’ve figured out **one** way to do this.

```julia
julia> out = crime(1u"m/s")
julia> Unitful.FreeUnits{(out,), Unitful.𝐓}() == u"s"
true

```
