dzuk-mutant/internet-time-elm/1.0.4

InternetTime

A module for using Internet Time.

Daily time

These functions convert a Posix Time to a displayable Internet Time) for that particular day.

(This also includes moving from the Posix timezone (UTC) to Internet Time's timezone (UTC+1).)

Traditionally, Internet Time is displayed with a @ beforehand (ie. @333) but for the sake of simplicity, that kind of decoration is left up to you to put into your interfaces in whatever way you prefer.

fromPosix : Posix -> Float

Converts a Time.Posix to Internet Time for that particular day as a raw Float.

oneTime = Time.millisToPosix 1525244393059
anotherTime = Time.millisToPosix 1525221281000


InternetTime.fromPosix oneTime -- 333
InternetTime.fromPosix anotherTime -- 65
displayFromPosix : Posix -> String

Converts a Time.Posix to Internet Time for that particular day. The output is a String with padded 0s if necessary so it displays as a traditionally correct 3 digit number.

oneTime = Time.millisToPosix 1525244393059
anotherTime = Time.millisToPosix 1525221281000


InternetTime.displayFromPosix oneTime -- "333"
InternetTime.displayFromPosix anotherTime -- "065"

Lenghts of time

Use the cadence of Internet Time in your application.

beat : Int

One Internet Time beat in milliseconds.

This is the largest possible measurement of time in Internet Time.

  • 1 beat = 86400 milliseconds. (86.4 seconds)
centibeat : Int

One Internet Time centibeat in milliseconds.

  • 1 centibeat = 864 milliseconds.
  • 1 centibeat = 1/100 beats.

Centibeats are quite rarely used in Internet Time, but it would be quite useful if you want to update your time subscription in something that matches the timing of beats exactly, but with something much more precise.

subscriptions : Model -> Sub Msg
subscriptions model =
    Time.every (25 * centibeat) Tick
millisToBeats : Int -> Float

Convert an Int representing milliseconds to raw beats (1/1,000th of a day).

millisToBeats 1380000 -- 23min = 15.972222 beats

Custom daily time

Just in case you need something with extra detail like counting time with centibeats as well.

In regular cases, fromPosix and displayFromPosix should probably cover all of your needs.

fromPosixCustom : Int -> Posix -> Float

Converts a Time.Posix to the Internet Time for that particular day as a Float.

The first argument is for how much detail (extra decimal points) you want - beats (0) are the largest form of measurement possible.

oneTime = Time.millisToPosix 1525244393059
anotherTime = Time.millisToPosix 1525221281000


fromPosixCustom 0 oneTime -- 333
fromPosixCustom 2 oneTime -- 333.25 (extra detail w/ centibeats)
fromPosixCustom 0 anotherTime -- 65
fromPosixCustom 2 anotherTime -- 65.75 (extra detail w/ centibeats)
displayFromPosixCustom : Int -> Posix -> String

Converts a Time.Posix to a Internet Time for that particular day in the form of a display-ready String.

The first argument is for how much detail (extra digits) you want - beats are the largest form of measurement possible.

oneTime = Time.millisToPosix 1525244393059
anotherTime = Time.millisToPosix 1525294572000


displayFromPosixCustom 0 oneTime -- "333"
displayFromPosixCustom 2 oneTime -- "333.25" (extra detail w/ centibeats)
displayFromPosixCustom 0 anotherTime -- "914"
displayFromPosixCustom 2 anotherTime -- "914.37" (extra detail w/ centibeats)

This time is padded with zeroes so you get the traditionally correct 3-digit display for beats.

thirdTime = Time.millisToPosix 1525221281000


displayFromPosixCustom 0 thirdTime -- "065"
displayFromPosixCustom 2 thirdTime -- "065.75" (extra detail w/ centibeats)