如何将 Elm 0.18 日期函数重写为 Elm 0.19

How to rewrite Elm 0.18 Date functions to Elm 0.19

我正在尝试将 Elm 0.18 升级到 0.19,但在最后一步卡住了,我不知道如何将 Elm 0.18 代码重写为 Elm 0.19。我遇到的一个问题是 mgold/elm-date-format": "1.5.0 <= v < 2.0.0 包是项目的依赖项之一,尚未升级以支持 Elm 0.19,所以我决定用 ryannhg/date-format. I've also read in the migration docs that Time and Date moved to elm/time 替换它,但我想不通了解如何重写下面的代码。我对 Elm 一无所知,所以请放轻松,我的任务是在我的项目中将 Elm 从 0.18 升级到 0.19。不过,我正在努力学习它。

这是我现在拥有的代码,在升级到 0.19 以及完整的堆栈跟踪后无法正常工作。我使用自动 Elm upgrade tool 升级 Elm

代码:

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

堆栈跟踪:

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)

日期和时间的基本类型现在是 Posix。这就是格式化程序函数所期望的。 Date.fromString 最直接的替代品现在在 https://package.elm-lang.org/packages/rtfeldman/elm-iso8601-date-strings/latest/Iso8601 中 - 请参阅 toTime 函数,

您需要处理结果而不是 Maybe,并且编译包的总大小将会增加,因为它使用解析库而不是使用 javascript 的本机数据解析器