So this is what the below code should do. I am essentially making objects that expire at the midnight mark of the different timezones. The way I think I should do this is to first take user location and find the corresponding timezone. From there, take the current date in that timezone and make a time-formatted string (currentTimestamp) so it expires at the end of the day at 11:59:59 PM. Then convert this time to UTC (because that's how the server operates) and then obviously I end up removing the object from my database when the time is passed. So for example, I'm trying to get this to work in the Shanghai timezone, but I'm getting a weird and very wrong value for UTC moment. Here's what it looks like:
let timezone = tzlookup(latitude, longitude);
let currentDate = new Date()
let localizedDateAndTime = moment.tz(currentDate, timezone).format('YYYY-MM-DD hh:mm:ss')
let localizedDate = moment.tz(currentDate, timezone).format('YYYY-MM-DD')
console.log("Timezone: " + timezone)
console.log("Local Time: " + localizedDateAndTime)
console.log("UTC Time: " + moment.tz(currentDate, 'UTC').format())
let date = ("0" + currentDate.getDate()).slice(-2);
let month = ("0" + (currentDate.getMonth() + 1)).slice(-2);
let year = currentDate.getFullYear();
let currentTimestamp = localizedDate + " " + 23 + ":" + 59 + ":" + 59
console.log("Localized timestamp: " + currentTimestamp)
var localizedMoment = moment.tz(currentTimestamp, 'YYYY-MM-DD hh:mm:ss', timezone);
var utcMoment = localizedMoment.utc()
console.log("UTC Moment (when event expires in UTC): " + utcMoment.format('YYYY-MM-DD hh:mm:ss'))
let timestamp = utcMoment.format('YYYY-MM-DD hh:mm:ss')
https://i.stack.imgur.com/deRbS.png
So I guess it shouldn't be 03:59:59 for the time, but rather something like 15:59:59, right? Not sure why it converts to 03:59:59...