1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-27 10:19:41 +00:00
Radarr/UI/Shared/FormatHelpers.js
2013-07-17 17:28:33 -07:00

50 lines
1.3 KiB
JavaScript

'use strict';
define(
[
'moment',
'filesize'
], function (Moment, Filesize) {
return {
Bytes: function (sourceSize) {
var size = Number(sourceSize);
return Filesize(size, 1, false);
},
DateHelper: function (sourceDate) {
if (!sourceDate) {
return '';
}
var date = Moment(sourceDate);
if (date.isAfter(Moment().add('days', 6))) {
return date.fromNow(true);
}
if (date.isBefore(Moment().add('days', -6))) {
return date.fromNow();
}
var calendarDate = date.calendar();
//TODO: It would be nice to not have to hack this...
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;
},
Number: function (input) {
if (!input) {
return '';
}
return input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
});