Announcement

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

    SmartClient 7.0rc2 patch for issue with XML Schema date times

    In SmartClient 7.0 rc2, a bug exists whereby for certain timezone offsets, time stamps will not be correctly parsed into live date objects.

    This has subsequently been resolved and will not be an issue with more recent builds.

    This patch code will resolve the issue for version 7.0rc2:

    Code:
    //----------------------------------------------------------------------------
    // Isomorphic SmartClient 7.0rc2 patch
    // Purpose: Fixes an issue when parsing XML date-time stamps for certain
    // explicitly specified timezones.
    // 
    // Applies to SmartClient 7.0RC2 builds only
    //----------------------------------------------------------------------------
    
    if (window.isc && isc.version.startsWith("7.0rc2/")) {
    
    isc.addProperties(Date, {
    parseSchemaDate : function (value) {
        if (isc.isA.Date(value)) return value;
    
        if (!isc.isA.String(value)) value = (value.toString ? value.toString() : value + "");
    
        // Notes on regex:
        // - result[4] is the optional timestamp including the T and colon separators
        // - result[8] would be the optional milliseconds including the ".", whereas
        //   result[9] is just the numeric part
        //   results[10] is the timezone - either "Z" (zulu time or GMT) or +/- HH:MM
        var result = value.match(/(\d{4})[\/-](\d{2})[\/-](\d{2})([T ](\d{2}):(\d{2}):(\d{2}))?(\.(\d+))?([+-]\d{2}:\d{2}|Z)?/);
               
        //isc.Log.logWarn("isDate: '" + value + "', regex match: " + result);
    
        if (result == null) return null;
                
        var dateValue;
        // NOTE: pass only the relevant arguments as Moz does not like being passed nulls
        if (!result[4]) { // no time
            dateValue = new Date(result[1], result[2] - 1, result[3]);
        } else if (!result[9]) { // no ms
            dateValue = new Date(Date.UTC(result[1], result[2] - 1, result[3],
                                          result[5], result[6], result[7]));
        } else {
            var ms = result[9];
            
            // XML Schema says any number of fractional digits can be specified.  new Date() is
            // expecting a whole number of milliseconds (and further precision would be ignored).
            // Multiply by a power of ten based on the number of digits provided, such that ".9"
            // becomes 900 and ".98367" becomes 984.
            if (ms.length != 3) {
                var multiplier = Math.pow(10,3-ms.length);
                ms = Math.round(parseInt(ms,10) * multiplier);
            }
            //isc.Log.logWarn("ms is: " + ms);
            
            dateValue = new Date(Date.UTC(result[1], result[2] - 1, result[3],
                                          result[5], result[6], result[7], ms));
        }
        // Handle timezone offset from GMT
        if (result[10] && result[10].toLowerCase() != "z") {
            var HM = result[10].split(":"),
                H = HM[0],
                negative = H && H.startsWith("-"),
                M = HM[1];
            H = parseInt(H, 10);
            M = parseInt(M, 10);
            var dateTime = dateValue.getTime();
    
            // Note no need to account for negative on hours since the "+" or "-" prefix was picked up
            // in parseInt
            if (isc.isA.Number(H)) dateTime -= (3600000 * H);
            if (isc.isA.Number(M)) dateTime -= (60000 * M * (negative ? -1 : 1));
            dateValue.setTime(dateTime);
        }
         
        return dateValue
    
    }
    });
    } else if (window.isc) {
        isc.Log.logWarn("Patch code included for version 7.0rc2. You're running version:" + isc.version
         + " this patch code will have no effect and can be removed.");
    }
Working...
X