Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed week/weeks rollover in relativeTime

  • Loading branch information...
commit f8cef24879decd67fc0bd91bcddbbf4eaa320d27 1 parent 9bf2db4
mde authored
Showing with 25 additions and 7 deletions.
  1. +2 −2 lib/date.js
  2. +23 −5 test/date.js
View
4 lib/date.js
@@ -832,11 +832,11 @@ date = new (function () {
num = parseInt((diff / day), 10);
ret = abbr ? num + 'd' : 'about ' + num + ' days ago';
break;
- case diff < (8*day):
+ case diff < (11*day):
ret = abbr ? '1w': 'one week ago';
break;
case diff < (1*month):
- num = parseInt((diff / week), 10);
+ num = Math.round(diff / week);
ret = abbr ? num + 'w' : 'about ' + num + ' weeks ago';
break;
default:
View
28 test/date.js
@@ -22,36 +22,54 @@ var date = require('../lib/date')
tests = {
- 'test strftime for date': function() {
+ 'test strftime for date': function () {
var data = date.strftime(_date, "%w")
, actual = _date.getDay();
assert.equal(actual, data);
}
-, 'test calcCentury using current year for date': function() {
+, 'test calcCentury using current year for date': function () {
var data = date.calcCentury()
, actual = '21';
assert.equal(actual, data);
}
-, 'test calcCentury using 20th century year for date': function() {
+, 'test calcCentury using 20th century year for date': function () {
var data = date.calcCentury(2000)
, actual = '20';
assert.equal(actual, data);
}
-, 'test calcCentury using 1st century year for date': function() {
+, 'test calcCentury using 1st century year for date': function () {
var data = date.calcCentury(10)
, actual = '1';
assert.equal(actual, data);
}
-, 'test getMeridiem for date': function() {
+, 'test getMeridiem for date': function () {
var data = date.getMeridiem(_date.getHours())
, actual = (_date.getHours() > 11) ? 'PM' : 'AM';
assert.equal(actual, data);
}
+, 'test relativeTime week/weeks switchover': function () {
+ var dtA = new Date()
+ , dtB
+ , res;
+
+ dtB = date.add(dtA, 'day', 10);
+ dtB = date.add(dtB, 'hour', 23);
+ dtB = date.add(dtB, 'minute', 59);
+ dtB = date.add(dtB, 'second', 59);
+ dtB = date.add(dtB, 'millisecond', 999);
+ res = date.relativeTime(dtA, {now: dtB});
+ assert.equal('one week ago', res);
+
+ dtB = date.add(dtB, 'millisecond', 1);
+ res = date.relativeTime(dtA, {now: dtB});
+ assert.equal('about 2 weeks ago', res);
+ }
+
};
module.exports = tests;
Please sign in to comment.
Something went wrong with that request. Please try again.