Skip to content

Commit

Permalink
Relative date tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Dec 22, 2023
1 parent 0a1423d commit 1f2de97
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/UI/DateTime.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Html.Attributes exposing (class)
import Iso8601
import Json.Decode as Decode
import Time exposing (Posix)
import UI.Tooltip as Tooltip


type DateTime
Expand All @@ -33,7 +34,6 @@ type DateTime
type DateTimeFormat
= ShortDate
| LongDate
| Distance
| DistanceFrom DateTime
| TimeWithSeconds24Hour
| TimeWithSeconds12Hour
Expand Down Expand Up @@ -170,10 +170,18 @@ toString format zone (DateTime p) =
DistanceFrom (DateTime from) ->
DateFormat.Relative.relativeTime from p

_ ->
""


view : DateTimeFormat -> Time.Zone -> DateTime -> Html msg
view format zone d =
span [ class "datetime" ] [ text (toString format zone d) ]
let
viewed =
span [ class "datetime" ] [ text (toString format zone d) ]
in
case format of
DistanceFrom _ ->
Tooltip.text (toString FullDateTime zone d)
|> Tooltip.tooltip
|> Tooltip.view viewed

_ ->
viewed

0 comments on commit 1f2de97

Please sign in to comment.