【发布时间】:2020-04-29 11:01:29
【问题描述】:
当我从 Firestore 获取带有时间戳的文档时,时间戳序列化为 [Object],因此我需要将这些字段值转换为日期时间瞬间。为此,我需要能够遍历文档数据并转换时间戳。
如何在不提前知道字段名称的情况下检查这些字段的类型是否与 Firestore 时间戳类型匹配?
【问题讨论】:
标签: node.js google-cloud-firestore timestamp clojurescript
当我从 Firestore 获取带有时间戳的文档时,时间戳序列化为 [Object],因此我需要将这些字段值转换为日期时间瞬间。为此,我需要能够遍历文档数据并转换时间戳。
如何在不提前知道字段名称的情况下检查这些字段的类型是否与 Firestore 时间戳类型匹配?
【问题讨论】:
标签: node.js google-cloud-firestore timestamp clojurescript
(ns some.namespace
(:require ["@google-cloud/firestore" :as firestore]
[clojure.walk :as walk]))
(def Timestamp (.-Timestamp firestore))
(defn fire->date [fire-date]
(.toDate fire-date))
(defn fire->clj [doc]
(walk/postwalk
(fn [x]
(cond
(= (type x) Timestamp) (fire->date x)
:default x))
doc))
【讨论】: