使用Time.now获取Elm 0.18中的时间分区日期

使用Time.now获取Elm 0.18中的时间分区日期,time,utc,elm,elm-0.18,Time,Utc,Elm,Elm 0.18,这给了我一个错误: posixDateTask : Task.Task x Time.Date.Date posixDateTask = let timeZoneDate now = Time.Date.date (Time.ZonedDateTime.year (Time.ZonedDateTime.fromDateTime (TimeZones.canada_pacific ()) now))

这给了我一个错误:

posixDateTask : Task.Task x Time.Date.Date
posixDateTask = 
    let
        timeZoneDate now =
            Time.Date.date
                (Time.ZonedDateTime.year (Time.ZonedDateTime.fromDateTime (TimeZones.canada_pacific ()) now))
                (Time.ZonedDateTime.month (Time.ZonedDateTime.fromDateTime (TimeZones.canada_pacific ()) now))
                (Time.ZonedDateTime.day (Time.ZonedDateTime.fromDateTime (TimeZones.canada_pacific ()) now))
    in
    Time.now
        |> Task.map timeZoneDate
如何更改以返回
Task.Task x Time.Date.Date
类型。
我不知道
Time.DateTime.DateTime
从何而来。

Time.now
返回一个带有
Time.Time
的任务,该任务是作为
now
传递给
timeZoneDate
的。然后将
now
传递到
Time.ZonedDateTime.fromDateTime
,这需要
Time.DateTime.DateTime
(鉴于其名称,这应该不会完全令人惊讶)。因此,您必须将
now
Time.Time
转换为
Time.DateTime.DateTime
。看来你可以用电脑来做

基于此,本协议的留置权应能发挥作用:

    |> Task.map timeZoneDate

(|>) is expecting the right side to be a:

     Task.Task x Time.Time -> a

But the right side is:

    Task.Task x Time.DateTime.DateTime -> Task.Task x Time.Date.Date

您可能可以使用诸如或之类的库来执行此操作
posixDateTask : Task.Task x Time.Date.Date
posixDateTask = 
    let
        timeZoneDate now =
            let
                dateTime =
                    Time.DateTime.fromTimeStamp now

                timeZone =
                    TimeZones.canada_pacific ()

                zonedDateTime =
                    Time.ZonedDateTime.fromDateTime timeZone dateTime
            in
            Time.Date.date
                (Time.ZonedDateTime.year zonedDateTime)
                (Time.ZonedDateTime.month zonedDateTime)
                (Time.ZonedDateTime.day zonedDateTime)
    in
    Time.now
        |> Task.map timeZoneDate