From 8a169db7f45a849ef37193998f39df7011179aa8 Mon Sep 17 00:00:00 2001 From: Felix Nagel Date: Sun, 27 Sep 2015 18:51:39 +0200 Subject: [PATCH] Calendar: Remove all unused methods from custom date object --- tests/unit/date/core.js | 23 +++++------------------ ui/date.js | 37 ------------------------------------- 2 files changed, 5 insertions(+), 55 deletions(-) diff --git a/tests/unit/date/core.js b/tests/unit/date/core.js index 349f5d873..c12303516 100644 --- a/tests/unit/date/core.js +++ b/tests/unit/date/core.js @@ -14,14 +14,13 @@ test( "Instantiation", function() { ok( $.ui.date( null, attributes ) instanceof $.ui.date, "instantiation without new" ); }); -test( "Check Sets and Gets", 6, function() { +test( "Check Sets and Gets", 4, function() { var date = $.ui.date( null, attributes ); - equal( date.setYear( 2012 ).year(), 2012, "Set year and retrieve" ); - equal( date.setMonth( 9 ).month(), 9, "Set month and retrieve" ); equal( date.setDay( 15 ).day(), 15, "Set day and retrieve" ); equal( date.setFullDate( 2012, 9, 15 ).year(), 2012, "Set full date and retrieve year" ); equal( date.month(), 9, "Set full date and retrieve month" ); equal( date.day(), 15, "Set full date and retrieve day" ); + // TODO Add setTime test }); test( "Date Adjustments - Normal Use Cases", 10, function() { @@ -95,18 +94,6 @@ test( "List days of Week", 2, function() { deepEqual( date.weekdays(), offset1, "Get weekdays with start of day on 1 (Germany)" ); }); -test( "Leap Year Check", 8, function() { - var date = $.ui.date( null, attributes ); - ok( date.setYear( 2008 ).isLeapYear(), "2008 is a Leap Year" ); - ok( !date.setYear( 2009 ).isLeapYear(), "2009 is not a Leap Year" ); - ok( !date.setYear( 2010 ).isLeapYear(), "2010 is not a Leap Year" ); - ok( !date.setYear( 2011 ).isLeapYear(), "2011 is not a Leap Year" ); - ok( date.isLeapYear( 2012 ), "2012 is a Leap Year" ); - ok( !date.isLeapYear( 2013 ), "2013 is not a Leap Year" ); - ok( !date.isLeapYear( 2014 ), "2014 is not a Leap year" ); - ok( !date.isLeapYear( 2015 ), "2015 is not a Leap year" ); -}); - test( "Days in Month", 3, function() { var date = $.ui.date( null, attributes ); date.setFullDate( 2012, 1, 1 ); @@ -117,9 +104,9 @@ test( "Days in Month", 3, function() { test( "Month Name", 2, function() { var date = $.ui.date( null, attributes ); - equal( date.setMonth( 3 ).monthName(), "April", "Month name return April (English)" ); + equal( date.setFullDate( 2012, 3, 1 ).monthName(), "April", "Month name return April (English)" ); date = $.ui.date( null, testHelper.getAttributes( "de" ) ); - equal( date.setMonth( 2 ).monthName(), "März", "Month name return March (German)" ); + equal( date.setFullDate( 2012, 2, 1 ).monthName(), "März", "Month name return March (German)" ); }); test( "Clone", 2, function() { @@ -130,7 +117,7 @@ test( "Clone", 2, function() { }); test( "Days", 1, function() { - // TODO needs work + // TODO Needs work var date = $.ui.date( null, attributes ); date.eachDay = function( day ) { if ( day.lead && day.date > 20 ) { diff --git a/ui/date.js b/ui/date.js index 1d207a39f..b192d6bc2 100644 --- a/ui/date.js +++ b/ui/date.js @@ -65,38 +65,6 @@ $.extend( $.ui.date.prototype, { return this; }, - setMonth: function( month ) { - - // Overflow example: Month is October 31 (yeah Halloween) and month is changed to April with 30 days, - // the new date will me May 1. We will honor the month the user wants to set and if and overflow - // occurs, set to last day of month. - var date = this.dateObject, - days = date.getDate(), year = date.getFullYear(); - if ( days > this.daysInMonth( year, month ) ) { - - // Overflow - days = this.daysInMonth( year, month ); - } - this.dateObject = new Date( year, month, days, date.getHours(), - date.getMinutes(), date.getSeconds() ); - return this; - }, - - setYear: function( year ) { - var date = this.dateObject, - day = date.getDate(), - month = date.getMonth(); - - // Check if Leap, and February and day is 29th - if ( this.isLeapYear( year ) && month === 1 && day === 29 ) { - - // set day to last day of February - day = this.daysInMonth( year, month ); - } - this.dateObject = new Date( year, month, day, date.getHours(), - date.getMinutes(), date.getSeconds() ); - return this; - }, setFullDate: function( year, month, day ) { this.dateObject = new Date( year, month, day ); @@ -141,11 +109,6 @@ $.extend( $.ui.date.prototype, { return this.dateObject.getFullYear(); }, - isLeapYear: function( year ) { - year = year || this.dateObject.getFullYear(); - return new Date( year, 1, 29 ).getMonth() === 1; - }, - weekdays: function() { var date, firstDay = this.firstDay, -- 2.39.5