Skip to content

Commit

Permalink
Upgrade to elm-iso8601-date-strings 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Feldman committed Aug 31, 2018
1 parent ad14ff6 commit c8c3201
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 29 deletions.
2 changes: 1 addition & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm-explorations/markdown": "1.0.0",
"rtfeldman/elm-iso8601-date-strings": "1.0.0"
"rtfeldman/elm-iso8601-date-strings": "1.1.0"
},
"indirect": {
"elm/parser": "1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Article.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import Html exposing (Attribute, Html, i)
import Html.Attributes exposing (class)
import Html.Events exposing (stopPropagationOn)
import Http
import Iso8601
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (custom, hardcoded, required)
import Json.Encode as Encode
import Markdown
import Profile exposing (Profile)
import Time
import Timestamp
import Username as Username exposing (Username)
import Viewer exposing (Viewer)

Expand Down Expand Up @@ -196,7 +196,7 @@ metadataDecoder =
|> required "description" (Decode.map (Maybe.withDefault "") (Decode.nullable Decode.string))
|> required "title" Decode.string
|> required "tagList" (Decode.list Decode.string)
|> required "createdAt" Timestamp.iso8601Decoder
|> required "createdAt" Iso8601.decoder
|> required "favorited" Decode.bool
|> required "favoritesCount" Decode.int

Expand Down
4 changes: 2 additions & 2 deletions src/Article/Comment.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import Article.Slug as Slug exposing (Slug)
import Author exposing (Author)
import CommentId exposing (CommentId)
import Http
import Iso8601
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (custom, required)
import Json.Encode as Encode exposing (Value)
import Profile exposing (Profile)
import Time
import Timestamp



Expand Down Expand Up @@ -103,6 +103,6 @@ decoder maybeCred =
Decode.succeed Internals
|> required "id" CommentId.decoder
|> required "body" Decode.string
|> required "createdAt" Timestamp.iso8601Decoder
|> required "createdAt" Iso8601.decoder
|> required "author" (Author.decoder maybeCred)
|> Decode.map Comment
25 changes: 1 addition & 24 deletions src/Timestamp.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Timestamp exposing (format, iso8601Decoder, view)
module Timestamp exposing (format, view)

import Html exposing (Html, span, text)
import Html.Attributes exposing (class)
import Iso8601
import Json.Decode as Decode exposing (Decoder, fail, succeed)
import Time exposing (Month(..))

Expand All @@ -17,28 +16,6 @@ view timeZone timestamp =



-- DECODE


{-| Decode an ISO-8601 date string.
-}
iso8601Decoder : Decoder Time.Posix
iso8601Decoder =
Decode.string
|> Decode.andThen fromString


fromString : String -> Decoder Time.Posix
fromString str =
case Iso8601.toTime str of
Ok successValue ->
succeed successValue

Err _ ->
fail ("Invalid date: " ++ str)



-- FORMAT


Expand Down

0 comments on commit c8c3201

Please sign in to comment.