gsr
11/18/2024, 8:04 PMpublic struct function checkTimeExpiration3(dateExpired, timezoneOffset, dstFlag) {
// Get current time in UTC
var currentTime = dateConvert("local2UTC", now());
dump(currentTime);
// Convert expiration date to UTC considering the timezone offset and DST
var offsetHours = val(left(timezoneOffset, 3));
var offsetMinutes = val(right(timezoneOffset, 2));
var totalOffsetMinutes = (offsetHours * 60) + offsetMinutes;
// Add DST hour if applicable
if (dstFlag == "1") {
totalOffsetMinutes += 60;
}
// Convert expiration date to UTC by subtracting the offset
var expirationUTC = dateAdd("n", -totalOffsetMinutes, dateExpired);
dump(expirationUTC);
// Calculate time difference in seconds instead of minutes
var timeDiffSeconds = dateDiff("s", currentTime, expirationUTC);
dump(timeDiffSeconds);
// If expired
if (timeDiffSeconds <= 0) {
return {
result: "Expired",
formattedTime: '<span style="color:red; font-weight:bold;">This invitation has expired</span>'
};
}
// Calculate remaining time components
var days = fix(timeDiffSeconds / (24 * 60 * 60));
var remainingSeconds = timeDiffSeconds mod (24 * 60 * 60);
var hours = fix(remainingSeconds / 3600);
remainingSeconds = remainingSeconds mod 3600;
var minutes = fix(remainingSeconds / 60);
var seconds = remainingSeconds mod 60;
// Format the time remaining
var components = [];
if (days > 0) components.append("#days# days");
if (hours > 0) components.append("#hours# hours");
if (minutes > 0) components.append("#minutes# minutes");
if (seconds > 0 || arrayLen(components) == 0) components.append("#seconds# seconds");
return {
result: "Not expired",
formattedTime: arrayLen(components) ? arrayToList(components, ", ") & " remaining" : "0 seconds remaining"
};
}
but i tried to convert the time to PST time zone which has the value from database -8:00,1 but its always giving me 1 hour aheadTomy Saman
11/18/2024, 10:51 PMgsr
11/19/2024, 1:16 PMrodyon
11/19/2024, 4:46 PM