【问题标题】:How to check the type of a Firestore server timestamp in ClojureScript?如何在 ClojureScript 中检查 Firestore 服务器时间戳的类型?
【发布时间】:2020-04-29 11:01:29
【问题描述】:

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

如何在不提前知道字段名称的情况下检查这些字段的类型是否与 Firestore 时间戳类型匹配?

【问题讨论】:

    标签: node.js google-cloud-firestore timestamp clojurescript


    【解决方案1】:

    已解决:

    (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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-30
      • 2018-11-27
      • 2021-04-19
      • 2021-12-21
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 2021-08-14
      相关资源
      最近更新 更多