Skip to content

Commit

Permalink
Fix and add tests for ago()/before()/fromNow()/after().
Browse files Browse the repository at this point in the history
  • Loading branch information
John Firebaugh committed May 21, 2010
1 parent 38cc6fc commit bbe5ed2
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/sugarpak.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$P._isSecond = false; $P._isSecond = false;


// private // private
$N._dateElement = "day"; $N._dateElement = "days";


/** /**
* Moves the date to the next instance of a date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()). * Moves the date to the next instance of a date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).
Expand Down Expand Up @@ -445,7 +445,7 @@
$P[de] = $P[de + "s"] = ef(px[k]); $P[de] = $P[de + "s"] = ef(px[k]);


// Create date element functions and plural date element functions used with Number (eg. day(), days(), months()). // Create date element functions and plural date element functions used with Number (eg. day(), days(), months()).
$N[de] = $N[de + "s"] = nf(de); $N[de] = $N[de + "s"] = nf(de + "s");
} }


$P._ss = ef("Second"); $P._ss = ef("Second");
Expand Down
95 changes: 93 additions & 2 deletions test/sugarpak/index.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,8 +9,99 @@ Date.Specification = new Specification({
} }
} }
}, },



'.before()': {
setup: function() {},
'seconds': {
run: function() { },
assert: function() {
return Date.equals((10).seconds().before(new Date(2010, 0, 1, 0, 0, 10)), new Date(2010, 0, 1));
}
},
'minutes': {
run: function() { },
assert: function() {
return Date.equals((2).minutes().before(new Date(2010, 0, 1, 0, 2)), new Date(2010, 0, 1));
}
},
'hours': {
run: function() { },
assert: function() {
return Date.equals((8).hours().before(new Date(2010, 0, 1, 8)), new Date(2010, 0, 1));
}
},
'days': {
run: function() { },
assert: function() {
return Date.equals((4).days().before(new Date(2010, 0, 5)), new Date(2010, 0, 1));
}
},
'weeks': {
run: function() { },
assert: function() {
return Date.equals((6).weeks().before(new Date(2010, 1, 12)), new Date(2010, 0, 1));
}
},
'months': {
run: function() { },
assert: function() {
return Date.equals((12).months().before(new Date(2011, 0, 1)), new Date(2010, 0, 1));
}
},
'years': {
run: function() { },
assert: function() {
return Date.equals((4).years().before(new Date(2014, 0, 1)), new Date(2010, 0, 1));
}
}
},

'.after()': {
setup: function() {},
'seconds': {
run: function() { },
assert: function() {
return Date.equals((10).seconds().after(new Date(2010, 0, 1)), new Date(2010, 0, 1, 0, 0, 10));
}
},
'minutes': {
run: function() { },
assert: function() {
return Date.equals((2).minutes().after(new Date(2010, 0, 1)), new Date(2010, 0, 1, 0, 2));
}
},
'hours': {
run: function() { },
assert: function() {
return Date.equals((8).hours().after(new Date(2010, 0, 1)), new Date(2010, 0, 1, 8));
}
},
'days': {
run: function() { },
assert: function() {
return Date.equals((4).days().after(new Date(2010, 0, 1)), new Date(2010, 0, 5));
}
},
'weeks': {
run: function() { },
assert: function() {
return Date.equals((6).weeks().after(new Date(2010, 0, 1)), new Date(2010, 1, 12));
}
},
'months': {
run: function() { },
assert: function() {
return Date.equals((12).months().after(new Date(2010, 0, 1)), new Date(2011, 0, 1));
}
},
'years': {
run: function() { },
assert: function() {
return Date.equals((4).years().after(new Date(2010, 0, 1)), new Date(2014, 0, 1));
}
}
},

'.same()': { '.same()': {
setup: function() {}, setup: function() {},
'same year(Date.today())': { 'same year(Date.today())': {
Expand Down

0 comments on commit bbe5ed2

Please sign in to comment.