我正在 Firestore 中编写更新函数,我想比较两个Timestamp
。我尝试了多种方法但没有成功。你能指出我比较两个的正确方法吗Timestamp
在消防库里。
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;
});
我想检查两个时间戳是否相同。
请参阅 Firestore 的 API 文档时间戳对象。 https://cloud.google.com/nodejs/docs/reference/firestore/0.15.x/Timestamp时间戳有一个方法叫做是平等的() https://cloud.google.com/nodejs/docs/reference/firestore/0.15.x/Timestamp#isEqual这将比较两个时间戳。
var result = newTimestamp.isEqual(oldTimestamp);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)