2013-06-22 09:24:24 +03:00
|
|
|
'use strict';
|
2013-06-07 05:39:12 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
define(
|
|
|
|
[
|
2013-07-17 09:23:44 +03:00
|
|
|
'moment',
|
|
|
|
'filesize'
|
|
|
|
], function (Moment, Filesize) {
|
2013-06-07 05:39:12 +03:00
|
|
|
|
2013-07-17 09:23:44 +03:00
|
|
|
return {
|
2013-06-07 05:39:12 +03:00
|
|
|
|
2013-08-04 04:27:12 +03:00
|
|
|
bytes: function (sourceSize) {
|
2013-07-17 09:23:44 +03:00
|
|
|
var size = Number(sourceSize);
|
|
|
|
return Filesize(size, 1, false);
|
|
|
|
},
|
2013-06-07 05:39:12 +03:00
|
|
|
|
2013-08-04 04:27:12 +03:00
|
|
|
dateHelper: function (sourceDate) {
|
2013-07-17 09:23:44 +03:00
|
|
|
if (!sourceDate) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
var date = Moment(sourceDate);
|
|
|
|
|
2013-07-18 05:37:39 +03:00
|
|
|
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;
|
2013-07-17 09:23:44 +03:00
|
|
|
}
|
2013-06-21 04:43:58 +03:00
|
|
|
|
2013-07-18 05:37:39 +03:00
|
|
|
if (date.isAfter(Moment())) {
|
|
|
|
return date.fromNow(true);
|
2013-07-18 03:28:33 +03:00
|
|
|
}
|
|
|
|
|
2013-07-20 04:21:13 +03:00
|
|
|
if (date.isBefore(Moment().add('years', -1))) {
|
|
|
|
return date.format('ll');
|
|
|
|
}
|
|
|
|
|
2013-07-18 05:37:39 +03:00
|
|
|
return date.fromNow();
|
2013-07-17 09:23:44 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
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-18 00:53:25 +03:00
|
|
|
},
|
|
|
|
|
2013-08-04 04:27:12 +03:00
|
|
|
number: function (input) {
|
2013-07-18 00:53:25 +03:00
|
|
|
if (!input) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
2013-07-17 09:23:44 +03:00
|
|
|
}
|
2013-06-25 02:41:59 +03:00
|
|
|
}
|
|
|
|
});
|