The following code works fine in 4.5 and ACF:
<cfset utcNow = dateConvert("local2UTC", now())>
But in Lucee 5 i get this helpful advice:
This function is no longer supported, because it gives you the wrong impression that the timezone
is part of the date object, what is wrong!When you wanna convert a Date to String based on the
UTC timezone, do for example [DateTimeFormat(date:now(),timezone:'UTC')].
Presumably this is an ACF incompatibility… what should i do here? Raise an issue for Velvet
? Or was there a specific reason for introducing this change?
@micstriit responds:
This function is terrible because it does not was is described, every use of this function is misleading, but we can remove this restriction and reenable it… I will raise this with tag
My only issue is that it breaks ACF compatibility. What would i use instead that works on both ACF and Lucee 5?
@micstriit ripostes:
Point is, when you use this function something with your code is wrong. A timezone is for a date nothing other than a locale, a locale influence how a date looks like when you output it.
So for example 5.6.12 for de-ch
But 6/5/12 for en-usBut the date is still the same and most important the date object is independent from any locale same for timezone
So you cannot convert a date from being local to being UTC.
So there is no replacement for invalid code.
Question is how to fix this code.
This is all well and good, but I am a humble CFML developer. What can I do to replace this code with something that works with both Lucee 5 and ACF?
<cfset utcNow = dateConvert("local2UTC", now())>
<cfset utcDateTime = dateFormat(utcNow, "yyyy-mm-dd") & " " & timeFormat(utcNow, "hh:mm:ss") & " +0000">
Or am I better off just ripping this out of my code base and replacing it with something less “terrible” If I do this what about all the other poor chumps using this function?