You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
58 lines
1.5 KiB
11 years ago
|
'use strict';
|
||
11 years ago
|
|
||
11 years ago
|
define(
|
||
|
[
|
||
11 years ago
|
'moment',
|
||
|
'filesize'
|
||
|
], function (Moment, Filesize) {
|
||
11 years ago
|
|
||
11 years ago
|
return {
|
||
11 years ago
|
|
||
11 years ago
|
bytes: function (sourceSize) {
|
||
11 years ago
|
var size = Number(sourceSize);
|
||
|
return Filesize(size, 1, false);
|
||
|
},
|
||
11 years ago
|
|
||
11 years ago
|
dateHelper: function (sourceDate) {
|
||
11 years ago
|
if (!sourceDate) {
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
var date = Moment(sourceDate);
|
||
|
|
||
11 years ago
|
var calendarDate = date.calendar();
|
||
|
|
||
|
//TODO: It would be nice to not have to hack this...
|
||
|
var strippedCalendarDate = calendarDate.substring(0, calendarDate.indexOf(' at '));
|
||
|
|
||
|
if (strippedCalendarDate){
|
||
|
return strippedCalendarDate;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
if (date.isAfter(Moment())) {
|
||
|
return date.fromNow(true);
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
if (date.isBefore(Moment().add('years', -1))) {
|
||
|
return date.format('ll');
|
||
|
}
|
||
|
|
||
11 years ago
|
return date.fromNow();
|
||
11 years ago
|
},
|
||
|
|
||
|
pad: function(n, width, z) {
|
||
|
z = z || '0';
|
||
|
n = n + '';
|
||
|
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
||
11 years ago
|
},
|
||
|
|
||
11 years ago
|
number: function (input) {
|
||
11 years ago
|
if (!input) {
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
return input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
});
|