tracker issue : CF-3802931

select a category, or use search below
(searches all categories and all time range)
Title:

dateCompare() interprets supplied date value if set using dateConvert('local2Utc',now())

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/AsDesigned

Reporter/Name(from Bugbase): Dave Cahill / Dave Cahill (web-eng)

Created: 08/10/2014

Components: Language

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final /

Priority/Frequency: Major / All users will encounter

Locale/System: English / Windows 7 64-bit

Vote Count: 0

Problem Description:
When supplying a dateTime value to dateCompare that is generated from  dateConvert('local2Utc',now()), dateCompare uses the "now() value" instead of the "dateConverted value".


Steps to Reproduce:

<cfset date1 = dateConvert('local2Utc', now())>
<cfset date2 = createDateTime(2014,08,09,13,20,00)>

<cfoutput>
<p>Time of test = #Now()#</p>
<p>date1 = #date1#</p>
<p>date2 = #date2#</p>
<p>dateCompare(date1, date2 ) = #dateCompare(date1, date2 )#</p>

Actual Result:

Time of test = {ts '2014-08-09 14:18:42'}
date1 = {ts '2014-08-09 04:18:42'}
date2 = {ts '2014-08-09 13:20:00'}
dateCompare(date1, date2 ) = 1

Expected Result:

Time of test = {ts '2014-08-09 14:18:42'}
date1 = {ts '2014-08-09 04:18:42'}
date2 = {ts '2014-08-09 13:20:00'}
dateCompare(date1, date2 ) = -1

Any Workarounds:
When setting a UTC dateTime value for date1, don't use dateConvert, instead use dateAdd()
<cfset date1 = DateAdd("s", GetTimeZoneInfo().UTCTotalOffset, now())>

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3802931

External Customer Info:
External Company:  
External Customer Name: web-eng
External Customer Email:  
External Test Config: My Hardware and Environment details:

Running CF10 on local and remote shared hosting.

Attachments:

Comments:

When testing, ensure that you choose a value for date2 that is between now() and dateConvert('local2Utc',now()). Obviously this will be a different range depending on your time zone. I have no idea which of your product areas to select so just picked performance.
Comment by External U.
11401 | August 10, 2014 09:01:36 AM GMT
Really? As designed?? Well perhaps you ought to update the documentation. At the moment the description states "Performs a full date/time comparison of two dates." There is no mention of it interpreting dates and then performing the comparison. On the off-chance that you missed the point of my bug report, check this link: https://forums.adobe.com/message/6625139#6625139
Comment by External U.
11402 | August 25, 2014 04:22:07 AM GMT
Hi web-eng, This comparison illustrates the CF9 bug that CF10 fixed: <!--- CF10 ---> <cfscript> //Server tz is EDT (UTC -4) in this example dateTime = createDateTime(2014,8,9,12,0,0);//value is August 9, 2014 12:00:00 EDT date1 = dateConvert('local2UTC', dateTime);//value is August 9, 2014 16:00:00 UTC (August 9, 2014 12:00:00 EDT) date2 = dateAdd("h", 4, dateTime);//value is August 9, 2014 16:00:00 EDT (August 9, 2014 20:00:00 UTC) </cfscript> <cfoutput>#getHTTPTimeString(date1)# is #getHTTPTimeString(date2)#: #date1 is date2#</cfoutput> <!--- Sat, 09 Aug 2014 16:00:00 GMT is Sat, 09 Aug 2014 20:00:00 GMT: NO ---> <!--- CF9 ---> <cfscript> //Server tz is EDT (UTC -4) in this example dateTime = createDateTime(2014,8,9,12,0,0);//value is August 9, 2014 12:00:00 EDT date1 = dateConvert('local2UTC', dateTime);//value is August 9, 2014 16:00:00 EDT (August 9, 2014 20:00:00 UTC) (bug b/c 2014,8,9,12,0,0 EDT is not 2014,8,9,20,0,0 UTC) date2 = dateAdd("h", 4, dateTime);//value is August 9, 2014 16:00:00 EDT (August 9, 2014 20:00:00 UTC) </cfscript> <cfoutput>#getHTTPTimeString(date1)# is #getHTTPTimeString(date2)#: #date1 is date2#</cfoutput> <!--- Sat, 09 Aug 2014 20:00:00 GMT is Sat, 09 Aug 2014 20:00:00 GMT: YES ---> Thanks!, -Aaron
Comment by External U.
11403 | November 23, 2014 06:12:04 PM GMT
Aaron, just so we're clear, this bug report is not for dateConvert, it's for dateCompare. I appreciate your desire to contribute, but advising how well dateConvert works in CF10 seems off target. Regards, Dave.
Comment by External U.
11404 | November 23, 2014 09:34:45 PM GMT
Hi Dave, CF10 Update 4 changed dateConvert() wrt underlying time zone offset. This affects what you're seeing in dateCompare(), b/c dateCompare() respects underlying time zone offset. date1 = dateConvert('local2Utc', now()) date1 = {ts '2014-08-09 04:18:42'} Before the change: date1's underlying time zone is server's time zone (incorrect, b/c time zone should be UTC after adding the UTC offset) After the change: date1's underlying time zone is UTC While dateCompare() appears to have changed, getHTTPTimeString(date1) gives a clearer view (b/c it outputs time zone as well) of the value of date1 that dateCompare() is using. Basically, use #getHTTPTimeString(date1)# instead of #date1#. Thanks, -Aaron
Comment by External U.
11405 | November 24, 2014 12:45:37 AM GMT
Aaron, I've confirmed your findings with respect to dateConvert being the culprit and that dateCompare appears to be fine. (Presuming we can trust getHTTPTimeString) You say that dateConvert was fixed in update 4, but it's not working on my local server and my webhost server even though we're at CF10 update 12! Anything to add here or should we be raising a bug report for that?
Comment by External U.
11406 | November 24, 2014 01:43:17 AM GMT
Hi Dave, Thank you for confirming. Regarding a dateConvert() issue, I would definitely raise another bug report w/ repro code. Thanks!, -Aaron
Comment by External U.
11407 | November 24, 2014 06:28:23 PM GMT
Hey Aaron, just when I thought this bug was settled.... ha ha. So I went back over all the code and have discovered that the bug you said was fixed in CF10 had been fixed in my version and had nothing to do with my results at all. My bad there! Next though is that the bug does exist when using the tag combination of DateConvert() to set a date and then dateCompare() to compare the dates. Whilst your suggested work-around works fine, there is still a bug when using these functions together. Below is my test code and results. Make sure you choose a value for “testDate” which is between Now() and UTC time otherwise you won’t see the prob. Note that the last 2 lines in results should both be “1”. TEST CODE <cfset DateConvertUTC = dateConvert('local2Utc', now())> <cfset GetTimeZoneInfoUTC = DateAdd("s", GetTimeZoneInfo().UTCTotalOffset, now())> <cfset testDate = createDateTime(2014,12,18,03,00,00)> <cfoutput> <p>DateConvertUTC = #DateConvertUTC#</p> <p>GetTimeZoneInfoUTC= #GetTimeZoneInfoUTC#</p> <p>testDate = #testDate#</p> <p>&nbsp;</p> <p>dateCompare(DateConvertUTC, testDate ) = #dateCompare(DateConvertUTC, testDate )#</p> <p>dateCompare(GetTimeZoneInfoUTC, testDate ) = #dateCompare(GetTimeZoneInfoUTC, testDate )#</p> </cfoutput> RESULTS DateConvertUTC = {ts '2014-12-18 06:33:22'} GetTimeZoneInfoUTC= {ts '2014-12-18 06:33:22'} testDate = {ts '2014-12-18 03:00:00'} dateCompare(DateConvertUTC, testDate ) = -1 dateCompare(GetTimeZoneInfoUTC, testDate ) = 1
Comment by External U.
11408 | December 18, 2014 01:16:31 AM GMT