I am trying to upgrade Elm 0.18 to 0.19 and got stuck on a final step, where I can't figure out how to rewrite Elm 0.18 code to Elm 0.19. One issue I had was that the package mgold/elm-date-format": "1.5.0 <= v < 2.0.0
, which was one of the dependencies of the project, was not upgrded yet to support Elm 0.19 so I decided to replace it with ryannhg/date-format. I've also read in the migration docs that Time
and Date
moved to elm/time but I can't figure out how to rewrite the code below. I have no idea about Elm whatsoever so please go easy on me, I was just tasked to upgrade Elm from 0.18 to 0.19 in my project. I am trying to learn it, though.
Here's the code I have right now which does not work after upgrading to 0.19 plus the full stacktrace. I used the automated Elm upgrade tool for upgrading Elm
Code:
module Views.Note exposing (view)
import Data.Note.Author exposing (Author)
import Data.Note exposing (Note)
import Html exposing (Html, text, span, tr, td, p)
import Html.Attributes exposing (class)
import Date.Format exposing(format)
import Date
import Views.Note.Author
-- VIEW --
view : Note -> List Author -> Html msg
view note authors=
let
author = List.head (List.filter (hasAuthorId note.authorId) authors)
in
case Date.fromString(note.createdAt) of
Ok date ->
tr []
[ td [ class "stacked" ]
[ span [ class "date" ][ text (format "%m/%d/%Y %l:%M %P" date) ]
, Views.Note.Author.view author
, p [ class "text" ][ text note.text ]
]
]
Err _ -> text ""
hasAuthorId : Maybe Int -> Author -> Bool
hasAuthorId authorId author =
case authorId of
Just authorId ->
author.id == authorId
_ ->
False
Stacktrace:
ERROR in ./app/javascript/Page/Notes.elm
Module build failed (from ./node_modules/elm-webpack-loader/index.js):
Error: Compiler process exited with error Compilation failed
-- UNKNOWN IMPORT -------------------------------- app/javascript/Views/Note.elm
The Views.Note module has a bad import:
import Date
I cannot find that module! Is there a typo in the module name?
The "source-directories" field of your elm.json tells me to only look in the
app/javascript directory, but it is not there. Maybe it is in a package that is
not installed yet?
at ChildProcess.<anonymous> (/home/jedrek/workspace/ironin/lease_management_system/node_modules/node-elm-compiler/dist/index.js:131:35)
at ChildProcess.emit (events.js:203:13)
at maybeClose (internal/child_process.js:1021:16)
at Socket.<anonymous> (internal/child_process.js:430:11)
at Socket.emit (events.js:203:13)
at Pipe.<anonymous> (net.js:588:12)
The base type for Dates and Times now is Posix
. That's what the formatter functions will expect. The most direct replacement for Date.fromString
now is in https://package.elm-lang.org/packages/rtfeldman/elm-iso8601-date-strings/latest/Iso8601 - see the toTime
function,
You'll need to handle a result rather than a Maybe, and the total size of your compiled package will go up as this uses parsing libraries rather than using javascript's native data parser