Move pretty date filter to shared client.js
This commit is contained in:
@@ -99,6 +99,42 @@ angular.module('Application').filter('prettyDiskSize', function () {
|
||||
return function (size, fallback) { return prettyByteSize(size, fallback) || 'Not available yet'; };
|
||||
});
|
||||
|
||||
angular.module('Application').filter('prettyDate', function () {
|
||||
// http://ejohn.org/files/pretty.js
|
||||
return function prettyDate(utc) {
|
||||
var date = new Date(utc), // this converts utc into browser timezone and not cloudron timezone!
|
||||
diff = (((new Date()).getTime() - date.getTime()) / 1000) + 30, // add 30seconds for clock skew
|
||||
day_diff = Math.floor(diff / 86400);
|
||||
|
||||
if (isNaN(day_diff) || day_diff < 0)
|
||||
return 'just now';
|
||||
|
||||
return day_diff === 0 && (
|
||||
diff < 60 && 'just now' ||
|
||||
diff < 120 && '1 minute ago' ||
|
||||
diff < 3600 && Math.floor( diff / 60 ) + ' minutes ago' ||
|
||||
diff < 7200 && '1 hour ago' ||
|
||||
diff < 86400 && Math.floor( diff / 3600 ) + ' hours ago') ||
|
||||
day_diff === 1 && 'Yesterday' ||
|
||||
day_diff < 7 && day_diff + ' days ago' ||
|
||||
day_diff < 31 && Math.ceil( day_diff / 7 ) + ' weeks ago' ||
|
||||
day_diff < 365 && Math.round( day_diff / 30 ) + ' months ago' ||
|
||||
Math.round( day_diff / 365 ) + ' years ago';
|
||||
};
|
||||
});
|
||||
|
||||
angular.module('Application').filter('prettyLongDate', function () {
|
||||
return function prettyLongDate(utc) {
|
||||
return moment(utc).format('MMMM Do YYYY, h:mm:ss a'); // this converts utc into browser timezone and not cloudron timezone!
|
||||
};
|
||||
});
|
||||
|
||||
angular.module('Application').filter('prettyShortDate', function () {
|
||||
return function prettyShortDate(utc) {
|
||||
return moment(utc).format('MMMM Do YYYY'); // this converts utc into browser timezone and not cloudron timezone!
|
||||
};
|
||||
});
|
||||
|
||||
angular.module('Application').filter('markdown2html', function () {
|
||||
var converter = new showdown.Converter({
|
||||
simplifiedAutoLink: true,
|
||||
|
||||
Reference in New Issue
Block a user