Skip to content
Browse files

fix ordinal number, add some tests to validate, general test cleanup

  • Loading branch information...
1 parent 6560678 commit b7ce3396ecd3b719a54c335fb5b796ddfa43e245 @jsievert jsievert committed
Showing with 768 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +67 −0 test/date-format-test.js
  3. +60 −0 test/date-new-test.js
  4. +122 −0 test/date-parse-test.js
  5. +518 −0 test/date-validate-test.js
View
1 .gitignore
@@ -0,0 +1 @@
+node_modules
View
67 test/date-format-test.js
@@ -0,0 +1,67 @@
+var vows = require('vows');
+var assert = require('assert');
+
+require('../lib/date-utils.js');
+
+function pad(str, length) {
+ str = String(str);
+ while (str.length < length) {
+ str = '0' + str;
+ }
+ return str;
+}
+
+vows.describe('Date Format').addBatch({
+ 'can return month abbreviations as static method': {
+ topic: function () { return new Date(123456789); },
+ 'returns the correct abbreviated month': function (date) {
+ assert.equal(date.getMonthAbbr(), 'Jan');
+ }
+ },
+
+ 'can return month as static method': {
+ topic: function () { return new Date(123456789); },
+ 'returns the correct month': function (date) {
+ assert.equal(date.getMonthAbbr(), 'Jan');
+ }
+ },
+
+ 'can return common log formatted string': {
+ topic: function () { return new Date(Date.UTC(2011, 0, 1, 1, 1, 1, 0)); },
+ 'returns the correct clf string': function (date) {
+ var tz = pad(Math.abs(date.getTimezoneOffset() / 0.6), 4);
+ if (date.getTimezoneOffset() > 0) {
+ tz = '-' + tz;
+ }
+
+ date = new Date(date.valueOf() + date.getTimezoneOffset() * 60000);
+ assert.equal(date.toCLFString(), '01/Jan/2011:01:01:01 ' + tz);
+ }
+ },
+
+ 'can return correctly formatted toFormat': {
+ topic: function () { var topic = new Date(2011, 0, 1);
+ topic.addHours(13)
+ .addMinutes(11)
+ .addSeconds(41);
+ return topic;
+ },
+ 'returns correctly': function (date) {
+ assert.equal(date.toFormat('YYYY'), '2011');
+ assert.equal(date.toFormat('YY'), '11');
+ assert.equal(date.toFormat('MM'), '01');
+ assert.equal(date.toFormat('DD'), '01');
+ assert.equal(date.toFormat('HH'), '01');
+ assert.equal(date.toFormat('HH24'), '13');
+ assert.equal(date.toFormat('MI'), '11');
+ assert.equal(date.toFormat('SS'), '41');
+ }
+ },
+
+ 'can return database formatted string': {
+ topic: function () { return new Date(Date.UTC(2011, 0, 1, 1, 1, 1, 0)); },
+ 'returns the correct database string': function (date) {
+ assert.equal(date.toDBString(), '2011-01-01 01:01:01');
+ }
+ }
+}).export(module);
View
60 test/date-new-test.js
@@ -0,0 +1,60 @@
+var vows = require('vows');
+var assert = require('assert');
+
+require('../lib/date-utils.js');
+
+vows.describe('Date New').addBatch({
+ 'can return a new object from today static method': {
+ topic: function () { return Date.today(); },
+ 'returns the correct time': function (date) {
+ var compare = new Date().clearTime();
+ assert.equal(date.valueOf(), compare.valueOf());
+ }
+ },
+
+ 'clearTime() works': {
+ topic: function() { return new Date().clearTime(); },
+ 'returns the correct value': function (date) {
+ var compare = new Date();
+ compare.setHours(0);
+ compare.setMinutes(0);
+ compare.setSeconds(0);
+ compare.setMilliseconds(0);
+
+ assert.equal(date.valueOf(), compare.valueOf());
+ }
+ },
+
+ 'today() works': {
+ topic: function() {
+ return Date.today();
+ },
+ 'returns the correct value': function(date) {
+ var compare = new Date().clearTime();
+ assert.equal(date.valueOf(), compare.valueOf());
+ }
+ },
+
+ 'yesterday() works': {
+ topic: function() {
+ return Date.yesterday();
+ },
+ 'returns the correct value': function(date) {
+ var compare = new Date().clearTime();
+ compare.setSeconds(compare.getSeconds() - 86400);
+ assert.equal(date.valueOf(), compare.valueOf());
+ }
+ },
+
+ 'tomorrow() works': {
+ topic: function() {
+ return Date.tomorrow();
+ },
+ 'returns the correct value': function(date) {
+ var compare = new Date().clearTime();
+ compare.setSeconds(compare.getSeconds() + 86400);
+ assert.equal(date.valueOf(), compare.valueOf());
+ }
+ }
+
+}).export(module);
View
122 test/date-parse-test.js
@@ -0,0 +1,122 @@
+var vows = require('vows');
+var assert = require('assert');
+
+require('../lib/date-utils.js');
+//getTimezoneOffset returns number of minutes
+//converting to milliseconds
+var offset = (new Date().getTimezoneOffset()) * 60 * 1000;
+
+vows.describe('Date Parse').addBatch({
+ 'can instantiate milliseconds': {
+ topic: function () { return new Date(123456789); },
+ 'returns a valid date object': function (date) {
+ assert.ok(date);
+ },
+ 'returns a correct value': function (date) {
+ assert.equal(date.valueOf(), 123456789);
+ }
+ },
+
+ 'can instantiate string': {
+ topic: function () { return new Date('Jan 1, 2011 01:01:01 GMT'); },
+ 'returns a valid date object': function (date) {
+ assert.ok(date);
+ },
+ 'returns a correct value': function (date) {
+ assert.equal(date.valueOf(), 1293843661000);
+ }
+ },
+
+ 'can instantiate arguments': {
+ topic: function () { return new Date(2011, 1, 1, 1, 1, 1, 0); },
+ 'returns a valid date object': function (date) {
+ assert.ok(date);
+ }
+ },
+
+ 'can parse normal date': {
+ topic: function () { return Date.parse('Jan 1, 2011 01:01:01 GMT'); },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1293843661000);
+ }
+ },
+ 'can parse ISO-8601': {
+ topic: function () { return Date.parse('2011-01-01T01:01:01Z'); },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1293843661000);
+ }
+ },
+ 'can parse custom format': {
+ topic: function () {
+ return Date.parse('20/6/2011 8:30', 'd/M/y H:m');
+ },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1308558600000 + offset);
+ }
+ },
+ 'parse custom format with full month name': {
+ topic: function () {
+ return Date.parse('June 20, 2011 08:30:00', 'MMM d, y H:m:s');
+ },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1308558600000 + offset);
+ }
+ },
+ 'parse custom format with abbr month name': {
+ topic: function () {
+ return Date.parse('Jun 20, 2011 08:30:00', 'MMM d, y H:m:s');
+ },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1308558600000 + offset);
+ }
+ },
+ 'parse custom format with 12 hr clock': {
+ topic: function () {
+ return Date.parse('June 20, 2011 08:30:00AM', 'MMM d, y h:m:sa');
+ },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1308558600000 + offset);
+ }
+ },
+ 'parse mysql date format': {
+ topic: function () {
+ return Date.parse('2011-06-20 08:30:00', 'y-M-d H:m:s');
+ },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1308558600000 + offset);
+ }
+ },
+ 'parse us date format w/o time': {
+ topic: function () {
+ return Date.parse('6/20/2011', 'M/d/y');
+ },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1308528000000 + offset);
+ }
+ },
+ 'parse us date format with time': {
+ topic: function () {
+ return Date.parse('6/20/2011 00:00:01', 'M/d/y H:m:s');
+ },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1308528001000 + offset);
+ }
+ },
+ 'parse uk date format w/o time': {
+ topic: function () {
+ return Date.parse('20/6/2011', 'd/M/y');
+ },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1308528000000 + offset);
+ }
+ },
+ 'parse uk date format with time': {
+ topic: function () {
+
+ return Date.parse('20/6/2011 00:00:01', 'd/M/y H:m:s');
+ },
+ 'returns a correct value': function (milli) {
+ assert.equal(milli, 1308528001000 + offset);
+ }
+ }
+}).export(module);
View
518 test/date-validate-test.js
@@ -0,0 +1,518 @@
+var vows = require('vows');
+var assert = require('assert');
+
+require('../lib/date-utils.js');
+
+vows.describe('Date Validate').addBatch({
+ 'can deal with hours': {
+ topic: function () { return Date; },
+ 'false for less than 0': function (topic) {
+ assert.equal(topic.validateHour(-1), false);
+ },
+ 'false for greater than 23': function (topic) {
+ assert.equal(topic.validateHour(24), false);
+ },
+ 'true for in range': function (topic) {
+ assert.equal(topic.validateHour(12), true);
+ }
+ },
+
+ 'can deal with minutes': {
+ topic: function () { return Date; },
+ 'false for less than 0': function (topic) {
+ assert.equal(topic.validateMinute(-1), false);
+ },
+ 'false for greater than 59': function (topic) {
+ assert.equal(topic.validateMinute(60), false);
+ },
+ 'true for in range': function (topic) {
+ assert.equal(topic.validateMinute(30), true);
+ }
+ },
+
+ 'can deal with seconds': {
+ topic: function () { return Date; },
+ 'false for less than 0': function (topic) {
+ assert.equal(topic.validateSecond(-1), false);
+ },
+ 'false for greater than 59': function (topic) {
+ assert.equal(topic.validateSecond(60), false);
+ },
+ 'true for in range': function (topic) {
+ assert.equal(topic.validateSecond(30), true);
+ }
+ },
+
+ 'can deal with milliseconds': {
+ topic: function () { return Date; },
+ 'false for less than 0': function (topic) {
+ assert.equal(topic.validateMillisecond(-1), false);
+ },
+ 'false for greater than 999': function (topic) {
+ assert.equal(topic.validateMillisecond(1000), false);
+ },
+ 'true for in range': function (topic) {
+ assert.equal(topic.validateMillisecond(500), true);
+ }
+ },
+
+ 'can deal with years': {
+ topic: function () { return Date; },
+ 'false for less than 0': function (topic) {
+ assert.equal(topic.validateYear(-1), false);
+ },
+ 'false for greater than 9999': function (topic) {
+ assert.equal(topic.validateYear(10000), false);
+ },
+ 'true for in range': function (topic) {
+ assert.equal(topic.validateYear(5000), true);
+ }
+ },
+
+ 'can deal with days': {
+ topic: function () { return Date; },
+ 'false for less than 0': function (topic) {
+ assert.equal(topic.validateDay(-1, 2011, 12), false);
+ },
+ 'false for greater than 31': function (topic) {
+ assert.equal(topic.validateDay(32, 2011, 12), false);
+ },
+ 'true for in range': function (topic) {
+ assert.equal(topic.validateDay(10, 2011, 11), true);
+ }
+ },
+
+ 'static compare works': {
+ topic: function () { return Date.today(); },
+ '-1 for yesterday': function (topic) {
+ assert.equal(Date.compare(Date.yesterday(), topic), -1);
+ },
+ '1 for tomorrow': function (topic) {
+ assert.equal(Date.compare(Date.tomorrow(), topic), 1);
+ },
+ '0 for today': function (topic) {
+ assert.equal(Date.compare(Date.today(), topic), 0);
+ }
+ },
+
+ 'static equals works': {
+ topic: function () { return Date.today(); },
+ 'equal for today': function (topic) {
+ assert.equal(Date.equals(topic, Date.today()), true);
+ },
+ 'false for tomorrow': function (topic) {
+ assert.equal(Date.equals(topic, Date.tomorrow()), false);
+ },
+ 'false for yesterday': function (topic) {
+ assert.equal(Date.equals(topic, Date.yesterday()), false);
+ }
+ },
+
+ 'getDayNumberFromName works': {
+ topic: function () { return Date; },
+ 'sunday works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('sunday'), 0);
+ },
+ 'sun works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('sun'), 0);
+ },
+ 'su works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('su'), 0);
+ },
+ 'monday works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('monday'), 1);
+ },
+ 'mon works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('mon'), 1);
+ },
+ 'mo works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('mo'), 1);
+ },
+ 'tuesday works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('tuesday'), 2);
+ },
+ 'tue works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('tue'), 2);
+ },
+ 'tu works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('tu'), 2);
+ },
+ 'wednesday works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('wednesday'), 3);
+ },
+ 'wed works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('wed'), 3);
+ },
+ 'we works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('we'), 3);
+ },
+ 'thursday works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('thursday'), 4);
+ },
+ 'thu works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('thu'), 4);
+ },
+ 'th works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('th'), 4);
+ },
+ 'friday works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('friday'), 5);
+ },
+ 'fri works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('fri'), 5);
+ },
+ 'fr works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('fr'), 5);
+ },
+ 'saturday works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('saturday'), 6);
+ },
+ 'sat works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('sat'), 6);
+ },
+ 'sa works': function (topic) {
+ assert.equal(topic.getDayNumberFromName('sa'), 6);
+ },
+ 'everything else does not': function (topic) {
+ assert.equal(topic.getDayNumberFromName('junk'), undefined);
+ }
+ },
+
+ 'getMonthNumberFromName works': {
+ topic: function () { return Date; },
+ 'january works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('january'), 0);
+ },
+ 'jan works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('jan'), 0);
+ },
+ 'february works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('february'), 1);
+ },
+ 'feb works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('feb'), 1);
+ },
+ 'march works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('march'), 2);
+ },
+ 'mar works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('mar'), 2);
+ },
+ 'april works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('april'), 3);
+ },
+ 'apr works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('apr'), 3);
+ },
+ 'may works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('may'), 4);
+ },
+ 'june works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('june'), 5);
+ },
+ 'jun works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('jun'), 5);
+ },
+ 'july works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('july'), 6);
+ },
+ 'jul works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('jul'), 6);
+ },
+ 'august works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('august'), 7);
+ },
+ 'aug works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('aug'), 7);
+ },
+ 'september works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('september'), 8);
+ },
+ 'sep works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('sep'), 8);
+ },
+ 'october works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('october'), 9);
+ },
+ 'oct works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('oct'), 9);
+ },
+ 'november works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('november'), 10);
+ },
+ 'nov works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('nov'), 10);
+ },
+ 'december works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('december'), 11);
+ },
+ 'dec works': function (topic) {
+ assert.equal(topic.getMonthNumberFromName('dec'), 11);
+ }
+ },
+
+ 'can add milliseconds': {
+ 'adding positive milliseconds works': function () {
+ var topic = Date.today();
+ topic.addMilliseconds(500);
+ assert.equal(topic.getMilliseconds(), 500);
+ },
+ 'adding negative milliseconds works': function () {
+ var topic = Date.today();
+ topic.addMilliseconds(500);
+ assert.equal(topic.getMilliseconds(), 500);
+ topic.addMilliseconds(-250);
+ assert.equal(topic.getMilliseconds(), 250);
+ }
+ },
+
+ 'can add seconds': {
+ 'adding positive seconds works': function () {
+ var topic = Date.today();
+ topic.addSeconds(50);
+ assert.equal(topic.getSeconds(), 50);
+ },
+ 'adding negative seconds works': function () {
+ var topic = Date.today();
+ topic.addSeconds(50);
+ assert.equal(topic.getSeconds(), 50);
+ topic.addSeconds(-25);
+ assert.equal(topic.getSeconds(), 25);
+ }
+ },
+
+ 'can add minutes': {
+ 'adding positive minutes works': function () {
+ var topic = Date.today();
+ topic.addMinutes(50);
+ assert.equal(topic.getMinutes(), 50);
+ },
+ 'adding negative minutes works': function () {
+ var topic = Date.today();
+ topic.addMinutes(50);
+ assert.equal(topic.getMinutes(), 50);
+ topic.addMinutes(-25);
+ assert.equal(topic.getMinutes(), 25);
+ }
+ },
+
+ 'can add hours': {
+ 'adding positive hours works': function () {
+ var topic = Date.today();
+ topic.addHours(5);
+ assert.equal(topic.getHours(), 5);
+ },
+ 'adding negative hours works': function () {
+ var topic = Date.today();
+ topic.addHours(5);
+ assert.equal(topic.getHours(), 5);
+ topic.addHours(-2);
+ assert.equal(topic.getHours(), 3);
+ }
+ },
+
+ 'can add days': {
+ 'adding positive days works': function () {
+ var topic = new Date(2011, 0, 10);
+ topic.addDays(1);
+ assert.equal(topic.getDate(), 11);
+ },
+ 'adding negative days works': function () {
+ var topic = new Date(2011, 0, 10);
+ topic.addDays(1);
+ assert.equal(topic.getDate(), 11);
+ topic.addDays(-2);
+ assert.equal(topic.getDate(), 9);
+ }
+ },
+
+ 'can add weeks': {
+ 'adding positive weeks works': function () {
+ var topic = new Date(2011, 0, 10);
+ topic.addWeeks(1);
+ assert.equal(topic.getDate(), 17);
+ },
+ 'adding negative weeks works': function () {
+ var topic = new Date(2011, 0, 10);
+ topic.addWeeks(1);
+ assert.equal(topic.getDate(), 17);
+ topic.addWeeks(-2);
+ assert.equal(topic.getDate(), 3);
+ }
+ },
+
+ 'can add months': {
+ 'adding positive months works': function () {
+ var topic = new Date(2011, 1, 10);
+ topic.addMonths(1);
+ assert.equal(topic.getMonth(), 2);
+ },
+ 'adding negative months works': function () {
+ var topic = new Date(2011, 1, 10);
+ topic.addMonths(1);
+ assert.equal(topic.getMonth(), 2);
+ topic.addMonths(-2);
+ assert.equal(topic.getMonth(), 0);
+ }
+ },
+
+ 'can set time to now': {
+ 'setting time to now works': function () {
+ var topic = Date.today();
+ topic.setTimeToNow();
+ var now = new Date();
+
+ // hokey, but should be sufficient
+ assert.equal((now.valueOf() - topic.valueOf() < 100), true);
+ }
+ },
+
+ 'can clone time': {
+ topic: function () { return new Date(); },
+ 'clone works': function (topic) {
+ var clone = topic.clone();
+ assert.equal(clone.valueOf(), topic.valueOf());
+ }
+ },
+
+ 'between works': {
+ 'between returns true for valid start and end': function () {
+ var today = Date.today();
+ var yesterday = Date.yesterday();
+ var tomorrow = Date.tomorrow();
+ assert.equal(today.between(yesterday, tomorrow), true);
+ },
+ 'between returns false for invalid start and end': function () {
+ var today = Date.today();
+ var yesterday = Date.yesterday();
+ var tomorrow = Date.tomorrow();
+ assert.equal(today.between(tomorrow, yesterday), false);
+ }
+ },
+
+ 'compareTo works': {
+ topic: function () { return Date.today(); },
+ '-1 for tomorrow': function (topic) {
+ assert.equal(topic.compareTo(Date.tomorrow()), -1);
+ },
+ '1 for yesterday': function (topic) {
+ assert.equal(topic.compareTo(Date.yesterday()), 1);
+ },
+ '0 for today': function (topic) {
+ assert.equal(topic.compareTo(Date.today()), 0);
+ }
+ },
+
+
+ 'equals instance works': {
+ topic: function () { return Date.today(); },
+ 'true for equal': function (topic) {
+ assert.equal(topic.equals(Date.today()), true);
+ },
+ 'false for not equal': function (topic) {
+ assert.equal(topic.equals(Date.tomorrow()), false);
+ }
+ },
+
+ 'isBefore works': {
+ topic: function () { return Date.today(); },
+ 'true for before': function (topic) {
+ assert.equal(topic.isBefore(Date.tomorrow()), true);
+ },
+ 'false for after': function (topic) {
+ assert.equal(topic.isBefore(Date.yesterday()), false);
+ }
+ },
+
+ 'isAfter works': {
+ topic: function () { return Date.today(); },
+ 'false for before': function (topic) {
+ assert.equal(topic.isAfter(Date.tomorrow()), false);
+ },
+ 'true for after': function (topic) {
+ assert.equal(topic.isAfter(Date.yesterday()), true);
+ }
+ },
+
+ 'getDaysBetween works': {
+ topic: function () { return Date.today(); },
+ '1 for tomorrow': function (topic) {
+ assert.equal(topic.getDaysBetween(Date.tomorrow()), 1);
+ },
+ '-1 for yesterday': function (topic) {
+ assert.equal(topic.getDaysBetween(Date.yesterday()), -1);
+ },
+ '0 for today': function (topic) {
+ assert.equal(topic.getDaysBetween(Date.today()), 0);
+ }
+ },
+
+ 'getDaysBetween works for beginning of year': {
+ topic: function () { return new Date('Jan 1, 2011 01:01:01 GMT'); },
+ 'should return 0 for the same day': function (topic) {
+ var date = new Date('Jan 1, 2011 01:01:01 GMT');
+ assert.equal(topic.getDaysBetween(date), 0);
+ },
+ 'should return 1 for tomorrow': function (topic) {
+ var date = new Date('Jan 2, 2011 01:01:01 GMT');
+ assert.equal(topic.getDaysBetween(date), 1);
+ }
+ },
+
+ 'getOrdinalNumber works': {
+ 'returns correct day': function () {
+ var date = new Date('02-01-2011');
+ assert.equal(date.getOrdinalNumber(), 31);
+ }
+ },
+
+ 'getOrdinalNumber works for january 1st': {
+ 'returns correct day': function () {
+ var date = new Date('01-01-2011');
+ assert.equal(date.getOrdinalNumber(), 0);
+ }
+ },
+
+ 'getDaysInMonth works': {
+ 'january': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 0), 31);
+ },
+ 'february': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 1), 28);
+ },
+ 'february leap year': function (topic) {
+ assert.equal(Date.getDaysInMonth(2008, 1), 29);
+ },
+ 'march': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 2), 31);
+ },
+ 'april': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 3), 30);
+ },
+ 'may': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 4), 31);
+ },
+ 'june': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 5), 30);
+ },
+ 'july': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 6), 31);
+ },
+ 'august': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 7), 31);
+ },
+ 'september': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 8), 30);
+ },
+ 'october': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 9), 31);
+ },
+ 'november': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 10), 30);
+ },
+ 'december': function (topic) {
+ assert.equal(Date.getDaysInMonth(2011, 11), 31);
+ }
+ }
+
+}).export(module);

0 comments on commit b7ce339

Please sign in to comment.
Something went wrong with that request. Please try again.