1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2025-03-04 18:48:36 +00:00
Sonarr/UI/Shared/FormatHelpers.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

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