forked from cockpit-project/registry-image-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.js
88 lines (74 loc) · 2.07 KB
/
date.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* globals moment */
(function() {
angular.module('registryUI.date', [])
.provider("MomentLib", [
function() {
var self = this;
/* Until we come up with a good default implementation, must be provided */
self.MomentLibFactory = "globalMoment";
function load(injector, name) {
if (angular.isString(name))
return injector.get(name, "MomentLib");
else
return injector.invoke(name);
}
self.$get = [
"$injector",
function($injector) {
return load($injector, self.MomentLibFactory);
}
];
}
])
.factory("globalMoment", [
function() {
return moment;
}
])
.factory('dateRefreshMinute', [
"$rootScope",
function($rootScope) {
var interval = null;
return {
enable: function() {
if (interval === null) {
interval = window.setInterval(function() {
$rootScope.$applyAsync();
}, 60000);
}
},
disable: function() {
if (interval !== null) {
window.clearInterval(interval);
interval = null;
}
},
};
}
])
.filter('dateRelative', [
"MomentLib",
"dateRefreshMinute",
function(momentLib) {
if (typeof(momentLib) === 'function') {
momentLib.createFromInputFallback = function(config) {
config._d = new Date(config._i);
};
}
function dateRelative(timestamp) {
if (!timestamp)
return timestamp;
return momentLib(timestamp).fromNow();
}
/* When moment is not loaded fall back to simple behavior */
function dateAbsolute(timestamp) {
return timestamp;
}
dateRelative.$stateful = true;
if (typeof(momentLib) === 'function')
return dateRelative;
else
return dateAbsolute;
}
]);
}());