6e6aa9b0
Tarpit Grover
Basic Setup
|
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
(function(angular){
var module = angular.module('framework.filters.utility',[]);
module.filter('RemoveSpaces', removeSpaces);
module.filter('Truncate', truncate);
module.filter('AbbrValue', abbrValue);
module.filter('Countdown', countdown);
function removeSpaces() {
return function (text) {
return text.replace(/\s/g, '');
}
}
function truncate () {
return function (text, length, end) {
if (isNaN(length))
length = 10;
if (end === undefined)
end = "...";
if (text.length <= length || text.length - end.length <= length)
{ return text; }
else
{ return String(text).substring(0, length - end.length) + end; }
}
}
function abbrValue() {
return function (val) {
return Math.abs(Number(val)) >= 1.0e+9
? Math.round(Math.abs((Number(val)) / 1.0e+9)*10)/10 + "b"
// Six Zeroes for Millions
: Math.abs(Number(val)) >= 1.0e+6
? Math.round(Math.abs((Number(val)) / 1.0e+6)*10)/10 + "m"
// Three Zeroes for Thousands
: Math.abs(Number(val)) >= 1.0e+3
? Math.round(Math.abs((Number(val)) / 1.0e+3)*10)/10 + "k"
: Math.abs(Number(val));
}
}
function countdown() {
return function (input) {
var substitute = function (stringOrFunction, number, strings) {
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, dateDifference) : stringOrFunction;
var value = (strings.numbers && strings.numbers[number]) || number;
return string.replace(/%d/i, value);
},
nowTime = (new Date()).getTime(),
date = (new Date(input)).getTime(),
allowFuture = true,
strings = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "ago",
suffixFromNow: "",//"from now"
seconds: "less than a minute",
minute: "a minute",
minutes: "%d minutes",
hour: "an hour",
hours: "%d hours",
day: "a day",
days: "%d days",
month: "a month",
months: "%d months",
year: "a year",
years: "%d years"
},
dateDifference = nowTime - date,
words,
seconds = Math.abs(dateDifference) / 1000,
minutes = seconds / 60,
hours = minutes / 60,
days = hours / 24,
years = days / 365,
separator = strings.wordSeparator === undefined ? " " : strings.wordSeparator,
prefix = strings.prefixAgo,
suffix = strings.suffixAgo;
if (allowFuture) {
if (dateDifference < 0) {
prefix = strings.prefixFromNow;
suffix = strings.suffixFromNow;
}
}
words = seconds < 45 && substitute(strings.seconds, Math.round(seconds), strings) ||
seconds < 90 && substitute(strings.minute, 1, strings) ||
minutes < 45 && substitute(strings.minutes, Math.round(minutes), strings) ||
minutes < 90 && substitute(strings.hour, 1, strings) ||
hours < 24 && substitute(strings.hours, Math.round(hours), strings) ||
hours < 42 && substitute(strings.day, 1, strings) ||
days < 30 && substitute(strings.days, Math.round(days), strings) ||
days < 45 && substitute(strings.month, 1, strings) ||
days < 365 && substitute(strings.months, Math.round(days / 30), strings) ||
years < 1.5 && substitute(strings.year, 1, strings) ||
substitute(strings.years, Math.round(years), strings);
return $.trim([prefix, words, suffix].join(separator));
}
}
})(angular);
|