Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/utils.js

Issue 29459562: Issue 5278 - Improved date formatting approach, in particular fixing broken formatting in 32-bit Li… (Closed) Base URL: https://hg.adblockplus.org/adblockplus
Patch Set: Use default locale after all Created June 8, 2017, 8:47 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 /** 246 /**
247 * Formats a unix time according to user's locale. 247 * Formats a unix time according to user's locale.
248 * @param {Integer} time unix time in milliseconds 248 * @param {Integer} time unix time in milliseconds
249 * @return {String} formatted date and time 249 * @return {String} formatted date and time
250 */ 250 */
251 formatTime: function(time) 251 formatTime: function(time)
252 { 252 {
253 try 253 try
254 { 254 {
255 let date = new Date(time); 255 return Utils.dateFormatter.format(time);
256 return Utils.dateFormatter.FormatDateTime("", Ci.nsIScriptableDateFormat.d ateFormatShort,
257 Ci.nsIScriptableDateFormat.timeF ormatNoSeconds,
258 date.getFullYear(), date.getMont h() + 1, date.getDate(),
259 date.getHours(), date.getMinutes (), date.getSeconds());
260 } 256 }
261 catch(e) 257 catch(e)
262 { 258 {
263 // Make sure to return even on errors 259 // Make sure to return even on errors
264 Cu.reportError(e); 260 Cu.reportError(e);
265 return ""; 261 return "";
266 } 262 }
267 }, 263 },
268 264
269 /** 265 /**
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 XPCOMUtils.defineLazyServiceGetter(Utils, "promptService", "@mozilla.org/embedco mp/prompt-service;1", "nsIPromptService"); 549 XPCOMUtils.defineLazyServiceGetter(Utils, "promptService", "@mozilla.org/embedco mp/prompt-service;1", "nsIPromptService");
554 XPCOMUtils.defineLazyServiceGetter(Utils, "effectiveTLD", "@mozilla.org/network/ effective-tld-service;1", "nsIEffectiveTLDService"); 550 XPCOMUtils.defineLazyServiceGetter(Utils, "effectiveTLD", "@mozilla.org/network/ effective-tld-service;1", "nsIEffectiveTLDService");
555 XPCOMUtils.defineLazyServiceGetter(Utils, "netUtils", "@mozilla.org/network/util ;1", "nsINetUtil"); 551 XPCOMUtils.defineLazyServiceGetter(Utils, "netUtils", "@mozilla.org/network/util ;1", "nsINetUtil");
556 XPCOMUtils.defineLazyServiceGetter(Utils, "styleService", "@mozilla.org/content/ style-sheet-service;1", "nsIStyleSheetService"); 552 XPCOMUtils.defineLazyServiceGetter(Utils, "styleService", "@mozilla.org/content/ style-sheet-service;1", "nsIStyleSheetService");
557 XPCOMUtils.defineLazyServiceGetter(Utils, "prefService", "@mozilla.org/preferenc es-service;1", "nsIPrefService"); 553 XPCOMUtils.defineLazyServiceGetter(Utils, "prefService", "@mozilla.org/preferenc es-service;1", "nsIPrefService");
558 XPCOMUtils.defineLazyServiceGetter(Utils, "versionComparator", "@mozilla.org/xpc om/version-comparator;1", "nsIVersionComparator"); 554 XPCOMUtils.defineLazyServiceGetter(Utils, "versionComparator", "@mozilla.org/xpc om/version-comparator;1", "nsIVersionComparator");
559 XPCOMUtils.defineLazyServiceGetter(Utils, "windowMediator", "@mozilla.org/appshe ll/window-mediator;1", "nsIWindowMediator"); 555 XPCOMUtils.defineLazyServiceGetter(Utils, "windowMediator", "@mozilla.org/appshe ll/window-mediator;1", "nsIWindowMediator");
560 XPCOMUtils.defineLazyServiceGetter(Utils, "windowWatcher", "@mozilla.org/embedco mp/window-watcher;1", "nsIWindowWatcher"); 556 XPCOMUtils.defineLazyServiceGetter(Utils, "windowWatcher", "@mozilla.org/embedco mp/window-watcher;1", "nsIWindowWatcher");
561 XPCOMUtils.defineLazyServiceGetter(Utils, "chromeRegistry", "@mozilla.org/chrome /chrome-registry;1", "nsIXULChromeRegistry"); 557 XPCOMUtils.defineLazyServiceGetter(Utils, "chromeRegistry", "@mozilla.org/chrome /chrome-registry;1", "nsIXULChromeRegistry");
562 XPCOMUtils.defineLazyServiceGetter(Utils, "systemPrincipal", "@mozilla.org/syste mprincipal;1", "nsIPrincipal"); 558 XPCOMUtils.defineLazyServiceGetter(Utils, "systemPrincipal", "@mozilla.org/syste mprincipal;1", "nsIPrincipal");
563 XPCOMUtils.defineLazyServiceGetter(Utils, "dateFormatter", "@mozilla.org/intl/sc riptabledateformat;1", "nsIScriptableDateFormat");
564 XPCOMUtils.defineLazyServiceGetter(Utils, "httpProtocol", "@mozilla.org/network/ protocol;1?name=http", "nsIHttpProtocolHandler"); 559 XPCOMUtils.defineLazyServiceGetter(Utils, "httpProtocol", "@mozilla.org/network/ protocol;1?name=http", "nsIHttpProtocolHandler");
565 XPCOMUtils.defineLazyServiceGetter(Utils, "clipboard", "@mozilla.org/widget/clip board;1", "nsIClipboard"); 560 XPCOMUtils.defineLazyServiceGetter(Utils, "clipboard", "@mozilla.org/widget/clip board;1", "nsIClipboard");
566 XPCOMUtils.defineLazyServiceGetter(Utils, "clipboardHelper", "@mozilla.org/widge t/clipboardhelper;1", "nsIClipboardHelper"); 561 XPCOMUtils.defineLazyServiceGetter(Utils, "clipboardHelper", "@mozilla.org/widge t/clipboardhelper;1", "nsIClipboardHelper");
562 XPCOMUtils.defineLazyGetter(Utils, "dateFormatter", function()
563 {
564 return new Intl.DateTimeFormat(undefined, {
565 year: "numeric",
566 month: "numeric",
567 day: "numeric",
568 hour: "numeric",
569 minute: "numeric"
570 });
571 });
567 XPCOMUtils.defineLazyGetter(Utils, "crypto", function() 572 XPCOMUtils.defineLazyGetter(Utils, "crypto", function()
568 { 573 {
569 try 574 try
570 { 575 {
571 let ctypes = Cu.import("resource://gre/modules/ctypes.jsm", null).ctypes; 576 let ctypes = Cu.import("resource://gre/modules/ctypes.jsm", null).ctypes;
572 577
573 let nsslib; 578 let nsslib;
574 try 579 try
575 { 580 {
576 nsslib = ctypes.open(ctypes.libraryName("nss3")); 581 nsslib = ctypes.open(ctypes.libraryName("nss3"));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 Cu.reportError(e); 735 Cu.reportError(e);
731 // Expected, ctypes isn't supported in Gecko 1.9.2 736 // Expected, ctypes isn't supported in Gecko 1.9.2
732 return null; 737 return null;
733 } 738 }
734 }); 739 });
735 740
736 if ("@mozilla.org/messenger/headerparser;1" in Cc) 741 if ("@mozilla.org/messenger/headerparser;1" in Cc)
737 XPCOMUtils.defineLazyServiceGetter(Utils, "headerParser", "@mozilla.org/messen ger/headerparser;1", "nsIMsgHeaderParser"); 742 XPCOMUtils.defineLazyServiceGetter(Utils, "headerParser", "@mozilla.org/messen ger/headerparser;1", "nsIMsgHeaderParser");
738 else 743 else
739 Utils.headerParser = null; 744 Utils.headerParser = null;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld