davla
03/20/2024, 4:42 PM<cfscript>
myutcdt = createDateTime("2024","7","1","12","00","00");
writedump(myutcdt);
setTimeZone("GB");
mylocaldt = dateConvert("utc2Local", myutcdt);
writedump(mylocaldt);
</cfscript>
Given a date that is in BST (British Summer Time) UTC+1. The code above shows my utc date/time as {ts '2024-07-01 12:00:00'} and the localdate shows as {ts '2024-07-01 14:00:00'} which is UTC+2 which is incorrect. Is this a bug or am I doing something daft. Both Lucee and ACF appear to do the same thing. I found a UDF DateConvertNoBug that produces the expected result {ts '2024-07-01 13:00:00'} . Why is the built-in dateConvert producing the wrong time?Patrick
03/20/2024, 4:56 PMPatrick
03/20/2024, 5:08 PMrstewart
03/20/2024, 5:24 PM<cfscript>
javatz = CreateObject("java", "java.util.TimeZone");
tz_list = javatz.getAvailableIDs();
writedump(var = tz_list, expand = false);
writeDump(getTimezone());
n = Now();
writeDump(n);
setTimezone('Etc/UTC');
writeDump(getTimezone());
d = Now();
writeDump(d);
setTimezone('America/Boise');
writeDump(getTimezone());
l = dateConvert('utc2local', d);
writeDump(l);
</cfscript>davla
03/20/2024, 5:41 PMPatrick
03/20/2024, 6:11 PMrstewart
03/20/2024, 9:07 PM<cfscript>
writeDump(getTimezone());
n = Now();
writeDump(n);
setTimezone('America/Boise');
writeDump(getTimezone());
writeDump(n);
</cfscript>
Note that when you dump n before and after the setTimezone() call, its value changes...
How is that even possible that a call to a function like that could go rippling through variables with values already assigned?rstewart
03/20/2024, 9:58 PM<cfscript>
setTimezone('America/Boise');
writeDump(getTimezone());
// Now, locally:
n = createDateTime(2024, 1, 1, 12, 0, 0);
writeDump(n);
u = dateConvert('local2utc', n);
writeDump(u);
l = dateConvert('utc2local', u);
writeDump(l);
</cfscript>
... and it seems to work in the same manner if I use 'Europe/London' for the timezone. Not sure if that helps?
Used in that context, dateConvert() makes sense but clearly calling setTimezone() has massive implications for any date-time variables laying around in your code before and after the call. There is some serious BFM going on under the JDK covers, it seems?rstewart
03/20/2024, 10:08 PMgetTimezoneInfo() includes arguments so you can ask for information about a specific timezone in case you need to do your own version of timezone-math. Adobe's does not support those same arguments and you're limited to getting information about the server's current timezone, whatever that might be.davla
03/20/2024, 10:15 PMrstewart
03/20/2024, 10:23 PMJohnT
03/21/2024, 1:27 PMdavla
03/21/2024, 1:27 PMmyutcdt = createDateTime("2024","7","1","12","00","00"); I assumed this to be in UTC. So July 1st 2024 12pm. However, I think that the createDateTime function is actually creating a local time which means that the above date in UTC is actually July 1st 2024 11am. Therefore the createDatetime has to be converted to utc as in @rstewart last code example. Then it all makes sense.
As usual trying to solve a problem that I created! head walldavla
03/21/2024, 1:32 PMbkbk
04/05/2024, 11:08 AMdavla
04/05/2024, 11:28 AM