Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Unified Diff: ui/file_manager/file_manager/foreground/js/ui/file_metadata_formatter.js

Issue 1789593002: Files app: Loading detailed information for single file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/file_manager/foreground/js/ui/file_metadata_formatter.js
diff --git a/ui/file_manager/file_manager/foreground/js/ui/file_metadata_formatter.js b/ui/file_manager/file_manager/foreground/js/ui/file_metadata_formatter.js
new file mode 100644
index 0000000000000000000000000000000000000000..61703d0defad00420b0de234b195124a6da1d90f
--- /dev/null
+++ b/ui/file_manager/file_manager/foreground/js/ui/file_metadata_formatter.js
@@ -0,0 +1,78 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * Formatter class for file metadatas.
+ * @constructor
+ */
+function FileMetadataFormatter() {
+ this.setDateTimeFormat(true);
+}
+
+/**
+ * Sets date and time format.
+ * @param {boolean} use12hourClock True if 12 hours clock, False if 24 hours.
+ */
+FileMetadataFormatter.prototype.setDateTimeFormat = function(use12hourClock) {
+ this.timeFormatter_ = new Intl.DateTimeFormat(
+ [] /* default locale */,
+ {hour: 'numeric', minute: 'numeric', hour12: use12hourClock});
+ this.dateFormatter_ = new Intl.DateTimeFormat(
+ [] /* default locale */,
+ {
+ year: 'numeric', month: 'short', day: 'numeric',
+ hour: 'numeric', minute: 'numeric', hour12: use12hourClock
+ });
+};
+
+/**
+ * Generates a formatted modification time text.
+ * @param {Date} modTime
+ * @return {string} A string that represents modification time.
+ */
+FileMetadataFormatter.prototype.formatModDate = function (modTime) {
+ if (!modTime) {
+ return '...';
+ }
+ var today = new Date();
+ today.setHours(0);
+ today.setMinutes(0);
+ today.setSeconds(0);
+ today.setMilliseconds(0);
+
+ /**
+ * Number of milliseconds in a day.
+ */
+ var MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
+
+ if (isNaN(modTime.getTime())) {
+ // In case of 'Invalid Date'.
+ return '--';
+ } else if (modTime >= today &&
+ modTime < today.getTime() + MILLISECONDS_IN_DAY) {
+ return strf('TIME_TODAY', this.timeFormatter_.format(modTime));
+ } else if (modTime >= today - MILLISECONDS_IN_DAY && modTime < today) {
+ return strf('TIME_YESTERDAY', this.timeFormatter_.format(modTime));
+ } else {
+ return this.dateFormatter_.format(modTime);
+ }
+};
+
+/**
+ * Generates a formatted filesize text.
+ * @param {number=} size
+ * @param {boolean=} hosted
+ * @return {string} A string that represents a file size.
+ */
+FileMetadataFormatter.prototype.formatSize = function (size, hosted) {
+ if (size === null || size === undefined) {
+ return '...';
+ } else if (size === -1) {
+ return '--';
+ } else if (size === 0 && hosted) {
+ return '--';
+ } else {
+ return util.bytesToString(size);
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698