Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first pass at a relative time widget
- Loading branch information
1 parent
ac25d83
commit 8a2d1ae
Showing
3 changed files
with
118 additions
and
44 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
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
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,66 @@ | ||
module Widgets.TimeDifference exposing (timeDifference) | ||
|
||
import Accessibility.Styled as Html exposing (Html) | ||
import Time | ||
import Time.Extra exposing (Interval(..), diff) | ||
|
||
|
||
timeDifference : Time.Posix -> Time.Posix -> Html msg | ||
timeDifference before after = | ||
case diff Year Time.utc before after of | ||
0 -> | ||
case diff Month Time.utc before after of | ||
0 -> | ||
case diff Week Time.utc before after of | ||
0 -> | ||
case diff Day Time.utc before after of | ||
0 -> | ||
case diff Hour Time.utc before after of | ||
0 -> | ||
case diff Minute Time.utc before after of | ||
0 -> | ||
case diff Second Time.utc before after of | ||
0 -> | ||
Html.text "just now" | ||
|
||
1 -> | ||
Html.text "just now" | ||
|
||
otherwise -> | ||
Html.text (String.fromInt otherwise ++ " seconds") | ||
|
||
1 -> | ||
Html.text "a minute" | ||
|
||
otherwise -> | ||
Html.text (String.fromInt otherwise ++ " minutes") | ||
|
||
1 -> | ||
Html.text "an hour" | ||
|
||
otherwise -> | ||
Html.text (String.fromInt otherwise ++ " hours") | ||
|
||
1 -> | ||
Html.text "a day" | ||
|
||
otherwise -> | ||
Html.text (String.fromInt otherwise ++ " days") | ||
|
||
1 -> | ||
Html.text "a week" | ||
|
||
otherwise -> | ||
Html.text (String.fromInt otherwise ++ " weeks") | ||
|
||
1 -> | ||
Html.text "a month" | ||
|
||
otherwise -> | ||
Html.text (String.fromInt otherwise ++ " months") | ||
|
||
1 -> | ||
Html.text "a year" | ||
|
||
otherwise -> | ||
Html.text (String.fromInt otherwise ++ " years") |