DateAssert.js revision d0199bcbfc68b65683c19c4e3e0c38e238142e7e
3853N/A
3853N/A
3853N/A/**
3853N/A * The DateAssert object provides functions to test JavaScript Date objects
3853N/A * for a variety of cases.
3853N/A * @namespace Test
3853N/A * @class DateAssert
3853N/A * @static
3853N/A */
3853N/A
3853N/AYUITest.DateAssert = {
3853N/A
3853N/A /**
3853N/A * Asserts that a date's month, day, and year are equal to another date's.
3853N/A * @param {Date} expected The expected date.
3853N/A * @param {Date} actual The actual date to test.
3853N/A * @param {String} message (Optional) The message to display if the assertion fails.
3853N/A * @method datesAreEqual
3853N/A * @static
3853N/A */
3853N/A datesAreEqual : function (expected, actual, message){
3853N/A YUITest.Assert._increment();
3853N/A if (expected instanceof Date && actual instanceof Date){
3853N/A var msg = "";
5035N/A
3853N/A //check years first
3853N/A if (expected.getFullYear() != actual.getFullYear()){
3853N/A msg = "Years should be equal.";
3853N/A }
3853N/A
4803N/A //now check months
3853N/A if (expected.getMonth() != actual.getMonth()){
3853N/A msg = "Months should be equal.";
3853N/A }
4141N/A
3853N/A //last, check the day of the month
3853N/A if (expected.getDate() != actual.getDate()){
3853N/A msg = "Days of month should be equal.";
3853N/A }
3853N/A
4141N/A if (msg.length){
3898N/A throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, msg), expected, actual);
3898N/A }
4920N/A } else {
4518N/A throw new TypeError("YUITest.DateAssert.datesAreEqual(): Expected and actual values must be Date objects.");
3853N/A }
3853N/A },
3853N/A
3853N/A /**
4803N/A * Asserts that a date's hour, minutes, and seconds are equal to another date's.
3853N/A * @param {Date} expected The expected date.
3853N/A * @param {Date} actual The actual date to test.
3853N/A * @param {String} message (Optional) The message to display if the assertion fails.
3853N/A * @method timesAreEqual
3853N/A * @static
3853N/A */
3853N/A timesAreEqual : function (expected, actual, message){
3853N/A YUITest.Assert._increment();
3853N/A if (expected instanceof Date && actual instanceof Date){
3853N/A var msg = "";
3853N/A
3853N/A //check hours first
3853N/A if (expected.getHours() != actual.getHours()){
3853N/A msg = "Hours should be equal.";
3853N/A }
4803N/A
4803N/A //now check minutes
3853N/A if (expected.getMinutes() != actual.getMinutes()){
3853N/A msg = "Minutes should be equal.";
3853N/A }
3853N/A
3853N/A //last, check the seconds
3853N/A if (expected.getSeconds() != actual.getSeconds()){
3853N/A msg = "Seconds should be equal.";
3853N/A }
4141N/A
4141N/A if (msg.length){
4141N/A throw new YUITest.ComparisonFailure(YUITest.Assert._formatMessage(message, msg), expected, actual);
4141N/A }
4141N/A } else {
4141N/A throw new TypeError("YUITest.DateAssert.timesAreEqual(): Expected and actual values must be Date objects.");
4141N/A }
4141N/A }
4141N/A
4141N/A};
4518N/A