比较Cloud Functions中的两个Firestore时间戳 [英] Compare two Firestore Timestamps in Cloud Functions
本文介绍了比较Cloud Functions中的两个Firestore时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Firestore中编写更新功能,我想比较两个Timestamp
.我已经尝试了多种方法,但是没有用.您能为我指出在Firestore中比较两个Timestamp
的正确方法吗?
I'm writing update function in Firestore and I want to compare two Timestamp
. I've tried multiple things but not working. Can you point me correct way of comparing two Timestamp
in firestore.
exports.updateFunction = functions.firestore
.document('xyz/{xyzId}')
.onUpdate((change, context) => {
var updatedXYZ = change.after.data();
var oldXYZ = change.before.data();
var newTimestamp = updatedXYZ.timing;
var oldTimestamp = oldXYZ.timing;
// I've tried following things but not working
var result = newTimestamp === oldTimestamp; // not working
var result = new Date(newTimestamp) - new Date(oldTimestamp); // not working
return true;
});
我要检查两个时间戳是否相同.
I want to check two Timestamp is same or not.
推荐答案
咨询Firestore的时间戳对象.时间戳具有一种称为
Consult the API docs for Firestore's Timestamp object. Timestamp has a method called isEqual() that will compare two timestamps.
var result = newTimestamp.isEqual(oldTimestamp);
这篇关于比较Cloud Functions中的两个Firestore时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文