Datepicker: Initial commit of widget rewrite work from old branch

History is on the datepicker-dead branch.
This commit is contained in:
TJ VanToll 2013-08-26 06:44:20 -04:00 committed by Scott González
parent 912eb62ccb
commit 68f8e3c2e3
8 changed files with 1461 additions and 1999 deletions

View File

@ -5,8 +5,13 @@
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="../../themes/base/all.css">
<script src="../../external/jquery/jquery.js"></script>
<script src="../../external/globalize/globalize.js"></script>
<script src="../../external/date.js"></script>
<script src="../../external/localization.js"></script>
<script src="../../ui/core.js"></script>
<script src="../../ui/widget.js"></script>
<script src="../../ui/button.js"></script>
<script src="../../ui/position.js"></script>
<script src="../../ui/datepicker.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>

197
external/date.js vendored Normal file
View File

@ -0,0 +1,197 @@
/*
* Calendar math built on jquery-global
*
* Based on Marc Grabanski's jQuery Date Plugin
* http://marcgrabanski.com/articles/jquery-date-plugin
*/
(function( $, undefined ) {
$.date = function( datestring, formatstring ) {
//TODO: Need to refactor $.date to be a constructor, move the methods to a prototype.
var calendar = Globalize.culture().calendar,
format = formatstring ? formatstring : calendar.patterns.d,
date = datestring ? Globalize.parseDate( datestring, format ) : new Date();
if ( !date ) {
date = new Date();
}
return {
refresh: function() {
calendar = Globalize.culture().calendar;
format = formatstring || calendar.patterns.d;
return this;
},
setFormat: function( formatstring ) {
if ( formatstring ) {
format = formatstring;
}
return this;
},
//TODO: same as the underlying Date object's terminology, but still misleading.
//TODO: We can use .setTime() instead of new Date and rename to setTimestamp.
setTime: function( time ) {
date = new Date( time );
return this;
},
setDay: function( day ) {
date = new Date( date.getFullYear(), date.getMonth(), day, date.getHours(), date.getMinutes(), date.getSeconds() );
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 days = date.getDay(), year = date.getFullYear();
if ( days > this.daysInMonth( year, month ) ) {
// Overflow
days = this.daysInMonth( year, month );
}
date = new Date( year, month, days, date.getHours(), date.getMinutes(), date.getSeconds() );
return this;
},
setYear: function( year ) {
var 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 );
}
date = new Date( year, month, day, date.getHours(), date.getMinutes(), date.getSeconds() );
return this;
},
setFullDate: function( year, month, day ) {
date = new Date( year, month, day );
return this;
},
adjust: function( period, offset ) {
var day = period == "D" ? date.getDate() + offset : date.getDate(),
month = period == "M" ? date.getMonth() + offset : date.getMonth(),
year = period == "Y" ? date.getFullYear() + offset : date.getFullYear();
// If not day, update the day to the new month and year
if ( period != "D" ) {
day = Math.max( 1, Math.min( day, this.daysInMonth( year, month ) ) );
}
date = new Date( year, month, day, date.getHours(), date.getMinutes(), date.getSeconds() );
return this;
},
daysInMonth: function( year, month ) {
year = year || date.getFullYear();
month = month || date.getMonth();
return 32 - new Date( year, month, 32 ).getDate();
},
monthName: function() {
return calendar.months.names[ date.getMonth() ];
},
day: function() {
return date.getDate();
},
month: function() {
return date.getMonth();
},
year: function() {
return date.getFullYear();
},
isLeapYear: function( year ) {
year = year || date.getFullYear();
return new Date( year, 1, 29 ).getMonth() == 1;
},
weekdays: function() {
var result = [];
for ( var dow = 0; dow < 7; dow++ ) {
var day = ( dow + calendar.firstDay ) % 7;
result.push({
shortname: calendar.days.namesShort[ day ],
fullname: calendar.days.names[ day ]
});
}
return result;
},
days: function() {
var result = [],
today = $.date(),
firstDayOfMonth = new Date( this.year(), date.getMonth(), 1 ).getDay(),
leadDays = ( firstDayOfMonth - calendar.firstDay + 7 ) % 7,
rows = Math.ceil( ( leadDays + this.daysInMonth() ) / 7 ),
printDate = new Date( this.year(), date.getMonth(), 1 - leadDays );
for ( var row = 0; row < rows; row++ ) {
var week = result[ result.length ] = {
number: this.iso8601Week( printDate ),
days: []
};
for ( var dayx = 0; dayx < 7; dayx++ ) {
var day = week.days[ week.days.length ] = {
lead: printDate.getMonth() != date.getMonth(),
date: printDate.getDate(),
timestamp: printDate.getTime(),
current: this.selected && this.selected.equal( printDate ),
today: today.equal( printDate )
};
day.render = day.selectable = !day.lead;
// TODO undefined in picker demos, fix it
// this.eachDay( day );
// TODO use adjust("D", 1)?
printDate.setDate( printDate.getDate() + 1 );
}
}
return result;
},
// specialized for multi-month template, could be used in general
months: function( add ) {
var clone,
result = [ this ];
for ( var i = 0; i < add; i++ ) {
clone = this.clone();
clone.adjust( "M", i + 1 );
result.push( clone );
}
result[ 0 ].first = true;
result[ result.length - 1 ].last = true;
return result;
},
iso8601Week: function(date) {
var checkDate = new Date( date.getTime() );
// Find Thursday of this week starting on Monday
checkDate.setDate( checkDate.getDate() + 4 - ( checkDate.getDay() || 7 ) );
var time = checkDate.getTime();
// Compare with Jan 1
checkDate.setMonth( 0 );
checkDate.setDate( 1 );
return Math.floor( Math.round( ( time - checkDate ) / 86400000) / 7 ) + 1;
},
select: function() {
this.selected = this.clone();
return this;
},
clone: function() {
return $.date( new Date(date.getFullYear(), date.getMonth(),
date.getDate(), date.getHours(),
date.getMinutes(), date.getSeconds()), formatstring );
},
// TODO compare year, month, day each for better performance
equal: function( other ) {
function format( date ) {
return Globalize.format( date, "d" );
}
return format( date ) === format( other );
},
date: function() {
return date;
},
format: function( formatstring ) {
return Globalize.format( date, formatstring ? formatstring : format );
},
calendar: function( newcalendar ) {
if ( newcalendar ) {
calendar = newcalendar;
return this;
}
return calendar;
}
};
};
}( jQuery ));

436
external/localization.js vendored Normal file
View File

@ -0,0 +1,436 @@
// regional data
var regions = {
"en": {
"closeText": "Done",
"prevText": "Prev",
"nextText": "Next",
"currentText": "Today",
"weekHeader": "Wk",
"dateFormat": "d",
"datePickerRole": "date picker"
},
"af": {
"closeText": "Selekteer",
"prevText": "Vorige",
"nextText": "Volgende",
"currentText": "Vandag",
"weekHeader": "Wk",
"dateFormat": "d"
},
"zh-TW": {
"closeText": "\u95dc\u9589",
"prevText": "&#x3c;\u4e0a\u6708",
"nextText": "\u4e0b\u6708&#x3e;",
"currentText": "\u4eca\u5929",
"weekHeader": "\u5468",
"dateFormat": "d"
},
"ar": {
"closeText": "\u0625\u063a\u0644\u0627\u0642",
"prevText": "&#x3c;\u0627\u0644\u0633\u0627\u0628\u0642",
"nextText": "\u0627\u0644\u062a\u0627\u0644\u064a&#x3e;",
"currentText": "\u0627\u0644\u064a\u0648\u0645",
"weekHeader": "\u0623\u0633\u0628\u0648\u0639",
"dateFormat": "d"
},
"az": {
"closeText": "Ba\u011fla",
"prevText": "&#x3c;Geri",
"nextText": "\u0130r\u0259li&#x3e;",
"currentText": "Bug\u00fcn",
"weekHeader": "Hf",
"dateFormat": "d"
},
"bg": {
"closeText": "\u0437\u0430\u0442\u0432\u043e\u0440\u0438",
"prevText": "&#x3c;\u043d\u0430\u0437\u0430\u0434",
"nextText": "\u043d\u0430\u043f\u0440\u0435\u0434&#x3e;",
"currentText": "\u0434\u043d\u0435\u0441",
"weekHeader": "Wk",
"dateFormat": "d"
},
"bs": {
"closeText": "Zatvori",
"prevText": "&#x3c;",
"nextText": "&#x3e;",
"currentText": "Danas",
"weekHeader": "Wk",
"dateFormat": "d"
},
"ca": {
"closeText": "Tancar",
"prevText": "&#x3c;Ant",
"nextText": "Seg&#x3e;",
"currentText": "Avui",
"weekHeader": "Sm",
"dateFormat": "d"
},
"cs": {
"closeText": "Zav\u0159\u00edt",
"prevText": "&#x3c;D\u0159\u00edve",
"nextText": "Pozd\u011bji&#x3e;",
"currentText": "Nyn\u00ed",
"weekHeader": "T\u00fdd",
"dateFormat": "d"
},
"da": {
"closeText": "Luk",
"prevText": "&#x3c;Forrige",
"nextText": "N\u00e6ste&#x3e;",
"currentText": "Idag",
"weekHeader": "Uge",
"dateFormat": "d"
},
"de": {
"closeText": "schlie\u00dfen",
"prevText": "&#x3c;zur\u00fcck",
"nextText": "Vor&#x3e;",
"currentText": "heute",
"weekHeader": "Wo",
"dateFormat": "d"
},
"el": {
"closeText": "\u039a\u03bb\u03b5\u03af\u03c3\u03b9\u03bc\u03bf",
"prevText": "\u03a0\u03c1\u03bf\u03b7\u03b3\u03bf\u03cd\u03bc\u03b5\u03bd\u03bf\u03c2",
"nextText": "\u0395\u03c0\u03cc\u03bc\u03b5\u03bd\u03bf\u03c2",
"currentText": "\u03a4\u03c1\u03ad\u03c7\u03c9\u03bd \u039c\u03ae\u03bd\u03b1\u03c2",
"weekHeader": "\u0395\u03b2\u03b4",
"dateFormat": "d"
},
"en-GB": {
"closeText": "Done",
"prevText": "Prev",
"nextText": "Next",
"currentText": "Today",
"weekHeader": "Wk",
"dateFormat": "d"
},
"eo": {
"closeText": "Fermi",
"prevText": "&lt;Anta",
"nextText": "Sekv&gt;",
"currentText": "Nuna",
"weekHeader": "Sb",
"dateFormat": "dd/MM/yyyy"
},
"es": {
"closeText": "Cerrar",
"prevText": "&#x3c;Ant",
"nextText": "Sig&#x3e;",
"currentText": "Hoy",
"weekHeader": "Sm",
"dateFormat": "d"
},
"et": {
"closeText": "Sulge",
"prevText": "Eelnev",
"nextText": "J\u00e4rgnev",
"currentText": "T\u00e4na",
"weekHeader": "Sm",
"dateFormat": "d"
},
"eu": {
"closeText": "Egina",
"prevText": "&#x3c;Aur",
"nextText": "Hur&#x3e;",
"currentText": "Gaur",
"weekHeader": "Wk",
"dateFormat": "d"
},
"fa": {
"closeText": "\u0628\u0633\u062a\u0646",
"prevText": "&#x3c;\u0642\u0628\u0644\u064a",
"nextText": "\u0628\u0639\u062f\u064a&#x3e;",
"currentText": "\u0627\u0645\u0631\u0648\u0632",
"weekHeader": "\u0647\u0641",
"dateFormat": "d"
},
"fi": {
"closeText": "Sulje",
"prevText": "&laquo;Edellinen",
"nextText": "Seuraava&raquo;",
"currentText": "T&auml;n&auml;&auml;n",
"weekHeader": "Vk",
"dateFormat": "d"
},
"fo": {
"closeText": "Lat aftur",
"prevText": "&#x3c;Fyrra",
"nextText": "N\u00e6sta&#x3e;",
"currentText": "\u00cd dag",
"weekHeader": "Vk",
"dateFormat": "d"
},
"fr-CH": {
"closeText": "Fermer",
"prevText": "&#x3c;Pr\u00e9c",
"nextText": "Suiv&#x3e;",
"currentText": "Courant",
"weekHeader": "Sm",
"dateFormat": "d"
},
"fr": {
"closeText": "Fermer",
"prevText": "&#x3c;Pr\u00e9c",
"nextText": "Suiv&#x3e;",
"currentText": "Courant",
"weekHeader": "Sm",
"dateFormat": "d"
},
"he": {
"closeText": "\u05e1\u05d2\u05d5\u05e8",
"prevText": "&#x3c;\u05d4\u05e7\u05d5\u05d3\u05dd",
"nextText": "\u05d4\u05d1\u05d0&#x3e;",
"currentText": "\u05d4\u05d9\u05d5\u05dd",
"weekHeader": "Wk",
"dateFormat": "d"
},
"hr": {
"closeText": "Zatvori",
"prevText": "&#x3c;",
"nextText": "&#x3e;",
"currentText": "Danas",
"weekHeader": "Tje",
"dateFormat": "d"
},
"hu": {
"closeText": "bez\u00c3\u00a1r\u00c3\u00a1s",
"prevText": "&laquo;&nbsp;vissza",
"nextText": "el\u00c5\u2018re&nbsp;&raquo;",
"currentText": "ma",
"weekHeader": "H\u00c3\u00a9",
"dateFormat": "d"
},
"hy": {
"closeText": "\u00d5\u201c\u00d5\u00a1\u00d5\u00af\u00d5\u00a5\u00d5\u00ac",
"prevText": "&#x3c;\u00d5\u2020\u00d5\u00a1\u00d5\u00ad.",
"nextText": "\u00d5\u20ac\u00d5\u00a1\u00d5\u00bb.&#x3e;",
"currentText": "\u00d4\u00b1\u00d5\u00b5\u00d5\u00bd\u00d6\u2026\u00d6\u20ac",
"weekHeader": "\u00d5\u2021\u00d4\u00b2\u00d5\u008f",
"dateFormat": "d"
},
"id": {
"closeText": "Tutup",
"prevText": "&#x3c;mundur",
"nextText": "maju&#x3e;",
"currentText": "hari ini",
"weekHeader": "Mg",
"dateFormat": "d"
},
"is": {
"closeText": "Loka",
"prevText": "&#x3c; Fyrri",
"nextText": "N&aelig;sti &#x3e;",
"currentText": "&Iacute; dag",
"weekHeader": "Vika",
"dateFormat": "d"
},
"it": {
"closeText": "Chiudi",
"prevText": "&#x3c;Prec",
"nextText": "Succ&#x3e;",
"currentText": "Oggi",
"weekHeader": "Sm",
"dateFormat": "d"
},
"ja": {
"closeText": "\u9589\u3058\u308b",
"prevText": "&#x3c;\u524d",
"nextText": "\u6b21&#x3e;",
"currentText": "\u4eca\u65e5",
"weekHeader": "\u9031",
"dateFormat": "d"
},
"ko": {
"closeText": "\u00eb\u2039\u00ab\u00ea\u00b8\u00b0",
"prevText": "\u00ec\u009d\u00b4\u00ec\u00a0\u201e\u00eb\u2039\u00ac",
"nextText": "\u00eb\u2039\u00a4\u00ec\u009d\u0152\u00eb\u2039\u00ac",
"currentText": "\u00ec\u02dc\u00a4\u00eb\u0160\u02dc",
"weekHeader": "Wk",
"dateFormat": "d"
},
"lt": {
"closeText": "U\u00c5\u00bedaryti",
"prevText": "&#x3c;Atgal",
"nextText": "Pirmyn&#x3e;",
"currentText": "\u00c5\u00a0iandien",
"weekHeader": "Wk",
"dateFormat": "d"
},
"lv": {
"closeText": "Aizv\u00c4\u201crt",
"prevText": "Iepr",
"nextText": "N\u00c4\u0081ka",
"currentText": "\u00c5\u00a0odien",
"weekHeader": "Nav",
"dateFormat": "d"
},
"ms": {
"closeText": "Tutup",
"prevText": "&#x3c;Sebelum",
"nextText": "Selepas&#x3e;",
"currentText": "hari ini",
"weekHeader": "Mg",
"dateFormat": "d"
},
"nl": {
"closeText": "Sluiten",
"prevText": "\u2190",
"nextText": "\u2192",
"currentText": "Vandaag",
"weekHeader": "Wk",
"dateFormat": "d"
},
"no": {
"closeText": "Lukk",
"prevText": "&laquo;Forrige",
"nextText": "Neste&raquo;",
"currentText": "I dag",
"weekHeader": "Uke",
"dateFormat": "d"
},
"pl": {
"closeText": "Zamknij",
"prevText": "&#x3c;Poprzedni",
"nextText": "Nast\u00c4\u2122pny&#x3e;",
"currentText": "Dzi\u00c5\u203a",
"weekHeader": "Tydz",
"dateFormat": "d"
},
"pt-BR": {
"closeText": "Fechar",
"prevText": "&#x3c;Anterior",
"nextText": "Pr&oacute;ximo&#x3e;",
"currentText": "Hoje",
"weekHeader": "Sm",
"dateFormat": "d"
},
"ro": {
"closeText": "\u00cenchide",
"prevText": "&laquo; Luna precedent\u0103",
"nextText": "Luna urm\u0103toare &raquo;",
"currentText": "Azi",
"weekHeader": "S\u0103pt",
"dateFormat": "d"
},
"ru": {
"closeText": "\u00d0\u2014\u00d0\u00b0\u00d0\u00ba\u00d1\u20ac\u00d1\u2039\u00d1\u201a\u00d1\u0152",
"prevText": "&#x3c;\u00d0\u0178\u00d1\u20ac\u00d0\u00b5\u00d0\u00b4",
"nextText": "\u00d0\u00a1\u00d0\u00bb\u00d0\u00b5\u00d0\u00b4&#x3e;",
"currentText": "\u00d0\u00a1\u00d0\u00b5\u00d0\u00b3\u00d0\u00be\u00d0\u00b4\u00d0\u00bd\u00d1\u008f",
"weekHeader": "\u00d0\u009d\u00d0\u00b5",
"dateFormat": "d"
},
"sk": {
"closeText": "Zavrie\u00c5\u00a5",
"prevText": "&#x3c;Predch\u00c3\u00a1dzaj\u00c3\u00baci",
"nextText": "Nasleduj\u00c3\u00baci&#x3e;",
"currentText": "Dnes",
"weekHeader": "Ty",
"dateFormat": "d"
},
"sl": {
"closeText": "Zapri",
"prevText": "&lt;Prej&#x161;nji",
"nextText": "Naslednji&gt;",
"currentText": "Trenutni",
"weekHeader": "Teden",
"dateFormat": "d"
},
"sq": {
"closeText": "mbylle",
"prevText": "&#x3c;mbrapa",
"nextText": "P\u00ebrpara&#x3e;",
"currentText": "sot",
"weekHeader": "Ja",
"dateFormat": "d"
},
"sr-SR": {
"closeText": "Zatvori",
"prevText": "&#x3c;",
"nextText": "&#x3e;",
"currentText": "Danas",
"weekHeader": "Sed",
"dateFormat": "dd/MM/yyyy"
},
"sr": {
"closeText": "\u0417\u0430\u0442\u0432\u043e\u0440\u0438",
"prevText": "&#x3c;",
"nextText": "&#x3e;",
"currentText": "\u0414\u0430\u043d\u0430\u0441",
"weekHeader": "\u0421\u0435\u0434",
"dateFormat": "d"
},
"sv": {
"closeText": "St\u00e4ng",
"prevText": "&laquo;F\u00f6rra",
"nextText": "N\u00e4sta&raquo;",
"currentText": "Idag",
"weekHeader": "Ve",
"dateFormat": "d"
},
"ta": {
"closeText": "\u0bae\u0bc2\u0b9f\u0bc1",
"prevText": "\u0bae\u0bc1\u0ba9\u0bcd\u0ba9\u0bc8\u0baf\u0ba4\u0bc1",
"nextText": "\u0b85\u0b9f\u0bc1\u0ba4\u0bcd\u0ba4\u0ba4\u0bc1",
"currentText": "\u0b87\u0ba9\u0bcd\u0bb1\u0bc1",
"weekHeader": "\u041d\u0435",
"dateFormat": "d"
},
"th": {
"closeText": "\u0e1b\u0e34\u0e14",
"prevText": "&laquo;&nbsp;\u0e22\u0e49\u0e2d\u0e19",
"nextText": "\u0e16\u0e31\u0e14\u0e44\u0e1b&nbsp;&raquo;",
"currentText": "\u0e27\u0e31\u0e19\u0e19\u0e35\u0e49",
"weekHeader": "Wk",
"dateFormat": "d"
},
"tr": {
"closeText": "kapat",
"prevText": "&#x3c;geri",
"nextText": "ileri&#x3e",
"currentText": "bug\u00c3\u00bcn",
"weekHeader": "Hf",
"dateFormat": "d"
},
"uk": {
"closeText": "\u00d0\u2014\u00d0\u00b0\u00d0\u00ba\u00d1\u20ac\u00d0\u00b8\u00d1\u201a\u00d0\u00b8",
"prevText": "&#x3c;",
"nextText": "&#x3e;",
"currentText": "\u00d0\u00a1\u00d1\u0152\u00d0\u00be\u00d0\u00b3\u00d0\u00be\u00d0\u00b4\u00d0\u00bd\u00d1\u2013",
"weekHeader": "\u00d0\u009d\u00d0\u00b5",
"dateFormat": "d"
},
"vi": {
"closeText": "\u0110\u00f3ng",
"prevText": "&#x3c;Tr\u01b0\u1edbc",
"nextText": "Ti\u1ebfp&#x3e;",
"currentText": "H\u00f4m nay",
"weekHeader": "Tu",
"dateFormat": "d"
},
"zh-CN": {
"closeText": "\u00e5\u2026\u00b3\u00e9\u2014\u00ad",
"prevText": "&#x3c;\u00e4\u00b8\u0160\u00e6\u0153\u02c6",
"nextText": "\u00e4\u00b8\u2039\u00e6\u0153\u02c6&#x3e;",
"currentText": "\u00e4\u00bb\u0160\u00e5\u00a4\u00a9",
"weekHeader": "\u00e5\u2018\u00a8",
"dateFormat": "d"
},
"zh-HK": {
"closeText": "\u00e9\u2014\u0153\u00e9\u2013\u2030",
"prevText": "&#x3c;\u00e4\u00b8\u0160\u00e6\u0153\u02c6",
"nextText": "\u00e4\u00b8\u2039\u00e6\u0153\u02c6&#x3e;",
"currentText": "\u00e4\u00bb\u0160\u00e5\u00a4\u00a9",
"weekHeader": "\u00e5\u2018\u00a8",
"dateFormat": "d"
}
};
$.each( regions, function( name, value ) {
var culture = Globalize.findClosestCulture( name );
Globalize.addCultureInfo( culture && culture.name || name, {
messages : {
datepicker : value
}
});
});

30
tests/unit/date/all.html Normal file
View File

@ -0,0 +1,30 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Date Test Suite</title>
<script src="../../../jquery-1.10.2.js"></script>
<link rel="stylesheet" href="../../../external/qunit.css">
<link rel="stylesheet" href="../qunit-composite.css">
<script src="../../../external/qunit.js"></script>
<script src="../qunit-composite.js"></script>
<script src="../subsuite.js"></script>
<script>
testAllVersions( "date" );
</script>
</head>
<body>
<h1 id="qunit-header">jQuery UI Datepicker Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
</div>
</body>
</html>

40
tests/unit/date/date.html Normal file
View File

@ -0,0 +1,40 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Date Test Suite</title>
<script src="../../jquery.js"></script>
<link rel="stylesheet" href="../../../external/qunit.css">
<script src="../../../external/qunit.js"></script>
<script src="../../jquery.simulate.js"></script>
<script src="../testsuite.js"></script>
<script>
TestHelpers.loadResources({
js: [
"external/date.js",
"external/globalize.js",
"external/globalize.culture.de-DE.js"
]
});
</script>
<script src="date_core.js"></script>
<script src="../swarminject.js"></script>
</head>
<body>
<h1 id="qunit-header">jQuery UI Date Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<div><input type="text" id="inp"><input type="text" id="alt"><div id="inl"></div></div>
<p><input type="text" id="inp2"></p>
</div>
</body>
</html>

View File

@ -0,0 +1,223 @@
var PROP_NAME = 'date';
module('date: core');
test('Check Date Setup', 2, function(){
ok(true,'First Test Always Passes');
ok($.date(), 'Load JQuery Date');
});
test('Check Sets and Gets', 6, function(){
var date = $.date();
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');
});
test('Date Adjustments - Normal Use Cases', 10, function(){
var date = $.date();
//Use October 15, 2012
date.setFullDate(2012,9,15);
equal(date.adjust('D',1).day(),16,'Add 1 day');
equal(date.adjust('D',-1).day(),15,'Subtract 1 day');
equal(date.adjust('M',1).month(),10,'Add 1 month');
equal(date.adjust('M',-1).month(),9,'Subtract 1 month');
equal(date.adjust('Y',1).year(),2013,'Add 1 year');
equal(date.adjust('Y',-1).year(),2012,'Subtract 1 year');
//Check changing one value impact another. Ex: Day impacts month
//Use April 30th 2012
date.setFullDate(2012,3,30);
equal(date.adjust('D',1).month(),4,'Add 1 day to change month from April to May');
equal(date.adjust('D',-1).month(),3,'Subtract 1 day to change month from May to April');
//Use December 31st 2012
date.setFullDate(2012,11,31);
equal(date.adjust('D',1).year(),2013,'Add 1 day to change year from 2012 to 2013');
equal(date.adjust('D',-1).year(),2012,'Subtract 1 day to change month from 2013 to 2012');
});
test('Date Adjustments - Month Overflow Edge Cases', 2, function(){
var date = $.date();
//Use May 31 2012
date.setFullDate(2012,4,31);
equal(date.adjust('M',1).day(),30,'Add 1 month from May to June sets days to 30, last day in June (prevent Overflow)');
equal(date.adjust('M',-1).day(),30,'Subtract 1 month from June to May sets days to 30 in May');
});
test('Date Adjustments - Leap Year Edge Cases', 1, function(){
var date = $.date();
//Use February 29 2012 a Leap year
date.setFullDate(2012,1,29);
equal(date.adjust('Y',1).day(),28,'Feb 29 2012, add a year to convert to Feb 28, 2013');
});
test('List days of Week', 2, function(){
var date = $.date();
var offset0 = [
{ 'fullname': 'Sunday', 'shortname': 'Su' },
{ 'fullname': 'Monday', 'shortname': 'Mo' },
{ 'fullname': 'Tuesday', 'shortname': 'Tu' },
{ 'fullname': 'Wednesday', 'shortname': 'We' },
{ 'fullname': 'Thursday', 'shortname': 'Th' },
{ 'fullname': 'Friday', 'shortname': 'Fr' },
{ 'fullname': 'Saturday', 'shortname': 'Sa' } ];
var offset1 = [
{ 'fullname': 'Montag', 'shortname': 'Mo' },
{ 'fullname': 'Dienstag', 'shortname': 'Di' },
{ 'fullname': 'Mittwoch', 'shortname': 'Mi' },
{ 'fullname': 'Donnerstag', 'shortname': 'Do' },
{ 'fullname': 'Freitag', 'shortname': 'Fr' },
{ 'fullname': 'Samstag', 'shortname': 'Sa' },
{ 'fullname': 'Sonntag', 'shortname': 'So' } ];
deepEqual(date.weekdays(), offset0, 'Get weekdays with start of day on 0 (English)');
Globalize.culture( 'de-DE' );
date.refresh();
deepEqual(date.weekdays(), offset1, 'Get weekdays with start of day on 1 (Germany)');
//Revert Globalize changes back to English
Globalize.culture('en-EN');
});
test('Leap Year Check', 8, function(){
var date = $.date();
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 = $.date();
date.setFullDate( 2012, 1, 1 );
equal(date.daysInMonth(), 29, 'Leap Year implicit check for 29 days');
equal(date.daysInMonth( 2012, 1 ), 29, 'Leap Year explicit check for 29 days');
equal(date.daysInMonth( 2011, 3 ), 30, 'April has 30 days');
});
test('Month Name', 2, function(){
var date = $.date();
equal(date.setMonth(3).monthName(), 'April', 'Month name return April (English)');
Globalize.culture( 'de-DE' );
date.refresh();
equal(date.setMonth(2).monthName(), 'März', 'Month name return March (German)');
Globalize.culture('en-EN');
});
test('Clone', 2, function(){
var date = $.date();
var date2 = date.clone();
ok(date2, 'Created cloned object');
notEqual(date.adjust('Y',1).year(), date2.year(), 'Object manipulated independently');
});
test('Days', 1, function(){
//TODO needs work
var date = $.date();
date.eachDay = function( day ) {
if ( day.lead && day.date > 20 ) {
day.selectable = false;
day.render = true;
day.title = "These are the days of last month";
day.extraClasses = "ui-state-disabled";
}
if ( day.lead && day.date < 3 ) {
day.selectable = true;
day.render = true;
day.extraClasses = "ui-state-disabled";
}
if ( day.date == 1 ) {
day.extraClasses = "ui-state-error";
day.title = "Something bad explaining the error highlight";
}
if ( day.today ) {
day.title = "A good day!";
}
};
ok(date.days(), 'Date days() returns');
});
test( "Months", 5, function(){
var date = $.date(),
firstMonth = date.months( 1 )[ 0 ],
lastMonth = date.months( 1 )[ 1 ];
ok( firstMonth.first );
ok( !lastMonth.first );
ok( lastMonth.last );
ok( !lastMonth.first );
ok( firstMonth.month() == ( lastMonth.month() - 1 ) );
});
test('iso8601Week', 2, function(){
var date = $.date();
//date.setFullDate(2012, 0, 8);
equal(date.iso8601Week(new Date(2012, 0, 8)), 1, 'Test first week is 1');
equal(date.iso8601Week(new Date(2012, 11, 31)), 1, 'Test last week is 1 in next year');
});
test('Equal', 4, function(){
var date = $.date();
date.setFullDate(2012, 9, 16);
ok(date.equal(new Date(2012, 9, 16)), 'Does date equal provide date');
ok(!date.equal(new Date(2011, 9, 16)), 'Does date year not equal provide date');
ok(!date.equal(new Date(2012, 8, 16)), 'Does date month not equal provide date');
ok(!date.equal(new Date(2012, 9, 15)), 'Does date day not equal provide date');
});
test('Date', 1, function(){
var date = $.date();
ok(date.date() instanceof Date, 'Date returned');
});
test('Format', 4, function(){
var date = $.date();
date.setFullDate(2012, 9, 16);
equal(date.format(), '10/16/2012', 'Checking default US format');
equal(date.format('yyyy/MM/dd'), '2012/10/16', 'Checking yyyy/MM/dd format');
equal(date.format('yy/dd/MM'), '12/16/10', 'Checking yy/dd/MM format');
equal(date.format('MMMM dd, yyyy'), 'October 16, 2012', 'Checking MMMM dd, yyyy format');
});
test('Calendar', 3, function(){
var date = $.date();
ok(date.calendar(), 'Calendar type returned')
var de_cal = {calendars: {
standard: {
"/": ".",
firstDay: 1,
days: {
names: ["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],
namesAbbr: ["So","Mo","Di","Mi","Do","Fr","Sa"],
namesShort: ["So","Mo","Di","Mi","Do","Fr","Sa"]
},
months: {
names: ["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember",""],
namesAbbr: ["Jan","Feb","Mrz","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez",""]
},
AM: null,
PM: null,
eras: [{"name":"n. Chr.","start":null,"offset":0}],
patterns: {
d: "dd.MM.yyyy",
D: "dddd, d. MMMM yyyy",
t: "HH:mm",
T: "HH:mm:ss",
f: "dddd, d. MMMM yyyy HH:mm",
F: "dddd, d. MMMM yyyy HH:mm:ss",
M: "dd MMMM",
Y: "MMMM yyyy"
}
}
}};
ok(date.calendar(de_cal), 'Calendar type changed');
deepEqual(date.calendar(), de_cal, 'Calendar change verified');
});

View File

@ -21,8 +21,13 @@
.ui-datepicker .ui-datepicker-next {
position: absolute;
top: 2px;
width: 1.8em;
height: 1.8em;
width: 19px;
height: 18px;
}
.ui-datepicker .ui-datepicker-prev:not(.ui-state-hover):not(.ui-state-focus),
.ui-datepicker .ui-datepicker-next:not(.ui-state-hover):not(.ui-state-focus) {
background: none;
border: none;
}
.ui-datepicker .ui-datepicker-prev-hover,
.ui-datepicker .ui-datepicker-next-hover {
@ -40,8 +45,8 @@
.ui-datepicker .ui-datepicker-next-hover {
right: 1px;
}
.ui-datepicker .ui-datepicker-prev span,
.ui-datepicker .ui-datepicker-next span {
.ui-datepicker .ui-datepicker-prev .ui-icon,
.ui-datepicker .ui-datepicker-next .ui-icon {
display: block;
position: absolute;
left: 50%;

File diff suppressed because it is too large Load Diff