Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb8bac8
commit 86e5ef4
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package libra | ||
|
||
import ops.base.{Show, ConversionFactor} | ||
import spire._, spire.algebra._, spire.math._, spire.implicits._ | ||
import singleton.ops._ | ||
import libra.si.Time | ||
|
||
/* Imperial units */ | ||
package object imperial { | ||
|
||
/** Time units */ | ||
trait Day extends Unit[Time] | ||
trait Hour extends Unit[Time] | ||
|
||
implicit def dayShow: Show[Day] = Show[Day]("days") | ||
implicit def hourShow: Show[Hour] = Show[Hour]("hours") | ||
|
||
implicit def dayHourConversion[A]( | ||
implicit c: ConvertableTo[A] | ||
): ConversionFactor[A, Time, Day, Hour] = | ||
new ConversionFactor(c.fromInt(24)) | ||
|
||
implicit final class BaseQuantityImperialOps[A](val a: A) extends AnyVal { | ||
def days: QuantityOf[A, Time, Day] = Quantity(a) | ||
def hours: QuantityOf[A, Time, Hour] = Quantity(a) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package libra | ||
|
||
import spire.implicits._ | ||
import libra.imperial._, libra.si._ | ||
|
||
import org.scalatest._ | ||
|
||
class ImperialSpec extends WordSpec { | ||
|
||
"day" should { | ||
"show" in { | ||
assert(2.days.show === ("2 days [T]")) | ||
} | ||
|
||
"hour value" in { | ||
assert(2.0.days.to[Hour].value === (48.0)) | ||
} | ||
} | ||
|
||
"hour" should { | ||
"show" in { | ||
assert(2.hours.show === ("2 hours [T]")) | ||
} | ||
|
||
"day value" in { | ||
assert(24.0.hours.to[Day].value === (1.0)) | ||
} | ||
} | ||
} |