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

如何将Elm 0.18日期函数重写为Elm 0.19,elm,Elm,我正在尝试将Elm 0.18升级到0.19,但在最后一步中遇到了困难,我不知道如何将Elm 0.18代码重写为Elm 0.19。我遇到的一个问题是包mgold/elm日期格式“:“1.5.0现在日期和时间的基本类型是Posix。这就是格式化程序函数所期望的。最直接的日期替换方法是使用Date.fromString,请参见toTime函数 你需要处理一个结果,而不是一个可能,编译包的总大小将增加,因为它使用解析库,而不是使用javascript的原生数据解析器(旧的日期)。fromString是一

我正在尝试将Elm 0.18升级到0.19,但在最后一步中遇到了困难,我不知道如何将Elm 0.18代码重写为Elm 0.19。我遇到的一个问题是包
mgold/elm日期格式“:“1.5.0现在日期和时间的基本类型是
Posix
。这就是格式化程序函数所期望的。最直接的日期替换方法是使用
Date.fromString
,请参见
toTime
函数


你需要处理一个结果,而不是一个可能,编译包的总大小将增加,因为它使用解析库,而不是使用javascript的原生数据解析器(旧的
日期)。fromString
是一个委托给javascript的尽力而为的实现,因此在尝试解析它得到的任何东西时,它不是很可预测的,返回可能有效或可能无效的
日期
对象。这与惯用的Elm不太匹配,所以它被删除了
ryanhg/date格式
是一个用于转换为字符串的包,而不是从字符串转换为字符串的包,因此在这里对您没有帮助。您需要知道日期字符串的特定格式,并选择一个能够解析该格式的库。实际上,您的问题没有包含足够的信息来确定该字符串的格式以及如何解析该字符串。但即使这样做了,它基本上也只是要求提供一个库建议,不幸的是,这在堆栈溢出问题上明显偏离了主题。你可能想试试or,因为它们更适合提供指导。@绝地武士,你现在有足够的东西继续吗?
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)