2013-06-22 06:24:24 +00:00
|
|
|
'use strict';
|
2013-06-07 02:39:12 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
define(
|
|
|
|
[
|
2013-07-17 06:23:44 +00:00
|
|
|
'moment',
|
|
|
|
'filesize'
|
|
|
|
], function (Moment, Filesize) {
|
2013-06-07 02:39:12 +00:00
|
|
|
|
2013-07-17 06:23:44 +00:00
|
|
|
return {
|
2013-06-07 02:39:12 +00:00
|
|
|
|
2013-07-17 06:23:44 +00:00
|
|
|
Bytes: function (sourceSize) {
|
|
|
|
var size = Number(sourceSize);
|
|
|
|
return Filesize(size, 1, false);
|
|
|
|
},
|
2013-06-07 02:39:12 +00:00
|
|
|
|
2013-07-17 06:23:44 +00:00
|
|
|
DateHelper: function (sourceDate) {
|
|
|
|
if (!sourceDate) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
var date = Moment(sourceDate);
|
|
|
|
|
|
|
|
if (date.isAfter(Moment().add('days', 6))) {
|
|
|
|
return date.fromNow(true);
|
|
|
|
}
|
2013-06-21 01:43:58 +00:00
|
|
|
|
2013-07-18 00:28:33 +00:00
|
|
|
if (date.isBefore(Moment().add('days', -6))) {
|
|
|
|
return date.fromNow();
|
|
|
|
}
|
|
|
|
|
2013-07-17 06:23:44 +00:00
|
|
|
var calendarDate = date.calendar();
|
2013-07-18 00:28:33 +00:00
|
|
|
//TODO: It would be nice to not have to hack this...
|
2013-07-17 06:23:44 +00:00
|
|
|
return calendarDate.substring(0, calendarDate.indexOf(' at '));
|
|
|
|
},
|
|
|
|
|
|
|
|
pad: function(n, width, z) {
|
|
|
|
z = z || '0';
|
|
|
|
n = n + '';
|
|
|
|
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
2013-07-17 21:53:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Number: function (input) {
|
|
|
|
if (!input) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
2013-07-17 06:23:44 +00:00
|
|
|
}
|
2013-06-24 23:41:59 +00:00
|
|
|
}
|
|
|
|
});
|