Skip to content

Commit

Permalink
Add unit of year (#288)
Browse files Browse the repository at this point in the history
* Add units of year

used 365.25 days = 31557600 seconds for the conversion like in UnitfulAstro.jl.

* Add tests for time

Add tests for conversion between time units: s ⟷ min ⟷ hr ⟷ d ⟷ yr.

* Modify example from "yr" to "year"

changed the example of extending Unitful to use "year" instead of "yr" (and 365 days instead of 365.25) such that it is distinct from the "yr" unit that this PR adds to default units.
  • Loading branch information
briochemc authored Feb 21, 2020
1 parent f9c5476 commit 7526dc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/pkgdefaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ end
@unit hr "hr" Hour 3600s false
@unit d "d" Day 86400s false
@unit wk "wk" Week 604800s false
@unit yr "yr" Year 31557600s false
@unit rps "rps" RevolutionsPerSecond 2π*rad/s false
@unit rpm "rpm" RevolutionsPerMinute 2π*rad/minute false

Expand Down
12 changes: 8 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Unitful:
mg, g, kg,
Ra, °F, °C, K,
rad, °,
ms, s, minute, hr, Hz,
ms, s, minute, hr, d, yr, Hz,
J, A, N, mol, V,
mW, W,
dB, dB_rp, dB_p, dBm, dBV, dBSPL, Decibel,
Expand Down Expand Up @@ -165,6 +165,10 @@ end
@test 1inch == (254//100)*cm
@test 1ft == 12inch
@test 1/mi == 1//(5280ft)
@test 1minute == 60s
@test 1hr == 60minute
@test 1d == 24hr
@test 1yr == 365.25d
@test 1J == 1kg*m^2/s^2
@test typeof(1cm)(1m) === 100cm
@test (3V+4V*im) != (3m+4m*im)
Expand Down Expand Up @@ -1631,7 +1635,7 @@ try
module ExampleExtension
using Unitful
@unit yr "yr" JulianYear 365.25u"d" true
@unit year "year" JulianYear 365u"d" true
function __init__()
Unitful.register(ExampleExtension)
Expand All @@ -1641,8 +1645,8 @@ try
pushfirst!(LOAD_PATH, load_path)
pushfirst!(DEPOT_PATH, load_cache_path)
@eval using ExampleExtension
# Delay u"yr" expansion until test time
@eval @test uconvert(u"d", 1u"yr") == 365.25u"d"
# Delay u"year" expansion until test time
@eval @test uconvert(u"d", 1u"year") == 365u"d"
finally
rm(load_path, recursive=true)
rm(load_cache_path, recursive=true)
Expand Down

0 comments on commit 7526dc7

Please sign in to comment.