From 13f0c2ab9f0b8fc4aa92c707d9161c7566c42d91 Mon Sep 17 00:00:00 2001 From: Benoit Pasquier Date: Tue, 10 Dec 2019 12:54:26 +1100 Subject: [PATCH 1/3] Add units of year I think that expressing quantities in units of years is so ubiquitous in science that it would be nice to have it in the default Unitful. FWIW I used 365.25 days = 31557600 seconds for the conversion like in UnitfulAstro.jl. There may have been previous discussions about this but I could not find them. (Maybe they disappeared when Unitful moved to PainterQubits?) --- src/pkgdefaults.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pkgdefaults.jl b/src/pkgdefaults.jl index 8cf5b2d8..d71df74e 100644 --- a/src/pkgdefaults.jl +++ b/src/pkgdefaults.jl @@ -104,6 +104,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 From 2dfa01b830c7bf631b1662398f05fddc3bfdbc74 Mon Sep 17 00:00:00 2001 From: Benoit Pasquier Date: Tue, 10 Dec 2019 14:23:07 +1100 Subject: [PATCH 2/3] Add tests for time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add tests for conversion between time units: s ⟷ min ⟷ hr ⟷ d ⟷ yr --- test/runtests.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 64c46363..5ffb2c9f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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, @@ -164,6 +164,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) From 1edf03b08f0479aef9d99a06cc56cbd09e28f4da Mon Sep 17 00:00:00 2001 From: Benoit Pasquier Date: Tue, 10 Dec 2019 14:27:15 +1100 Subject: [PATCH 3/3] Modify example from "yr" to "year" This is a just suggestion where I 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. --- test/runtests.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 5ffb2c9f..1eee9a22 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1601,7 +1601,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) @@ -1611,8 +1611,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)