Bug 1154717 - Fix toLocalTimeISOString(). r=yoric,a=lmandel
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Wed, 15 Apr 2015 15:48:03 +0200
changeset 267222 3b81354f6a5b2419d7762f2aba4c5179ee8184c3
parent 267221 9c3834da969ea2513ff8a200b30e8b8e8f3d68f6
child 267223 17f73d964965d84870ed239f3818c72b833c699f
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyoric, lmandel
bugs1154717
milestone39.0a2
Bug 1154717 - Fix toLocalTimeISOString(). r=yoric,a=lmandel
toolkit/components/telemetry/TelemetrySession.jsm
toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
--- a/toolkit/components/telemetry/TelemetrySession.jsm
+++ b/toolkit/components/telemetry/TelemetrySession.jsm
@@ -248,28 +248,29 @@ function toLocalTimeISOString(date) {
     number = number.toString();
     while (number.length < places) {
       number = "0" + number;
     }
     return number;
   }
 
   let sign = (n) => n >= 0 ? "+" : "-";
-  let tzOffset = date.getTimezoneOffset();
+  // getTimezoneOffset counter-intuitively returns -60 for UTC+1.
+  let tzOffset = - date.getTimezoneOffset();
 
   // YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
   return    padNumber(date.getFullYear(), 4)
     + "-" + padNumber(date.getMonth() + 1, 2)
     + "-" + padNumber(date.getDate(), 2)
     + "T" + padNumber(date.getHours(), 2)
     + ":" + padNumber(date.getMinutes(), 2)
     + ":" + padNumber(date.getSeconds(), 2)
     + "." + date.getMilliseconds()
-    + sign(tzOffset) + Math.abs(Math.floor(tzOffset / 60))
-    + ":" + Math.abs(tzOffset % 60);
+    + sign(tzOffset) + padNumber(Math.floor(Math.abs(tzOffset / 60)), 2)
+    + ":" + padNumber(Math.abs(tzOffset % 60), 2);
 }
 
 /**
  * Read current process I/O counters.
  */
 let processInfo = {
   _initialized: false,
   _IO_COUNTERS: null,
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
@@ -255,25 +255,33 @@ function checkPingFormat(aPing, aType, a
   Assert.equal("clientId" in aPing, aHasClientId);
   Assert.equal("environment" in aPing, aHasEnvironment);
 }
 
 function checkPayloadInfo(data) {
   const ALLOWED_REASONS = [
     "environment-change", "shutdown", "daily", "saved-session", "test-ping"
   ];
-  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
   let numberCheck = arg => { return (typeof arg == "number"); };
   let positiveNumberCheck = arg => { return numberCheck(arg) && (arg >= 0); };
   let stringCheck = arg => { return (typeof arg == "string") && (arg != ""); };
-  let isoDateCheck = arg => { return stringCheck(arg) && !Number.isNaN(Date.parse(arg)); }
   let revisionCheck = arg => {
     return (Services.appinfo.isOfficial) ? stringCheck(arg) : (typeof arg == "string");
   };
-  let uuidCheck = arg => uuidRegex.test(arg);
+  let uuidCheck = arg => {
+    const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
+    return uuidRegex.test(arg);
+  };
+  let isoDateCheck = arg => {
+    // We expect use of this version of the ISO format:
+    // 2015-04-12T18:51:19.1+00:00
+    const isoDateRegEx = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+[+-]\d{2}:\d{2}$/;
+    return stringCheck(arg) && !Number.isNaN(Date.parse(arg)) &&
+           isoDateRegEx.test(arg);
+  };
 
   const EXPECTED_INFO_FIELDS_TYPES = {
     reason: stringCheck,
     revision: revisionCheck,
     timezoneOffset: numberCheck,
     sessionId: uuidCheck,
     subsessionId: uuidCheck,
     // Special case: previousSubsessionId is null on first run.