在 Elm 0.18 中使用 Time.now 获取时区日期
Use Time.now to get time zoned date in 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))
(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.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
我应该怎么改成return一个Task.Task x Time.Date.Date
类型。
我不知道 Time.DateTime.DateTime
来自哪里。
Time.now
returns 带有 Time.Time
的任务,这是您作为 now
传递给 timeZoneDate
的任务。然后,您将 now
传递给 Time.ZonedDateTime.fromDateTime
,它需要一个 Time.DateTime.DateTime
(考虑到它的名称,这应该不足为奇。)因此您必须将 now
从 [=12 转换为=] 到 Time.DateTime.DateTime
。看来你可以使用 Time.DateTime.fromTimestamp
.
基于此,一些与此相关的东西应该起作用:
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
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.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
我应该怎么改成return一个Task.Task x Time.Date.Date
类型。
我不知道 Time.DateTime.DateTime
来自哪里。
Time.now
returns 带有 Time.Time
的任务,这是您作为 now
传递给 timeZoneDate
的任务。然后,您将 now
传递给 Time.ZonedDateTime.fromDateTime
,它需要一个 Time.DateTime.DateTime
(考虑到它的名称,这应该不足为奇。)因此您必须将 now
从 [=12 转换为=] 到 Time.DateTime.DateTime
。看来你可以使用 Time.DateTime.fromTimestamp
.
基于此,一些与此相关的东西应该起作用:
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