Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

DateTime through local2utc through JSON bug

Advocate ,
Apr 05, 2016 Apr 05, 2016

I believe I found a bug in CF11 with DateTime comparisons when dealing with UTC converted values going through serializeJSON then deserializeJSON. I did modify the code to not include the local2utc conversion and that seemed to produce correct results. Can someone please confirm:

<cfscript>
  variables.dttm = createDateTime(2016,04,03,17,53,0);
  variables.dttmutc = dateConvert('local2utc',variables.dttm);

  variables.base = {};
  variables.base.dttmutc_min = dateConvert('local2utc',dateAdd('h',-1,variables.dttm));
  variables.base.dttmutc_max = dateConvert('local2utc',dateAdd('n',1,variables.dttm));

  variables.viajson = deserializeJSON(serializeJSON(variables.base));
  variables.viajson.dttmutc_min = parseDateTime(variables.viajson.dttmutc_min);  // to me this parsing should not be required
  variables.viajson.dttmutc_max = parseDateTime(variables.viajson.dttmutc_max);  // same
</cfscript>
<cfoutput>

  <h1>base</h1>
  dttm = #variables.dttm#<br />
  dttmutc = #variables.dttmutc#<br />
  dttmutc_min = #variables.base.dttmutc_min#<br />
  dttmutc_max = #variables.base.dttmutc_max#<br />
  <br />
  dttmutc GT dttmutc_min = #variables.dttmutc GT variables.base.dttmutc_min#<br />
  dttmutc LT dttmutc_max = #variables.dttmutc LT variables.base.dttmutc_max#<br />

  <h1>via json</h1>
  dttm = #variables.dttm#<br />
  dttmutc = #variables.dttmutc#<br />
  dttmutc_min = #variables.viajson.dttmutc_min#<br />
  dttmutc_max = #variables.viajson.dttmutc_max#<br />
  <br />
  dttmutc GT dttmutc_min = #variables.dttmutc GT variables.viajson.dttmutc_min# (should be YES)<br />  // this is the failing comparison
  dttmutc LT dttmutc_max = #variables.dttmutc LT variables.viajson.dttmutc_max#<br />
</cfoutput>

My results are as follows:

base

dttm = {ts '2016-04-03 17:53:00'}

dttmutc = {ts '2016-04-04 00:53:00'}

dttmutc_min = {ts '2016-04-03 23:53:00'}

dttmutc_max = {ts '2016-04-04 00:54:00'}

dttmutc GT dttmutc_min = YES

dttmutc LT dttmutc_max = YES

via json

dttm = {ts '2016-04-03 17:53:00'}

dttmutc = {ts '2016-04-04 00:53:00'}

dttmutc_min = {ts '2016-04-03 23:53:00'}

dttmutc_max = {ts '2016-04-04 00:54:00'}

dttmutc GT dttmutc_min = NO (should be YES)

dttmutc LT dttmutc_max = YES

BTW, I'm not sure if it matters but my time zone is Pacific Daylight Time (PDT).

268
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Resources