github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/src/Duration.elm (about) 1 module Duration exposing (Duration, between, format) 2 3 import Time 4 5 6 type alias Duration = 7 Int 8 9 10 between : Time.Posix -> Time.Posix -> Duration 11 between a b = 12 Time.posixToMillis b - Time.posixToMillis a 13 14 15 format : Duration -> String 16 format duration = 17 let 18 seconds = 19 duration // 1000 20 21 remainingSeconds = 22 remainderBy 60 seconds 23 24 minutes = 25 seconds // 60 26 27 remainingMinutes = 28 remainderBy 60 minutes 29 30 hours = 31 minutes // 60 32 33 remainingHours = 34 remainderBy 24 hours 35 36 days = 37 hours // 24 38 in 39 case ( ( days, remainingHours ), remainingMinutes, remainingSeconds ) of 40 ( ( 0, 0 ), 0, s ) -> 41 String.fromInt s ++ "s" 42 43 ( ( 0, 0 ), m, s ) -> 44 String.fromInt m ++ "m " ++ String.fromInt s ++ "s" 45 46 ( ( 0, h ), m, _ ) -> 47 String.fromInt h ++ "h " ++ String.fromInt m ++ "m" 48 49 ( ( d, h ), _, _ ) -> 50 String.fromInt d ++ "d " ++ String.fromInt h ++ "h"