Index: chrome/browser/resources/file_manager/js/file_manager.js |
=================================================================== |
--- chrome/browser/resources/file_manager/js/file_manager.js (revision 138096) |
+++ chrome/browser/resources/file_manager/js/file_manager.js (working copy) |
@@ -121,6 +121,11 @@ |
var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; |
/** |
+ * Number of milliseconds in a day. |
+ */ |
+ var MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000; |
+ |
+ /** |
* Item for the Grid View. |
* @constructor |
*/ |
@@ -328,8 +333,12 @@ |
this.metadataCache_ = MetadataCache.createFull(); |
- this.shortDateFormatter_ = |
- this.locale_.createDateTimeFormat({'dateType': 'medium'}); |
+ this.dateFormatter_ = v8Intl.DateTimeFormat( |
+ undefined, |
dgozman
2012/05/21 15:45:41
Comment what undefined means.
Oleg Eterevsky
2012/05/21 15:53:55
Done.
|
+ {year: 'numeric', month: 'short', day: 'numeric', |
+ hour: 'numeric', minute: 'numeric'}); |
+ this.timeFormatter_ = v8Intl.DateTimeFormat( |
+ undefined, {hour: 'numeric', minute: 'numeric'}); |
this.collator_ = this.locale_.createCollator({ |
'numeric': true, 'ignoreCase': true, 'ignoreAccents': true}); |
@@ -671,6 +680,16 @@ |
this.setListType(listType); |
this.textSearchState_ = {text: '', date: new Date()}; |
+ |
+ // Update metadata once per minute to change 'Today' and 'Yesterday' |
dgozman
2012/05/21 15:45:41
Wrong comment?
Oleg Eterevsky
2012/05/21 15:53:55
Done.
|
+ // modification time on |
+ var today = new Date(); |
+ today.setHours(0); |
+ today.setMinutes(0); |
+ today.setSeconds(0); |
+ today.setMilliseconds(0); |
+ setTimeout(this.dailyUpdateModificationTime_.bind(this), |
+ today.getTime() + MILLISECONDS_IN_DAY - Date.now() + 1000); |
}; |
FileManager.prototype.initRootsList_ = function() { |
@@ -1962,9 +1981,25 @@ |
FileManager.prototype.updateDate_ = function(div, filesystemProps) { |
if (!filesystemProps) { |
div.textContent = '...'; |
+ return; |
+ } |
+ |
+ var modTime = filesystemProps.modificationTime; |
+ var today = new Date(); |
+ today.setHours(0); |
+ today.setMinutes(0); |
+ today.setSeconds(0); |
+ today.setMilliseconds(0); |
+ |
+ if (modTime >= today && |
+ modTime < today.getTime() + MILLISECONDS_IN_DAY) { |
+ div.textContent = strf('TIME_TODAY', this.timeFormatter_.format(modTime)); |
+ } else if (modTime >= today - MILLISECONDS_IN_DAY && modTime < today) { |
+ div.textContent = strf('TIME_YESTERDAY', |
+ this.timeFormatter_.format(modTime)); |
} else { |
div.textContent = |
- this.shortDateFormatter_.format(filesystemProps.modificationTime); |
+ this.dateFormatter_.format(filesystemProps.modificationTime); |
} |
}; |
@@ -2012,6 +2047,20 @@ |
} |
}; |
+ FileManager.prototype.dailyUpdateModificationTime_ = function() { |
+ var fileList = this.directoryModel_.getFileList(); |
+ var urls = []; |
+ for (var i = 0; i < fileList.length; i++) { |
+ urls.push(fileList.item(i).toURL()); |
+ } |
+ this.metadataCache_.get( |
+ urls, 'filesystem', |
dgozman
2012/05/21 15:45:41
Passing entries instead of urls will greatly speed
Oleg Eterevsky
2012/05/21 15:53:55
Done.
|
+ this.updateMetadataInUI_.bind(this, 'filesystem', urls)); |
+ |
+ setTimeout(this.dailyUpdateModificationTime_.bind(this), |
+ MILLISECONDS_IN_DAY); |
+ }; |
+ |
FileManager.prototype.updateMetadataInUI_ = function( |
type, urls, properties) { |
if (this.listType_ != FileManager.ListType.DETAIL) return; |