Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    getDefaultDisplayTimezone

    Hi,

    There seems to be a problem with the way the Time.getDefaultDisplayTimezone() was implemented ...

    The problem arises when dealing with negative time offsets (timezone). With negative time offsets,
    non significant leading zeros are not being output.

    For example, it outputs "+05:00" for positive offsets (good) and "-8:00" for negative offsets (bad).

    Following, is a full example to reproduce this, as well as a suggested patch that fixes the specific
    issue at hand (not regression tested) :

    Code:
    <HTML>
    	<HEAD>
    		<META HTTP-EQUIV="X-UA-Compatible" CONTENT="IE=9" />
    <SCRIPT>
    window.isomorphicDir = 'isomorphic/';
    </SCRIPT>
    
    		<SCRIPT SRC="isomorphic/system/modules/ISC_Core.js"></SCRIPT>
    		<SCRIPT SRC="isomorphic/system/modules/ISC_Foundation.js"></SCRIPT>
    		<SCRIPT SRC="isomorphic/system/modules/ISC_Containers.js"></SCRIPT>
    		<SCRIPT SRC="isomorphic/system/modules/ISC_Grids.js"></SCRIPT>
    		<SCRIPT SRC="isomorphic/system/modules/ISC_Forms.js"></SCRIPT>
    		<SCRIPT SRC="isomorphic/system/modules/ISC_DataBinding.js"></SCRIPT>
    		<SCRIPT SRC="isomorphic/skins/MEI/load_skin.js"></SCRIPT>
    
    		<TITLE>Investigation - isc.Time.setDefaultDisplayTimezone()</TITLE>
    		<style type="text/css">
    .bad {
    	color : red;
    }
    
    .good {
    	color : green;
    }
    		</style>
    	</HEAD>
    
    	<BODY STYLE="overflow:hidden">
    		<h1>Bug with isc.Time.getDefaultDisplayTimezone()</h1>
    		
    		<p>Explanation: when a timezone offset is negative, the value returned by isc.Time.getDefaultDisplayTimezone() is not compliant with the documented "+/-HH:MM" format</p>
    		
    		Examples with default implementation as of SmartClient_SC_SNAPSHOT-2012-03-13_v82p:
    		<ul>
    			<li>Time offset of +05:00:<span class="good">
    				<script>
    				isc.Time.setDefaultDisplayTimezone('+05:00');
    		
    				document.write(isc.Time.getDefaultDisplayTimezone());
    				</script>
    				</span>
    			</li>
    			<li>Time offset of -08:00:<span class="bad">
    				<script>
    				isc.Time.setDefaultDisplayTimezone('-08:00');
    				document.write(isc.Time.getDefaultDisplayTimezone());
    				</script>
    				</span>
    			</li>
    		</ul>
    
    
    		<SCRIPT>
    isc.Time.getDefaultDisplayTimezone = function () {
    	var H = this.UTCHoursDisplayOffset,
        	M = this.UTCMinutesDisplayOffset,
        	negative = H < 0;
    	return (!negative ? "+" : "-") +
    		((negative ? -1 : 1) * H).stringify(2) + ":" + ((negative ? -1 : 1) * M).stringify(2);
    };
    </SCRIPT>
    
    		Examples with corrected implementation:
    		<ul>
    			<li>Time offset of +05:00:<span class="good">
    				<script>
    				isc.Time.setDefaultDisplayTimezone('+05:00');
    		
    				document.write(isc.Time.getDefaultDisplayTimezone());
    				</script>
    				</span>
    			</li>
    			<li>Time offset of -08:00:<span class="good">
    				<script>
    				isc.Time.setDefaultDisplayTimezone('-08:00');
    				document.write(isc.Time.getDefaultDisplayTimezone());
    				</script>
    				</span>
    			</li>
    		</ul>
    
    		Suggested patch for SmartClient_SC_SNAPSHOT-2012-03-13_v82p/smartclientSDK/source/client/language/Time.js:
    		<br />
    		<textarea rows="15" cols="100">
    --- SmartClient_SC_SNAPSHOT-2012-03-13_v82p/smartclientSDK/source/client/language/Time.js
    +++ SmartClient_SC_SNAPSHOT-2012-03-13_v82p/smartclientSDK/source/client/language/Time-2.js
    @@ -139,8 +139,8 @@
             var H = this.UTCHoursDisplayOffset,
                 M = this.UTCMinutesDisplayOffset,
                 negative = H < 0;
    -        return (!negative ? "+" : "") +
    -                H.stringify(2) + ":" + ((negative ? -1 : 1) * M).stringify(2);
    +        return (!negative ? "+" : "-") +
    +            ((negative ? -1 : 1) * H).stringify(2) + ":" + ((negative ? -1 : 1) * M).stringify(2);
         },
             
         //>	@classAttr	isc.Time._timeExpressions (Array : [..] : IRA)
    </textarea>
    
    	</BODY>
    </HTML>
    Thanks,

    #2
    Thanks for the clear example and suggested patch. From a first look, this looks correct. We'll do a little more testing and roll it into the codebase (probably today)

    Regards
    Isomorphic Software

    Comment


      #3
      So I can remove my local patch, I need this included in your 8.2p branch.

      Please let me know when it's been integrated so I can update to latest.

      Thanks,

      Comment


        #4
        We've implemented it now - so it will be present in the next nightly (both 8.2 and 8.3 branches)

        Comment


          #5
          Excellent. Thanks!

          I'll wait for the updated version that also contains a fix for
          http://forums.smartclient.com/showthread.php?t=21386


          Thanks,

          Comment

          Working...
          X