Bug 1396211 - Use mozIntl for dates in aboutTelemetry.js, clean up unused code r=chutten draft
authorFrancesco Lodolo (:flod) <flod@lodolo.net>
Sat, 02 Sep 2017 12:00:25 +0200
changeset 659295 34eab3e454802f14ea55c1d3c40f22792315de80
parent 659208 8886840becc88c60eb76a42531a30123414fc154
child 729957 f5f47b49882681b88d11410b3c6b5136f76c650d
push id78095
push userbmo:francesco.lodolo@gmail.com
push dateTue, 05 Sep 2017 20:41:00 +0000
reviewerschutten
bugs1396211
milestone57.0a1
Bug 1396211 - Use mozIntl for dates in aboutTelemetry.js, clean up unused code r=chutten MozReview-Commit-ID: KdUDzYNQqvD
toolkit/content/aboutTelemetry.css
toolkit/content/aboutTelemetry.js
--- a/toolkit/content/aboutTelemetry.css
+++ b/toolkit/content/aboutTelemetry.css
@@ -37,17 +37,18 @@ body {
   position: absolute;
   bottom: 0;
   left: 0;
 }
 
 .heading {
   display: flex;
   flex-direction: column;
-  font-size: 18px;
+  font-size: 17px;
+  font-weight: 600;
   pointer-events: none;
   padding: 12px 8px;
 }
 
 .header {
   display: flex;
 }
 
--- a/toolkit/content/aboutTelemetry.js
+++ b/toolkit/content/aboutTelemetry.js
@@ -161,59 +161,16 @@ function getMainWindowWithPreferencesPan
  * Remove all child nodes of a document node.
  */
 function removeAllChildNodes(node) {
   while (node.hasChildNodes()) {
     node.removeChild(node.lastChild);
   }
 }
 
-/**
- * Pad a number to two digits with leading "0".
- */
-function padToTwoDigits(n) {
-  return String(n).padStart(2, "0");
-}
-
-/**
- * Return yesterdays date with the same time.
- */
-function yesterday(date) {
-  let d = new Date(date);
-  d.setDate(d.getDate() - 1);
-  return d;
-}
-
-/**
- * Return tomorrow's date with the same time.
- */
-function tomorrow(date) {
-  let d = new Date(date);
-  d.setDate(d.getDate() + 1);
-  return d;
-}
-
-/**
- * This returns a short date string of the form YYYY/MM/DD.
- */
-function shortDateString(date) {
-  return date.getFullYear()
-         + "/" + padToTwoDigits(date.getMonth() + 1)
-         + "/" + padToTwoDigits(date.getDate());
-}
-
-/**
- * This returns a short time string of the form hh:mm:ss.
- */
-function shortTimeString(date) {
-  return padToTwoDigits(date.getHours())
-         + ":" + padToTwoDigits(date.getMinutes())
-         + ":" + padToTwoDigits(date.getSeconds());
-}
-
 var Settings = {
   SETTINGS: [
     // data upload
     {
       pref: PREF_FHR_UPLOAD_ENABLED,
       defaultPrefValue: false,
     },
     // extended "Telemetry" recording
@@ -450,34 +407,42 @@ var PingPicker = {
   },
 
   _renderPingList() {
     let pingSelector = document.getElementById("choose-ping-id");
     Array.from(pingSelector.children).forEach((child) => removeAllChildNodes(child));
 
     let pingTypes = new Set();
     pingTypes.add(this.TYPE_ALL);
-    let todayString =  (new Date()).toDateString();
-    let yesterdayString = yesterday(new Date()).toDateString();
+
+    const today = new Date();
+    today.setHours(0, 0, 0, 0);
+    const yesterday = new Date(today);
+    yesterday.setDate(today.getDate() - 1);
+
     for (let p of this._archivedPings) {
       pingTypes.add(p.type);
-      let date = new Date(p.timestampCreated);
-      let datetext = date.toLocaleDateString() + " " + shortTimeString(date);
-      let text = datetext + ", " + p.type;
+      const pingDate = new Date(p.timestampCreated);
+      const datetimeText = Services.intl.createDateTimeFormat(undefined, {
+          dateStyle: "short",
+          timeStyle: "medium"
+        }).format(pingDate);
+      const pingName = `${datetimeText}, ${p.type}`;
 
       let option = document.createElement("option");
-      let content = document.createTextNode(text);
+      let content = document.createTextNode(pingName);
       option.appendChild(content);
       option.setAttribute("value", p.id);
       option.dataset.type = p.type;
-      option.dataset.date = datetext;
+      option.dataset.date = datetimeText;
 
-      if (date.toDateString() == todayString) {
+      pingDate.setHours(0, 0, 0, 0);
+      if (pingDate.getTime() === today.getTime()) {
         pingSelector.children[0].appendChild(option);
-      } else if (date.toDateString() == yesterdayString) {
+      } else if (pingDate.getTime() === yesterday.getTime()) {
         pingSelector.children[1].appendChild(option);
       } else {
         pingSelector.children[2].appendChild(option);
       }
     }
     this._renderPingTypes(pingTypes);
   },