如何在ClojureScript中检查Firestore服务器时间戳的类型?

问题描述 投票:0回答:1

当我从Firestore中获取带有时间戳的文档时,时间戳序列化为[Object],因此我需要将这些字段值转换为日期时间点。为此,我需要能够遍历文档数据并转换时间戳。

如何检查这些字段的类型是否与Firestore时间戳类型匹配,而不提前知道字段名称是什么?

node.js google-cloud-firestore timestamp clojurescript
1个回答
0
投票

已解决:

(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))
© www.soinside.com 2019 - 2024. All rights reserved.