Copy link to clipboard
Copied
Hello,
I am not sure if this is a bug or if I am not using the tag correctly. The following occurs in ColdFusion 2018 release.
If I setup a new event with cfexchangecalendar, using the following event parameters, the timezone changes to (UTC+00:00) Monrovia, Reykjavik (and the event time is therefore incorrect):
<cfset local.event.Message = "Event Message">
<cfset local.event.Subject = "Event Subject">
<cfset local.event.AllDayEvent = "no">
<cfset local.event.StartTime = createDateTime(2019, 7, 26, 0, 0, 0)>
<cfset local.event.EndTime = createDateTime(2019, 7, 27, 0, 0, 0)>
<cfset local.event.IsRecurring = "yes">
<cfset local.event.RecurrenceType = "WEEKLY">
<cfset local.event.RecurrenceEndDate = createDateTime(2019, 12, 31, 0, 0, 0)>
<cfset local.event.RecurrenceDays = "MON">
Any assistance would be appreciated.
Thank you,
Robert
Copy link to clipboard
Copied
Does this help?
<cfset local.event.StartTime = dateConvert("utc2local", createDateTime(2019, 7, 26, 0, 0, 0))>
<cfset local.event.EndTime = dateConvert("utc2local", createDateTime(2019, 7, 27, 0, 0, 0))>
<cfset local.event.RecurrenceEndDate = dateConvert("utc2local", createDateTime(2019, 12, 31, 0, 0, 0))>
Copy link to clipboard
Copied
That was a really good suggestion, but unfortunately, the result is the same. The time gets changed to UTC 0 even though I pass all time events through the dateConvert "utc2local" function.
It is odd, because if I do not set a recurring event everything is ok. As soon as I specify that it is a recurring event, the times get changed.
Copy link to clipboard
Copied
If the function dateConvert("utc2local", dateObj) isn't working as expected, then there is probably a bug. You should report it in Tracker
In the meantime, let's look for a workaround.
Copy link to clipboard
Copied
Will do. Thank you.
Copy link to clipboard
Copied
For the time being, you might like to use the following functions:
<cfscript>
string function convertUTCToLocal (date utcDatetime, string timezone) {
var utcFormat=createobject("java","java.text.SimpleDateFormat").init("yyyy-MM-dd HH:mm:ss");
var utcTimezone=createobject("java","java.util.TimeZone").getTimezone("UTC");
utcFormat.setTimeZone(utcTimezone);
var utcDatetimeString=datetimeFormat(arguments.utcDatetime, "yyyy-MM-dd HH:nn:ss");
var utcDatetimeFormatted=utcFormat.parse(utcDatetimeString);
var localFormat=createobject("java","java.text.SimpleDateFormat").init("yyyy-MM-dd HH:mm:ss");
var localTimezone=createobject("java","java.util.TimeZone").getTimezone(arguments.timezone);
localFormat.setTimeZone(localTimezone);
var localDatetime=localFormat.format(utcDatetimeFormatted)
return localDatetime.toString();
}
string function convertLocalToUTC (date localDatetime, string timezone) {
var localFormat=createobject("java","java.text.SimpleDateFormat").init("yyyy-MM-dd HH:mm:ss");
var localTimezone=createobject("java","java.util.TimeZone").getTimezone(arguments.timezone);
localFormat.setTimeZone(localTimezone);
var localDatetimeString=datetimeFormat(arguments.localDatetime, "yyyy-MM-dd HH:nn:ss");
var localDatetimeFormatted=localFormat.parse(localDatetimeString);
var utcFormat=createobject("java","java.text.SimpleDateFormat").init("yyyy-MM-dd HH:mm:ss");
var utcTimezone=createobject("java","java.util.TimeZone").getTimezone("UTC");
utcFormat.setTimeZone(utcTimezone);
var utcDatetime=utcFormat.format(localDatetimeFormatted);
return utcDatetime.toString();
}
/***** Example of conversion from local datetime to UTC *****/
myLocalTimezone="Europe/Amsterdam";
myLocaldatetime=createdatetime(2019,08,18,16,21,05);
utcDate=convertLocalToUTC(myLocaldatetime, myLocalTimezone);
writeoutput("UTC datetime: " & utcDate)
/***** Example of conversion from UTC to local datetime *****/
/*myLocalTimezone="Asia/Shanghai";
utcDatetime=createdatetime(2019,8,18,13,56,37);
localDatetime=convertUTCToLocal(utcDatetime, myLocalTimezone);
writeoutput("Local datetime: " & localDatetime)*/
</cfscript>
Copy link to clipboard
Copied
Thank you for your help. I tried using your convertLocalToUTC function but unfortunately the times still get changed.
Copy link to clipboard
Copied
rob_cyberdyne wrote
Thank you for your help. I tried using your convertLocalToUTC function but unfortunately the times still get changed.
This now confuses me. What are the
that you wish to convert to UTC?
Copy link to clipboard
Copied
If I put today's date, with a weekly Monday occurrence, I get a series of calendar events that start on Monday at 22:00 and end on Tuesday at 22:00.
I pass the start and end date as below:
myLocaldatetime=createdatetime(2019,08,19,0,0,0);
convertLocalToUTC(myLocaldatetime, "Europe/Madrid")
Copy link to clipboard
Copied
rob_cyberdyne wrote
If I put today's date, with a weekly Monday occurrence, I get a series of calendar events that start on Monday at 22:00 and end on Tuesday at 22:00.
Let's then apply the code I gave you
<cfscript>
string function convertLocalToUTC (date localDatetime, string timezone) {
var localFormat=createobject("java","java.text.SimpleDateFormat").init("yyyy-MM-dd HH:mm:ss");
var localTimezone=createobject("java","java.util.TimeZone").getTimezone(arguments.timezone);
localFormat.setTimeZone(localTimezone);
var localDatetimeString=datetimeFormat(arguments.localDatetime, "yyyy-MM-dd HH:nn:ss");
var localDatetimeFormatted=localFormat.parse(localDatetimeString);
var utcFormat=createobject("java","java.text.SimpleDateFormat").init("yyyy-MM-dd HH:mm:ss");
var utcTimezone=createobject("java","java.util.TimeZone").getTimezone("UTC");
utcFormat.setTimeZone(utcTimezone);
var utcDatetime=utcFormat.format(localDatetimeFormatted);
return utcDatetime.toString();
}
myLocalStartDatetime=createdatetime(2019,08,19,22,0,0);
myLocalEndDatetime=createdatetime(2019,08,20,22,0,0);
utcStartDateTime=convertLocalToUTC(myLocalStartDatetime, "Europe/Madrid");
utcEndDateTime=convertLocalToUTC(myLocalEndDatetime, "Europe/Madrid");
writeoutput("Start datetime converted to UTC: " & utcStartDateTime);
writeoutput("<br>");
writeoutput("End datetime converted to UTC: " & utcEndDateTime);
</cfscript>
The above code gives me the expected result, namely:
Start datetime converted to UTC: 2019-08-19 20:00:00
End datetime converted to UTC: 2019-08-20 20:00:00
Copy link to clipboard
Copied
The code that you supplied is not the issue. The issue is that the cfexchangecalendar tag is not working as expected.
When an event is not setup as a "Recurring Event", the timezone is fine. When set as a "Recurring Event", the timezone switches and even if I use the functions you provided, the times are always out of sync.
Copy link to clipboard
Copied
We saw the same behavior on all events...not just recurring...after updating to CF2018. Everything switched to UTC time.
Did you post a bug to Adobe? I will vote it up, if so.
Copy link to clipboard
Copied
Yes, the bug post can be found here: