date - 模块导入错误
问题描述
在尝试导入 Date 模块并在一个简单的 Elm 文件中使用它时,我收到以下错误:
-- UNKNOWN IMPORT ---------------------------- app/javascript/CountdownTimer.elm
The CountdownTimer 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 src
directory, but it is not there. Maybe it is in a package that is not installed
yet?
CountdownTimer 是文件和模块的名称,取自此处,似乎工作正常,但不适合我。
我正在使用 Elm 0.19.0 和 Rails 6.0.0beta1,这似乎不是一个约束,因为如果我在任何地方进入 Elm REPL 并尝试导入日期,我将面临同样的错误:
> import Date
-- UNKNOWN IMPORT ---------------------------------------------------------- elm
The Elm_Repl module has a bad import:
import Date
I cannot find that module! Is there a typo in the module name?
When creating a package, all modules must live in the src/ directory.
我的 elm.json 文件如下所示:
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/html": "1.0.0",
"elm/time": "1.0.0",
"elm/json": "1.1.2",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
},
"indirect": {
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
解决方案
您尝试使用的代码已过时。Date
据我所知,已从core
Elm 0.19 中删除,没有直接替换或涵盖完全相同功能的间接替换。elm/time
旨在作为两者的官方继任者Date
and Time
,但它不提供您在此处需要的日期/时间字符串解析。
旧Date.fromString
的只是 JavaScript 解析 API 的一个薄包装器,因此不是很一致或定义良好。因此,为什么它被删除。在 Elm 0.19 中,您必须使用提供更具体功能的第三方包,例如elm-iso8601-date-strings。
如果您收到的是 ISO 8601 字符串,您应该能够替换parseTime
为:
import Iso8601
import Time
parseTime : String -> Time.Posix
parseTime string =
Iso8601.toTime string
|> Result.withDefault (Time.millisToPosix 0)
但是,如果您收到的不是 ISO 8601 格式,您需要找到另一个可以解析该特定格式的包。
推荐阅读
- c - C - 通过scanf获取数字后,但计算出错误的结果
- javascript - 如何使用 vanilla JavaScript 获取文本的字密度?
- r - 在 R Markdown 中使用 Stargazer 时出现浮动错误的字幕
- python - 当我们在 Django 中搜索某些产品时如何进行产品排序?
- android - 菜单未出现在自定义工具栏布局中
- reactjs - 如何将图像调用到reactjs和airtable中
- javascript - 在 ReactJS 中使用 HttpClient 下载 CSV 文件
- regex - 十进制数的正则表达式在颤动的TextFormField inputFormatters中不起作用
- swift - 如何在 Swift 框架中使用具有泛型和多重一致性的子协议来强制使用一致的 API?
- pandas - Seaborn Catplot 抛出错误:真值不明确