jxxcarlson/elm-typed-time/1.2.0

TypedTime

This library provides functions for working with typed time. For example,

equal (seconds 60) (minutes 1)
--> True


add (hours 1) (minutes 20) |> toString Minutes
--> "01:20"


add (hours 1) (minutes 20) |> toString Seconds
--> "01:20:00"

Types

The data type for the package

type Unit
= Milliseconds
| Seconds
| Minutes
| Hours

Constructors

hours : Float -> TypedTime
hours 1.5 |> toString Minutes
--> "01:30"
minutes : Float -> TypedTime
minutes 14.5 |> toString Seconds
--> "00:14:30"
seconds : Float -> TypedTime
seconds 44 |> toString Seconds
--> "00:00:44"
milliseconds 1000  |> toString Seconds
--> "00:00:01"
The zero element for TypedTime.

Comparison

equal (milliseconds 1000) (seconds 1)
--> True


 equal (hours 1) (minutes 60)
 --> True


 equal (minutes 1) (seconds 60)
 --> True
gt : TypedTime -> TypedTime -> Bool
Greater than:


gt (seconds 1.0001) (seconds 1)
--> True
gte : TypedTime -> TypedTime -> Bool
Greater than or equal to:


gte (seconds 1) (seconds 1)
--> True


gte (seconds 1.001) (seconds 1)
--> True
lt : TypedTime -> TypedTime -> Bool
Les than:


lt (seconds 1) (seconds 1.001)
--> True
lte : TypedTime -> TypedTime -> Bool
Less than or equal to:


lte (seconds 1) (seconds 1)
--> True


lte (seconds 1) (seconds 1.001)
--> True

Operators

common Seconds Minutes
--> Seconds
equal (multiply 0.5 (minutes 1)) (seconds 30)
--> True
divide : Float -> TypedTime -> TypedTime
equal (divide 0.5 (minutes 1)) (seconds 120)
--> True
equal (add (seconds 60) (minutes 1)) (minutes 2)
--> True
equal (sub (seconds 120) (minutes 1)) (minutes 1)
--> True
equal (sum [seconds 30, minutes 1]) (milliseconds 90000)
--> True


equal (sum [seconds 30, minutes 1]) (minutes 1.5)
--> True
ratio : TypedTime -> TypedTime -> Float
abs ((ratio (minutes 1) (seconds 60)) - 1.0) < 0.000001
--> True

Conversion

toSeconds : TypedTime -> Float
abs( (toSeconds (seconds 1)) - 1.0) < 0.00001
--> True


abs( (toSeconds (minutes 1)) - 60.0) < 0.00001
--> True
toString : Unit -> TypedTime -> String
toString Seconds (minutes 30)
--> "00:30:00"


toString Seconds (hours 0.5)
--> "00:30:00"


toString Minutes (hours 0.5)
--> "00:30"
fromString : Unit -> String -> Maybe TypedTime
fromString Milliseconds "123"
--> Just (milliseconds 123)


fromString Seconds "23"
--> Just  (seconds 23)


fromString Seconds "2.17"
--> Just  (seconds 2.17)


fromString Seconds "4:23"
--> Just (add (minutes 4) (seconds 23))


fromString Seconds "04:03"
--> Just (add (minutes 4) (seconds 3))


fromString Minutes "04:03"
--> Just (add (hours 4) (minutes 3))


fromString Minutes "4.7"
--> Just (minutes 4.7)