I followed different answers from here and here
I'm just getting started learning Cloud Tasks
from here. In that blog post Doug says "What I want is for expirationAtSeconds to be the time of expiration expressed in epoch seconds".
I want the Task to delete the post when that time is set. In my iOS app I create a post that expires at a specific time:
let timeStamp = Date().timeIntervalSince1970
let postDate: Date = Date(timeIntervalSince1970: timeStamp)
var expirationDate: Date? = Calendar.current.date(byAdding: .hour, value: +24, to: postDate)
guard let exp = expirationDate else { return }
let expiresAt = exp.timeIntervalSince1970
dict.updateValue(expiresAt, forKey: "expiresAt")
dict.updateValue(timeStamp, forKey: "postDate")
// other values ...
ref.updateChildValues(dict)
which gives me a database value like:
posts
some_post_Id
-"expiresAt": 1632627680.340107
// other values ...
In my cloud function I want the expiresAt date which is a Double
expressed in Epoch
seconds. I'm not sure if I should use expDate1, expDate2, expDate3, or expDate4:
exports.onCreatePost = functions.database.ref('/posts/{postId}').onCreate((snapshot, context) => {
const post = snapshot.data();
const expiresAt = snapshot.child("expiresAt").val();
const expirationDate = expiresAt.valueOf(); // 1632627680.340107
var expDate1 = DateTime.fromMillisecondsSinceEpoch(expirationDate * 1000)
var expDate2 = DateTime.fromMicrosecondsSinceEpoch(expirationDate * 1000000)
var expDate3 = DateTime.fromMicrosecondsSinceEpoch(expirationDate.microsecondsSinceEpoch)
var expDate4 = expirationDate.toDate()
const expirationAtSeconds = either expDate1, expDate2, expDate3, or expDate4
// continue on with the rest of the code ...
});