Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ julia> unit(1.0) == NoUnits
true
```
"""
@inline unit(x::Any) = NoUnits # In general, things do not have units.
@inline unit(x::Number) = NoUnits
@inline unit(x::Type{T}) where {T <: Number} = NoUnits
@inline unit(x::Type{Union{Missing, T}}) where T = unit(T)
@inline unit(x::Function) = NoUnits # Functions do not have units. Function values might.
@inline unit(x::Type{Union{Missing, T}}) where { T <: Number } = unit(T) # Type restriction required here for T, or might result in infinite recursion.
@inline unit(x::Type{Missing}) = missing
@inline unit(x::Missing) = missing

Expand Down
6 changes: 3 additions & 3 deletions test/dates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
@test_throws MethodError dimension(T(1))
@test_throws MethodError Unitful.numtype(T)
@test_throws MethodError Unitful.numtype(T(1))
@test_throws MethodError unit(T)
@test_throws MethodError unit(T(1))
@test unit(T) == NoUnits
@test unit(T(1)) == NoUnits
end

for p = (CompoundPeriod, CompoundPeriod(), CompoundPeriod(Day(1)), CompoundPeriod(Day(1), Hour(-1)))
@test dimension(p) === 𝐓
@test_throws MethodError Unitful.numtype(p)
@test_throws MethodError unit(p)
@test unit(p) == NoUnits
end
end

Expand Down
Loading