Skip to content

Commit

Permalink
Add DateTime.TimeWithSeconds format
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Jul 24, 2023
1 parent 092d7c8 commit 1dd1b3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/UI/DateTime.elm
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- Include ui/FormatDateTime.js in the bundle to be able to call DateTime.view


module UI.DateTime exposing
( DateTime
, DateTimeFormat(..)
Expand All @@ -23,6 +26,7 @@ type DateTimeFormat
= ShortDate
| LongDate
| Distance
| TimeWithSeconds


fromPosix : Posix -> DateTime
Expand All @@ -47,6 +51,9 @@ toISO8601 (DateTime t) =
Iso8601.fromTime t


{-| Note: requires the web component ui/FormatDateTime.js to
be part of the bundle
-}
view : DateTimeFormat -> DateTime -> Html msg
view format d =
let
Expand All @@ -60,6 +67,9 @@ view format d =

Distance ->
"distance"

TimeWithSeconds ->
"timeWithSeconds"
in
node "format-date-time"
[ attribute "format" (formatToString format) ]
Expand Down
1 change: 1 addition & 0 deletions src/UI/FormatDateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { format, formatDistance, parseISO } from "date-fns";
const FORMATS = {
shortDate: (d) => format(d, "MMM d, yyyy"),
longDate: (d) => format(d, "MMMM d, yyyy"),
timeWithSeconds: (d) => format(d, "HH:MM:SS"),
distance: (d) => formatDistance(d, new Date()),
};

Expand Down

0 comments on commit 1dd1b3a

Please sign in to comment.