@muhammadn fixed issue #1716 - 'absolute' time formatting setting is not reflected on pending tickets.
This commit is contained in:
parent
6c90628944
commit
307ce2f506
2 changed files with 219 additions and 97 deletions
|
@ -31,7 +31,7 @@ class App.PrettyDate
|
||||||
|
|
||||||
if type is undefined && window.App && window.App.Config
|
if type is undefined && window.App && window.App.Config
|
||||||
type = window.App.Config.get('pretty_date_format')
|
type = window.App.Config.get('pretty_date_format')
|
||||||
if type is 'absolute' && direction is 'past'
|
if type is 'absolute' && (direction is 'past' || direction is 'future')
|
||||||
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
||||||
weekday = weekdays[created.getDay()]
|
weekday = weekdays[created.getDay()]
|
||||||
|
|
||||||
|
|
|
@ -1,49 +1,53 @@
|
||||||
|
|
||||||
// pretty date
|
// pretty date
|
||||||
test("check pretty date", function() {
|
test("check pretty date", function() {
|
||||||
var current = new Date()
|
var current = new Date()
|
||||||
|
// use date formatting as functions to make it more flexible
|
||||||
|
prettyDateRelative(current, '', true, 'relative');
|
||||||
|
prettyDateAbsolute(current, '', true, 'absolute');
|
||||||
|
|
||||||
// past
|
// past
|
||||||
var result = App.PrettyDate.humanTime(current);
|
|
||||||
|
function prettyDateRelative(current, escalation, lng, type) {
|
||||||
|
var result = App.PrettyDate.humanTime(current, escalation, lng, type);
|
||||||
equal(result, 'just now', 'just now')
|
equal(result, 'just now', 'just now')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - 15000);
|
result = App.PrettyDate.humanTime(current - 15000, escalation, lng, type);
|
||||||
equal(result, 'just now', 'just now')
|
equal(result, 'just now', 'just now')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - 60000);
|
result = App.PrettyDate.humanTime(current - 60000, escalation, lng, type);
|
||||||
equal(result, '1 minute ago', '1 min ago')
|
equal(result, '1 minute ago', '1 min ago')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (2 * 60000));
|
result = App.PrettyDate.humanTime(current - (2 * 60000), escalation, lng, type);
|
||||||
equal(result, '2 minutes ago', '2 min ago')
|
equal(result, '2 minutes ago', '2 min ago')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60)) ;
|
result = App.PrettyDate.humanTime(current - (60000 * 60), escalation, lng, type);
|
||||||
equal(result, '1 hour ago', '1 hour')
|
equal(result, '1 hour ago', '1 hour')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60 * 2));
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 2), escalation, lng, type);
|
||||||
equal(result, '2 hours ago', '2 hours')
|
equal(result, '2 hours ago', '2 hours')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60 * 2.5));
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 2.5), escalation, lng, type);
|
||||||
equal(result, '2 hours 30 minutes ago', '2.5 hours')
|
equal(result, '2 hours 30 minutes ago', '2.5 hours')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60 * 12.5));
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 12.5), escalation, lng, type);
|
||||||
equal(result, '12 hours ago', '12.5 hours')
|
equal(result, '12 hours ago', '12.5 hours')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24)) ;
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24), escalation, lng, type);
|
||||||
equal(result, '1 day ago', '1 day')
|
equal(result, '1 day ago', '1 day')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2));
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2), escalation, lng, type);
|
||||||
equal(result, '2 days ago', '2 days')
|
equal(result, '2 days ago', '2 days')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2) - (60000 * 5));
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2) - (60000 * 5), escalation, lng, type);
|
||||||
equal(result, '2 days ago', '2 days')
|
equal(result, '2 days ago', '2 days')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2.5));
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2.5), escalation, lng, type);
|
||||||
equal(result, '2 days 12 hours ago', '2.5 days')
|
equal(result, '2 days 12 hours ago', '2.5 days')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2.5) - (60000 * 5));
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2.5) - (60000 * 5), escalation, lng, type);
|
||||||
equal(result, '2 days 12 hours ago', '2.5 days')
|
equal(result, '2 days 12 hours ago', '2.5 days')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 10.5));
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 10.5), escalation, lng, type);
|
||||||
var pastDate = new Date(current - (60000 * 60 * 24 * 10.5))
|
var pastDate = new Date(current - (60000 * 60 * 24 * 10.5))
|
||||||
var dd = pastDate.getDate();
|
var dd = pastDate.getDate();
|
||||||
if(dd<10) {
|
if(dd<10) {
|
||||||
|
@ -57,7 +61,7 @@ test("check pretty date", function() {
|
||||||
// mm/dd/yyyy
|
// mm/dd/yyyy
|
||||||
equal(result, mm+'/'+dd+'/'+yyyy, '10.5 days')
|
equal(result, mm+'/'+dd+'/'+yyyy, '10.5 days')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 30));
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 30), escalation, lng, type);
|
||||||
var pastDate = new Date(current - (60000 * 60 * 24 * 30))
|
var pastDate = new Date(current - (60000 * 60 * 24 * 30))
|
||||||
var dd = pastDate.getDate();
|
var dd = pastDate.getDate();
|
||||||
if(dd<10) {
|
if(dd<10) {
|
||||||
|
@ -73,44 +77,162 @@ test("check pretty date", function() {
|
||||||
|
|
||||||
// future
|
// future
|
||||||
current = new Date()
|
current = new Date()
|
||||||
result = App.PrettyDate.humanTime(current);
|
result = App.PrettyDate.humanTime(current, escalation, lng, type);
|
||||||
equal(result, 'just now', 'just now')
|
equal(result, 'just now', 'just now')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + 55000);
|
result = App.PrettyDate.humanTime(current.getTime() + 55000, escalation, lng, type);
|
||||||
equal(result, 'just now', 'just now')
|
equal(result, 'just now', 'just now')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + 65000);
|
result = App.PrettyDate.humanTime(current.getTime() + 65000, escalation, lng, type);
|
||||||
equal(result, 'in 1 minute', 'in 1 min')
|
equal(result, 'in 1 minute', 'in 1 min')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + (2 * 65000));
|
result = App.PrettyDate.humanTime(current.getTime() + (2 * 65000), escalation, lng, type);
|
||||||
equal(result, 'in 2 minutes', 'in 2 min')
|
equal(result, 'in 2 minutes', 'in 2 min')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + (60500 * 60)) ;
|
result = App.PrettyDate.humanTime(current.getTime() + (60500 * 60), escalation, lng, type);
|
||||||
equal(result, 'in 1 hour', 'in 1 hour')
|
equal(result, 'in 1 hour', 'in 1 hour')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 2));
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 2), escalation, lng, type);
|
||||||
equal(result, 'in 2 hours', 'in 2 hours')
|
equal(result, 'in 2 hours', 'in 2 hours')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 2.5));
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 2.5), escalation, lng, type);
|
||||||
equal(result, 'in 2 hours 30 minutes', 'in 2.5 hours')
|
equal(result, 'in 2 hours 30 minutes', 'in 2.5 hours')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24)) ;
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24), escalation, lng, type) ;
|
||||||
equal(result, 'in 1 day', 'in 1 day')
|
equal(result, 'in 1 day', 'in 1 day')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 2));
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 2), escalation, lng, type);
|
||||||
equal(result, 'in 2 days', 'in 2 days')
|
equal(result, 'in 2 days', 'in 2 days')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 2.5));
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 2.5), escalation, lng, type);
|
||||||
equal(result, 'in 2 days 12 hours', 'in 2.5 days')
|
equal(result, 'in 2 days 12 hours', 'in 2.5 days')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 5.5));
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 5.5), escalation, lng, type);
|
||||||
equal(result, 'in 5 days 12 hours', 'in 30.5 days')
|
equal(result, 'in 5 days 12 hours', 'in 30.5 days')
|
||||||
|
|
||||||
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 30.5));
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 30.5), escalation, lng, type);
|
||||||
equal(result, 'in 30 days', 'in 30.5 days')
|
equal(result, 'in 30 days', 'in 30.5 days')
|
||||||
|
|
||||||
//
|
};
|
||||||
|
|
||||||
|
function prettyDateAbsolute(current, escalation, lng, type) {
|
||||||
|
|
||||||
|
var result = App.PrettyDate.humanTime(current, escalation, lng, type);
|
||||||
|
equal(result, 'just now', 'just now') // by defaul < 1 min is just now
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - 15000, escalation, lng, type);
|
||||||
|
equal(result, 'just now', 'just now') // by default < 1 min is just now
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - 60000, escalation, lng, type);
|
||||||
|
diff = 60
|
||||||
|
equal(result, getAbsolute(new Date(current - 60000), diff), '1 min ago')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - (2 * 60000), escalation, lng, type);
|
||||||
|
diff = 2 * 60
|
||||||
|
equal(result, getAbsolute(new Date(current - (2 * 60000)), diff), '2 min ago')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - (60000 * 60), escalation, lng, type);
|
||||||
|
diff = 60 * 60
|
||||||
|
equal(result, getAbsolute(new Date(current - (60000 * 60)), diff), '1 hour')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 2), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 2
|
||||||
|
equal(result, getAbsolute(new Date(current - (60000 * 60 * 2)), diff), '2 hours')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 2.5), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 2.5
|
||||||
|
equal(result, getAbsolute(new Date(current - (60000 * 60 * 2.5)), diff), '2.5 hours')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 12.5), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 12.5
|
||||||
|
equal(result, getAbsolute(new Date(current - (60000 * 60 * 12.5)), diff), '12.5 hours')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 25
|
||||||
|
equal(result, getAbsolute(new Date(current - (60000 * 60 * 24)), diff), '1 day')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 25 * 2
|
||||||
|
equal(result, getAbsolute(new Date(current - (60000 * 60 * 24 * 2)), diff), '2 days')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2) - (60000 * 5), escalation, lng, type);
|
||||||
|
diff = (60 * 60 * 24 * 2) - (60 * 5)
|
||||||
|
equal(result, getAbsolute(new Date(current - (60000 * 60 * 24 * 2) - (60000 * 5)), diff), '2 days')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2.5), escalation, lng, type);
|
||||||
|
diff = (60 * 60 * 24 * 2.5)
|
||||||
|
equal(result, getAbsolute(new Date(current - (60000 * 60 * 24 * 2.5)), diff), '2.5 days')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current - (60000 * 60 * 24 * 2.5) - (60000 * 5), escalation, lng, type);
|
||||||
|
diff = (60 * 60 * 24 * 2.5) - (60 * 5)
|
||||||
|
equal(result, getAbsolute(new Date(current - (60000 * 60 * 24 * 2.5) - (60000 * 5)), diff), '2.5 days')
|
||||||
|
|
||||||
|
// future
|
||||||
|
current = new Date()
|
||||||
|
result = App.PrettyDate.humanTime(current, escalation, lng, type);
|
||||||
|
equal(result, 'just now', 'just now') // no change, because < 1 min = just now
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + 55000, escalation, lng, type);
|
||||||
|
equal(result, 'just now', 'just now') // no change, because < 1 min = just now
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + 65000, escalation, lng, type);
|
||||||
|
diff = 60
|
||||||
|
equal(result, getAbsolute(new Date(current.getTime() + 65000), diff), 'in 1 min')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + (2 * 65000), escalation, lng, type);
|
||||||
|
diff = 2 * 60
|
||||||
|
equal(result, getAbsolute(new Date(current.getTime() + (2 * 65000)), diff), 'in 2 min')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + (60500 * 60), escalation, lng, type) ;
|
||||||
|
diff = 60 * 60
|
||||||
|
equal(result, getAbsolute(new Date(current.getTime() + (60500 * 60)), diff), 'in 1 hour')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 2), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 2
|
||||||
|
equal(result, getAbsolute(new Date(current.getTime() + (60050 * 60 * 2)), diff), 'in 2 hours')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 2.5), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 2.5
|
||||||
|
equal(result, getAbsolute(new Date(current.getTime() + (60050 * 60 * 2.5)), diff), 'in 2.5 hours')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 24
|
||||||
|
equal(result, getAbsolute(new Date(current.getTime() + (60050 * 60 * 24)), diff), 'in 1 day')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 2), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 24 * 2
|
||||||
|
equal(result, getAbsolute(new Date(current.getTime() + (60050 * 60 * 24 * 2)), diff), 'in 2 days')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 2.5), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 24 * 2.5
|
||||||
|
equal(result, getAbsolute(new Date(current.getTime() + (60050 * 60 * 24 * 2.5)), diff), 'in 2.5 days')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 5.5), escalation, lng, type);
|
||||||
|
diff = 60 * 60 * 24 * 5.5
|
||||||
|
equal(result, getAbsolute(new Date(current.getTime() + (60050 * 60 * 24 * 5.5)), diff), 'in 30.5 days')
|
||||||
|
|
||||||
|
result = App.PrettyDate.humanTime(current.getTime() + (60050 * 60 * 24 * 30.5), escalation, lng, type);
|
||||||
|
diff = (60 * 60 * 24 * 30.5);
|
||||||
|
equal(result, getAbsolute(new Date(current.getTime() + 60050 * 60 * 24 * 30.5), diff), 'in 30.5 days')
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
function getAbsolute(date, diff){
|
||||||
|
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||||
|
weekday = weekdays[date.getDay()];
|
||||||
|
|
||||||
|
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||||
|
month = months[date.getMonth()];
|
||||||
|
|
||||||
|
// for less than 6 days
|
||||||
|
// weekday HH::MM
|
||||||
|
if (diff < (60 * 60 * 24 * 6))
|
||||||
|
string = weekday + ' ' + date.getHours() + ':' + (date.getMinutes() < 10 ? '0':'') + date.getMinutes()
|
||||||
|
else if (current.getYear() == date.getYear())
|
||||||
|
string = weekday + ' ' + date.getDate() + '. ' + month + ' ' + date.getHours() + ":" + (date.getMinutes() < 10 ? '0':'') + date.getMinutes()
|
||||||
|
else
|
||||||
|
string = weekday + ' ' + date
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue