| 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);
|
| + }
|
| +};
|
|
|