(function(Date, _, undefined){
- // create shortcuts to Date.prototype for minification
- var dateProto = Date.prototype;
// assign variables here so they can be overwritten for i18n or customization
var self = this, _d,
wordsMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
+ wordsMonthsShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
wordsWeekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
+ wordsWeekdaysShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
wordsTimeAgo = {
future: "in %s",
past: "%s ago",
return output;
}
- // Date.prototype.humanize
- dateProto.humanize = function(inputString) {
- // shortcuts to this and getting time functions
- // done to save bytes in minification
- var self = this,
- currentMonth = self.getMonth(),
- currentDate = self.getDate(),
- currentYear = self.getFullYear(),
- currentDay = self.getDay(),
- currentHours = self.getHours(),
- currentMinutes = self.getMinutes(),
- currentSeconds = self.getSeconds(),
- charactersToReplace = /(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?)/g,
- formatFunctions = {
- // MONTH
- M : function() {
- return currentMonth + 1;
- },
- Mo : function() {
- return (currentMonth + 1) + createOrdinal(currentMonth + 1);
- },
- MM : function() {
- return leftZeroFill(currentMonth + 1, 2);
- },
- MMM : function() {
- return wordsMonths[currentMonth].slice(0, 3);
-
- },
- MMMM : function() {
- return wordsMonths[currentMonth];
-
- },
-
- // DAY OF MONTH
- D : function() {
- return currentDate;
- },
- Do : function() {
- return currentDate + createOrdinal(currentDate);
- },
- DD : function() {
- return leftZeroFill(currentDate, 2);
- },
-
- // DAY OF YEAR
- DDD : function() {
- var a = new Date(currentYear, currentMonth, currentDate),
- b = new Date(currentYear, 0, 1);
- return ((a - b) / 864e5) + 1.5 | 0;
- },
- DDDo : function() {
- var DDD = formatFunctions.DDD();
- return DDD + createOrdinal(DDD);
- },
- DDDD : function() {
- return leftZeroFill(formatFunctions.DDD(), 3);
- },
-
- // WEEKDAY
- d : function() {
- return currentDay;
- },
- 'do' : function() {
- return currentDay + createOrdinal(currentDay);
- },
- ddd : function() {
- return wordsWeekdays[currentDay].slice(0, 3);
- },
- dddd : function() {
- return wordsWeekdays[currentDay];
- },
-
- // WEEK OF YEAR
- w : function() {
- var a = new Date(currentYear, currentMonth, currentDate - currentDay + 5),
- b = new Date(a.getFullYear(), 0, 4);
- return (a - b) / 864e5 / 7 + 1.5 | 0;
- },
- wo : function() {
- var w = formatFunctions.w();
- return w + createOrdinal(w);
- },
- ww : function() {
- return leftZeroFill(formatFunctions.w(), 2);
- },
-
- // YEAR
- YY : function() {
- return (currentYear + '').slice(-2);
- },
- YYYY : function(shorthand) {
- return currentYear;
- },
-
- // AM / PM
- a : function() {
- return currentHours > 11 ? 'pm' : 'am';
- },
- A : function() {
- return currentHours > 11 ? 'PM' : 'AM';
- },
-
- // 24 HOUR
- H : function() {
- return currentHours;
- },
- HH : function() {
- return leftZeroFill(currentHours, 2);
- },
-
- // 12 HOUR
- h : function() {
- return currentHours % 12 || 12;
- },
- hh : function() {
- return leftZeroFill(currentHours % 12 || 12, 2);
- },
-
- // MINUTE
- m : function() {
- return currentMinutes;
- },
- mm : function() {
- return leftZeroFill(currentMinutes, 2);
- },
-
- // SECOND
- s : function() {
- return currentSeconds;
- },
- ss : function() {
- return leftZeroFill(currentSeconds, 2);
- }
- };
-
- // check if the character is a format
- // return formatted string or non string.
- function replaceFunction(input) {
- return formatFunctions[input] ? formatFunctions[input]() : input.replace("\\", "");
- }
-
- return inputString.replace(charactersToReplace, replaceFunction);
- };
-
- // is leap year
- dateProto.isleapyear = function() {
- var year = this.getFullYear();
- return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
- };
-
- // is daylight savings time
- dateProto.isdst = function() {
- var year = this.getFullYear();
- var offset = new Date(year, 0, 1).getTimezoneOffset();
- offset = Math.max(offset, new Date(year, 6, 1).getTimezoneOffset());
- return this.getTimezoneOffset() < offset;
- };
-
- // helper function for Date.prototype.add and Date.prototype.subtract
+ // helper function for _.addTime and _.subtractTime
function dateAddRemove(input, self, adding){
- var ms = (input.ms || 0) +
- (input.s || 0) * 1e3 + // 1000
- (input.m || 0) * 6e4 + // 1000 * 60
- (input.h || 0) * 36e5 + // 1000 * 60 * 60
- (input.d || 0) * 864e5 + // 1000 * 60 * 60 * 24
+ var ms = (input.ms || input[6] || 0) +
+ (input.s || input[5] || 0) * 1e3 + // 1000
+ (input.m || input[4] || 0) * 6e4 + // 1000 * 60
+ (input.h || input[3] || 0) * 36e5 + // 1000 * 60 * 60
+ (input.d || input[2] || 0) * 864e5 + // 1000 * 60 * 60 * 24
(input.w || 0) * 6048e5, // 1000 * 60 * 60 * 24 * 7
- M = (input.M || 0) +
- (input.y || 0) * 12,
+ M = (input.M || input[1] || 0) +
+ (input.y || input[0] || 0) * 12,
currentDate;
if (ms) {
self.setMilliseconds(self.getMilliseconds() + ms * adding);
self.setMonth(self.getMonth() + M * adding);
self.setDate(Math.min(new Date(self.getFullYear(), self.getMonth() + 1, 0).getDate(), currentDate));
}
+ return self;
}
- dateProto.add = function (input) {
- dateAddRemove(input, this, 1);
- };
-
- dateProto.subtract = function (input) {
- dateAddRemove(input, this, -1);
- };
+ // convert an array to a date.
+ // the array should mirror the parameters below
+ // note: all values past the year are optional and will default to the lowest possible value.
+ // [year, month, day , hour, minute, second, millisecond]
+ function dateFromArray(input) {
+ return new Date(input[0], input[1] || 0, input[2] || 1, input[3] || 0, input[4] || 0, input[5] || 0, input[6] || 0);
+ }
- /*
- * Underscore mixins
- */
+ // convert any input to milliseconds
+ //
+ // undefined = _.now()
+ // number = number
+ // date = date.gettime()
+ // array = new Date(array).getTime()
+ // string = new Date(string).getTime()
function makeInputMilliseconds(input){
return input === undefined ? _d.now(true) :
- input instanceof Date ? input.getTime() : input;
+ !isNaN(input) ? input :
+ _.isDate(input) ? input.getTime() :
+ _.isArray(input) && input.length > 2 ? dateFromArray(input).getTime() :
+ new Date(input).getTime();
+ }
+
+ // convert any input to a date
+ //
+ // undefined = _.now()
+ // date = date
+ // array = new Date(array)
+ // number = new Date(number)
+ // string = new Date(string)
+ function makeInputDate(input){
+ return input === undefined ? _d.now() :
+ _.isDate(input) ? input :
+ _.isArray(input) && input.length > 2 ? dateFromArray(input) :
+ new Date(input);
}
+ // helper function for _.relativeTime
function substituteTimeAgo(string, number) {
return wordsTimeAgo[string].replace(/%d/i, number || 1);
}
+ // underscore mixins
_d = {
+ addTime : function(date, input) {
+ return dateAddRemove(input, makeInputDate(date), 1);
+ },
+ customizeDate : function(input) {
+ var inputWeekdays = input.weekdays,
+ inputWeekdaysShort = input.weekdaysShort,
+ inputMonths = input.months,
+ inputMonthsShort = input.monthsShort,
+ inputTimeago = input.timeago,
+ inputOrdinal = input.ordinal;
+ if (inputWeekdays && _.isArray(inputWeekdays) && inputWeekdays.length === 7) {
+ wordsWeekdays = inputWeekdays;
+ }
+ if (inputWeekdaysShort && _.isArray(inputWeekdaysShort) && inputWeekdaysShort.length === 7) {
+ wordsWeekdaysShort = inputWeekdaysShort;
+ }
+ if (inputMonths && _.isArray(inputMonths) && inputMonths.length === 12) {
+ wordsMonths = inputMonths;
+ }
+ if (inputMonthsShort && _.isArray(inputMonthsShort) && inputMonthsShort.length === 12) {
+ wordsMonthsShort = inputMonthsShort;
+ }
+ if (inputTimeago) {
+ _.extend(wordsTimeAgo, inputTimeago);
+ }
+ if (inputOrdinal && _.isFunction(inputOrdinal)) {
+ createOrdinal = inputOrdinal;
+ }
+ },
+ date : function(input) {
+ return makeInputDate(input);
+ },
+ formatDate : function(_date, inputString) {
+ // shortcuts to this and getting time functions
+ // done to save bytes in minification
+ var date = makeInputDate(_date),
+ currentMonth = date.getMonth(),
+ currentDate = date.getDate(),
+ currentYear = date.getFullYear(),
+ currentDay = date.getDay(),
+ currentHours = date.getHours(),
+ currentMinutes = date.getMinutes(),
+ currentSeconds = date.getSeconds(),
+ charactersToReplace = /(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?)/g;
+ // check if the character is a format
+ // return formatted string or non string.
+ function replaceFunction(input) {
+ // create a couple variables to be used later inside one of the cases.
+ var a, b;
+ switch (input) {
+ // MONTH
+ case 'M' :
+ return currentMonth + 1;
+ case 'Mo' :
+ return (currentMonth + 1) + createOrdinal(currentMonth + 1);
+ case 'MM' :
+ return leftZeroFill(currentMonth + 1, 2);
+ case 'MMM' :
+ return wordsMonthsShort[currentMonth];
+ case 'MMMM' :
+ return wordsMonths[currentMonth];
+ // DAY OF MONTH
+ case 'D' :
+ return currentDate;
+ case 'Do' :
+ return currentDate + createOrdinal(currentDate);
+ case 'DD' :
+ return leftZeroFill(currentDate, 2);
+ // DAY OF YEAR
+ case 'DDD' :
+ a = new Date(currentYear, currentMonth, currentDate);
+ b = new Date(currentYear, 0, 1);
+ return ((a - b) / 864e5) + 1.5 | 0;
+ case 'DDDo' :
+ a = replaceFunction('DDD');
+ return a + createOrdinal(a);
+ case 'DDDD' :
+ return leftZeroFill(replaceFunction('DDD'), 3);
+ // WEEKDAY
+ case 'd' :
+ return currentDay;
+ case 'do' :
+ return currentDay + createOrdinal(currentDay);
+ case 'ddd' :
+ return wordsWeekdaysShort[currentDay];
+ case 'dddd' :
+ return wordsWeekdays[currentDay];
+ // WEEK OF YEAR
+ case 'w' :
+ a = new Date(currentYear, currentMonth, currentDate - currentDay + 5);
+ b = new Date(a.getFullYear(), 0, 4);
+ return (a - b) / 864e5 / 7 + 1.5 | 0;
+ case 'wo' :
+ a = replaceFunction('w');
+ return a + createOrdinal(a);
+ case 'ww' :
+ return leftZeroFill(replaceFunction('w'), 2);
+ // YEAR
+ case 'YY' :
+ return (currentYear + '').slice(-2);
+ case 'YYYY' :
+ return currentYear;
+ // AM / PM
+ case 'a' :
+ return currentHours > 11 ? 'pm' : 'am';
+ case 'A' :
+ return currentHours > 11 ? 'PM' : 'AM';
+ // 24 HOUR
+ case 'H' :
+ return currentHours;
+ case 'HH' :
+ return leftZeroFill(currentHours, 2);
+ // 12 HOUR
+ case 'h' :
+ return currentHours % 12 || 12;
+ case 'hh' :
+ return leftZeroFill(currentHours % 12 || 12, 2);
+ // MINUTE
+ case 'm' :
+ return currentMinutes;
+ case 'mm' :
+ return leftZeroFill(currentMinutes, 2);
+ // SECOND
+ case 's' :
+ return currentSeconds;
+ case 'ss' :
+ return leftZeroFill(currentSeconds, 2);
+ // DEFAULT
+ default :
+ return input.replace("\\", "");
+ }
+ }
+ return inputString.replace(charactersToReplace, replaceFunction);
+ },
+ fromNow : function(time, now) {
+ var difference = _d.msApart(time, now),
+ string = difference < 0 ? wordsTimeAgo.past : wordsTimeAgo.future;
+ return string.replace(/%s/i, _d.relativeTime(difference));
+ },
+ isLeapYear : function(input) {
+ var year = !isNaN(input) && input < 1e4 ? input : makeInputDate(input).getFullYear();
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
+ },
+ msApart : function(time, now) {
+ return makeInputMilliseconds(time) - makeInputMilliseconds(now);
+ },
now : function(asTimestamp) {
return asTimestamp ? new Date().getTime() : new Date();
},
- relativetime : function(milliseconds) {
+ relativeTime : function(milliseconds) {
var seconds = Math.abs(makeInputMilliseconds(milliseconds)) / 1000,
minutes = seconds / 60,
hours = minutes / 60,
years < 2 && substituteTimeAgo('y') ||
substituteTimeAgo('yy', years | 0);
},
- msapart : function(time, now) {
- return makeInputMilliseconds(time) - makeInputMilliseconds(now);
- },
- fromnow : function(time, now) {
- var difference = _d.msapart(time, now),
- string = difference < 0 ? wordsTimeAgo.past : wordsTimeAgo.future;
- return string.replace(/%s/i, _d.relativetime(difference));
- },
- customizedate : function(input) {
- if (input.weekdays && _.isArray(input.weekdays) && input.weekdays.length === 7) {
- wordsWeekdays = input.weekdays;
- }
- if (input.months && _.isArray(input.months) && input.months.length === 12) {
- wordsMonths = input.months;
- }
- if (input.timeago) {
- _.extend(wordsTimeAgo, input.timeago);
- }
- if (input.ordinal && _.isFunction(input.ordinal)) {
- createOrdinal = input.ordinal;
- }
+ subtractTime : function(date, input) {
+ return dateAddRemove(input, makeInputDate(date), -1);
}
};
- // assign to global
- self._d = _d;
-
// integrate with underscore.js
if (_ && _.mixin) {
_.mixin(_d);
module("Date");
- test("dateFormat", function() {
+ test("formatDate", function() {
var dateTest = new Date(2010, 1, 14, 15, 25, 50, 125);
expect(14);
- equal(dateTest.humanize("dddd, MMMM Do YYYY, h:mm:ss a"), "Sunday, February 14th 2010, 3:25:50 pm");
- equal(dateTest.humanize("ddd, hA"), "Sun, 3PM");
- equal(dateTest.humanize("M Mo MM MMMM MMM"), "2 2nd 02 February Feb");
- equal(dateTest.humanize("YYYY YY"), "2010 10");
- equal(dateTest.humanize("D Do DD"), "14 14th 14");
- equal(dateTest.humanize("d do dddd ddd"), "0 0th Sunday Sun");
- equal(dateTest.humanize("DDD DDDo DDDD"), "45 45th 045");
- equal(dateTest.humanize("w wo ww"), "8 8th 08");
- equal(dateTest.humanize("h hh"), "3 03");
- equal(dateTest.humanize("H HH"), "15 15");
- equal(dateTest.humanize("m mm"), "25 25");
- equal(dateTest.humanize("s ss"), "50 50");
- equal(dateTest.humanize("a A"), "pm PM");
- equal(dateTest.humanize("t\\he DDDo \\d\\ay of t\\he ye\\ar"), "the 45th day of the year");
+ equal(_.formatDate([2010, 1, 14, 15, 25, 50, 125], "dddd, MMMM Do YYYY, h:mm:ss a"), "Sunday, February 14th 2010, 3:25:50 pm");
+ equal(_.formatDate([2010, 1, 14, 15, 25, 50, 125], "ddd, hA"), "Sun, 3PM");
+ equal(_.formatDate(dateTest, "M Mo MM MMMM MMM"), "2 2nd 02 February Feb");
+ equal(_.formatDate(dateTest, "YYYY YY"), "2010 10");
+ equal(_.formatDate(dateTest, "D Do DD"), "14 14th 14");
+ equal(_.formatDate(dateTest, "d do dddd ddd"), "0 0th Sunday Sun");
+ equal(_.formatDate(dateTest, "DDD DDDo DDDD"), "45 45th 045");
+ equal(_.formatDate(dateTest, "w wo ww"), "8 8th 08");
+ equal(_.formatDate(dateTest, "h hh"), "3 03");
+ equal(_.formatDate(dateTest, "H HH"), "15 15");
+ equal(_.formatDate(dateTest, "m mm"), "25 25");
+ equal(_.formatDate(dateTest, "s ss"), "50 50");
+ equal(_.formatDate(dateTest, "a A"), "pm PM");
+ equal(_.formatDate(dateTest, "t\\he DDDo \\d\\ay of t\\he ye\\ar"), "the 45th day of the year");
});
- test("add || subtract", function() {
- var dateTest = new Date(2010, 1, 14, 15, 25, 50, 125);
- expect(7);
- equal(dateTest.humanize("MMMM Do YYYY, h:mm:ss a"), "February 14th 2010, 3:25:50 pm");
-
- dateTest.add({ms:200,s:10,m:10,h:2,d:3,M:2,y:3});
- equal(dateTest.humanize("MMMM Do YYYY, h:mm:ss a"), "April 17th 2013, 5:36:00 pm");
-
- dateTest.add({w:1});
- equal(dateTest.humanize("MMMM Do YYYY, h:mm:ss a"), "April 24th 2013, 5:36:00 pm");
-
- dateTest = new Date(2010, 0, 31);
- equal(dateTest.humanize("MMMM Do YYYY"), "January 31st 2010");
-
- dateTest.add({M:1});
- equal(dateTest.humanize("MMMM Do YYYY"), "February 28th 2010");
-
- dateTest = new Date(2008, 1, 29);
- dateTest.subtract({y:1});
- equal(dateTest.humanize("MMMM Do YYYY"), "February 28th 2007");
-
- dateTest = new Date(2008, 1, 29);
- dateTest.subtract({M:1});
- equal(dateTest.humanize("MMMM Do YYYY"), "January 29th 2008");
+ test("date", function() {
+ expect(6);
+ ok(_.isDate(_.date([2010, 1, 12])), "[2010, 1, 12]");
+ ok(_.isDate(_.date([2010, 1, 12, 1])), "[2010, 1, 12, 1]");
+ ok(_.isDate(_.date()), "undefined");
+ ok(_.isDate(_.date("Aug 9, 1995")), "Aug 9, 1995");
+ ok(_.isDate(_.date("Mon, 25 Dec 1995 13:30:00 GMT")), "Mon, 25 Dec 1995 13:30:00 GMT");
+ deepEqual(_.date(new Date(2010, 1, 14, 15, 25, 50, 125)), _.date([2010, 1, 14, 15, 25, 50, 125]), "native date constructor === _.date([]);");
+ });
+
+
+ test("addTime + subtractTime", function() {
+ expect(5);
+ equal(_([2010, 1, 14, 15, 25, 50, 125]).chain().date().addTime({ms:200,s:10,m:10,h:2,d:3,M:2,y:3}).formatDate("MMMM Do YYYY, h:mm:ss a").value(), "April 17th 2013, 5:36:00 pm");
+ equal(_([2010, 0, 31]).chain().date().formatDate("MMMM Do YYYY").value(), "January 31st 2010");
+ equal(_([2010, 0, 31]).chain().date().addTime({M:1}).formatDate("MMMM Do YYYY").value(), "February 28th 2010");
+ equal(_([2007, 1, 28]).chain().date().formatDate("MMMM Do YYYY").value(), "February 28th 2007");
+ equal(_([2007, 1, 28]).chain().date().subtractTime({M:1}).formatDate("MMMM Do YYYY").value(), "January 28th 2007");
+ });
+
+
+ test("relativeTime", function() {
+ expect(11);
+ equal(_.relativeTime(1000 * 30), "less than a minute");
+ equal(_.relativeTime(1000 * 60), "about a minute");
+ equal(_.relativeTime(1000 * 60 * 5), "5 minutes");
+ equal(_.relativeTime(1000 * 60 * 60), "about an hour");
+ equal(_.relativeTime(1000 * 60 * 60 * 5), "about 5 hours");
+ equal(_.relativeTime(1000 * 60 * 60 * 24), "a day");
+ equal(_.relativeTime(1000 * 60 * 60 * 24 * 5), "5 days");
+ equal(_.relativeTime(1000 * 60 * 60 * 24 * 30), "about a month");
+ equal(_.relativeTime(1000 * 60 * 60 * 24 * 30 * 5), "5 months");
+ equal(_.relativeTime(1000 * 60 * 60 * 24 * 30 * 12), "about a year");
+ equal(_.relativeTime(1000 * 60 * 60 * 24 * 365 * 5), "5 years");
});
- test("isleapyear", function() {
- expect(4);
- equal(new Date(2010, 0, 1).isleapyear(), false);
- equal(new Date(2100, 0, 1).isleapyear(), false);
- equal(new Date(2008, 0, 1).isleapyear(), true);
- equal(new Date(2000, 0, 1).isleapyear(), true);
+ test("msApart", function() {
+ expect(5);
+ equal(_.msApart(1000, 0), 1000, "1 second (ms) - 0 = 1000");
+ equal(_.msApart(1000, 500), 500, "1 second (ms) - .5 second (ms) = -500");
+ equal(_.msApart(0, 1000), -1000, "0 - 1 second (ms) = -1000");
+ equal(_.msApart(new Date(1000), 1000), 0, "1 second (date) - 1 second (ms) = 0");
+ var oneHourDate = new Date(),
+ nowDate = new Date();
+ oneHourDate.setHours(oneHourDate.getHours() + 1);
+ equal(_.msApart(oneHourDate, nowDate), 60 * 60 * 1000, "1 hour from now = 360000");
});
+ test("fromNow", function() {
+ expect(2);
+ equal(_.fromNow(30000, 0), "in less than a minute");
+ equal(_.fromNow(0, 30000), "less than a minute ago");
+ });
+
+ test("isLeapYear", function() {
+ expect(7);
+ equal(_.isLeapYear(2010), false);
+ equal(_.isLeapYear(2100), false);
+ equal(_.isLeapYear(2008), true);
+ equal(_.isLeapYear(2000), true);
+ equal(_.isLeapYear([2100, 0, 1]), false);
+ equal(_.isLeapYear(new Date(2008, 0, 1)), true);
+ equal(_.isLeapYear(new Date(2000, 0, 1)), true);
+ });
+
+ /*
test("isdst", function() {
expect(2);
equal(new Date(2010, 0, 1).isdst(), false);
equal(new Date(2010, 6, 1).isdst(), true);
- });
-
+ });*/
});
\ No newline at end of file
date2 = new Date(1000),
rt1 = 1000 * 60 * 60 * 24 * 365 * 5,
rt2 = 1000 * 30;
-
- JSLitmus.test('Date.humanize => Sunday, February 14th 2010, 3:25:50 pm', function() {
- return date1.humanize("w, l D1 Y, h:m2:s2 a");
- });
-
- JSLitmus.test('Date.humanize => Sun, 3PM', function() {
- return date1.humanize("w1, hA");
- });
JSLitmus.test('_.fromnow(1000 * 30, 0)', function() {
return _.fromnow(1000, 0);
});
- JSLitmus.test('_.relativetime(1000 * 30)', function() {
- return _.relativetime(rt2);
+ JSLitmus.test('_.relativeTime(1000 * 30)', function() {
+ return _.relativeTime(rt2);
});
- JSLitmus.test('_.relativetime(1000 * 60 * 60 * 24 * 365 * 5)', function() {
- return _.relativetime(rt1);
+ JSLitmus.test('_.relativeTime(1000 * 60 * 60 * 24 * 365 * 5)', function() {
+ return _.relativeTime(rt1);
});
- JSLitmus.test('_.msapart(1000)', function() {
- return _.msapart(1000);
+ JSLitmus.test('_.msApart(1000)', function() {
+ return _.msApart(1000);
});
- JSLitmus.test('_.msapart(date1, date2)', function() {
- return _.msapart(date1, date2);
+ JSLitmus.test('_.msApart(date1, date2)', function() {
+ return _.msApart(date1, date2);
});
- JSLitmus.test('_.msapart(date1, 1000)', function() {
- return _.msapart(date1, 1000);
+ JSLitmus.test('_.msApart(date1, 1000)', function() {
+ return _.msApart(date1, 1000);
});
- JSLitmus.test('_.msapart(1000, 1000)', function() {
- return _.msapart(1000, 1000);
- });
-
- JSLitmus.test('date1.isleapyear()', function() {
- return date1.isleapyear();
+ JSLitmus.test('_.msApart(1000, 1000)', function() {
+ return _.msApart(1000, 1000);
});
+ JSLitmus.test('_.date(date1)', function() {
+ return _.date(date1);
+ });
+ JSLitmus.test('_.date([2010, 2, 6, 15, 25, 50, 125])', function() {
+ return _.date([2010, 2, 6, 15, 25, 50, 125]);
+ });
+ JSLitmus.test('_.date(100000)', function() {
+ return _.date(100000);
+ });
+ JSLitmus.test('_.date("Mon, 25 Dec 1995 13:30:00 GMT")', function() {
+ return _.date("Mon, 25 Dec 1995 13:30:00 GMT");
+ });
+ JSLitmus.test('_.date()', function() {
+ return _.date();
+ });
})();
\ No newline at end of file
module("Time");
- test("relativetime", function() {
- expect(11);
- equal(_.relativetime(1000 * 30), "less than a minute");
- equal(_.relativetime(1000 * 60), "about a minute");
- equal(_.relativetime(1000 * 60 * 5), "5 minutes");
- equal(_.relativetime(1000 * 60 * 60), "about an hour");
- equal(_.relativetime(1000 * 60 * 60 * 5), "about 5 hours");
- equal(_.relativetime(1000 * 60 * 60 * 24), "a day");
- equal(_.relativetime(1000 * 60 * 60 * 24 * 5), "5 days");
- equal(_.relativetime(1000 * 60 * 60 * 24 * 30), "about a month");
- equal(_.relativetime(1000 * 60 * 60 * 24 * 30 * 5), "5 months");
- equal(_.relativetime(1000 * 60 * 60 * 24 * 30 * 12), "about a year");
- equal(_.relativetime(1000 * 60 * 60 * 24 * 365 * 5), "5 years");
- });
-
- test("msapart", function() {
- expect(5);
- equal(_d.msapart(1000, 0), 1000, "1 second (ms) - 0 = 1000");
- equal(_d.msapart(1000, 500), 500, "1 second (ms) - .5 second (ms) = -500");
- equal(_d.msapart(0, 1000), -1000, "0 - 1 second (ms) = -1000");
- equal(_d.msapart(new Date(1000), 1000), 0, "1 second (date) - 1 second (ms) = 0");
- var oneHourDate = new Date(),
- nowDate = new Date();
- oneHourDate.setHours(oneHourDate.getHours() + 1);
- equal(_d.msapart(oneHourDate, nowDate), 60 * 60 * 1000, "1 hour from now = 360000");
- });
-
- test("fromnow", function() {
- expect(2);
- equal(_d.fromnow(30000, 0), "in less than a minute");
- equal(_d.fromnow(0, 30000), "less than a minute ago");
- });
});