浪费了两个小时的人参

因为一句话浪费了两个小时。

Ubuntu 16.04 安装 postgresql的时候,由于一开始的sudo apt-get install postgresql的最后步骤被默认的not
set locale 打断所以需要手动运行

1
sudo pg_createcluster --locale en_US.UTF-8 --start 9.5 main

要是直接没看到提示,错过了,下次删了再安装就永远不会有提示了。
直到你翻遍了半个google。

sqlite3 migrate to postgresql && swift parse response time string from api

Rails migrate sqlite3 into postgresql

reference
尝试了pgloader, 遇到的问题很多。一筹莫展了半个下午。
尝试sequel,意外地顺利。

1
sequel -C sqlite://db/production.sqlite3 postgres://user@localhost/db

得到的教训是从刚一开始就应该使用postgresql,其次sqlite3中并不严格检查表项的类型,
导致以前定义成timestamps的表项直接被当string存储下来,给时间的转换统一带来了不少麻烦。

将API传来的关于时间的string转换成Swift的Date

1
2
3
4
5
6
7
8
9
10
// str =  "2016-05-31T08:18:37.969Z"
// string.asDate(with: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
extension String {
func asDate(with dateFormat: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(identifier: "UTC")
dateFormatter.dateFormat = dateFormat
return dateFormatter.date(from: self)
}
}