jquery ui datepicker changing date based on time of day -
i working on store friend. specific shipping standards need datepicker follow. deliver on monday, wednesday, , friday. also, @ 12pm on each of these days picker needs change next available date following mon. wed,. or fri. example: if 12pm on wednesday soonest select date following monday. 12pm need become unavailable friday.
i have found pieces of code should add functionality, not know how add them code use make change effective.
here current code:
jquery(function() { jquery("#date").datepicker( { beforeshowday: nonworkingdates, numberofmonths: 1, mindate: +2, maxdate: '+6m', firstday: 1 }); function nonworkingdates(date){ var day = date.getday(), sunday = 0, monday = 1, tuesday = 2, wednesday = 3, thursday = 4, friday = 5, saturday = 6; var closeddates = [[7, 29, 2009], [8, 25, 2010]]; var closeddays = [[tuesday], [thursday], [saturday], [sunday]]; (var = 0; < closeddays.length; i++) { if (day == closeddays[i][0]) { return [false]; } } (i = 0; < closeddates.length; i++) { if (date.getmonth() == closeddates[i][0] - 1 && date.getdate() == closeddates[i][1] && date.getfullyear() == closeddates[i][2]) { return [false]; } } return [true]; } ]); please explain possible. code noob. can copy , paste specific place ideal.
basically, need determine if date passed in next delivery day. if is, , it's past noon, disable date. i'm sure more experience more elegantly, came works @ least today (it's wednesday, , past noon, , blacked out friday).
jquery(function () { jquery("#date").datepicker({ beforeshowday: nonworkingdates, numberofmonths: 1, mindate: +2, maxdate: '+6m', firstday: 1 }); function nonworkingdates(date) { var day = date.getday(), sunday = 0, monday = 1, tuesday = 2, wednesday = 3, thursday = 4, friday = 5, saturday = 6; var closeddates = [ [7, 29, 2009], [8, 25, 2010] ]; var closeddays = [ [tuesday], [thursday], [saturday], [sunday] ]; (var = 0; < closeddays.length; i++) { if (day == closeddays[i][0]) { return [false]; } } (i = 0; < closeddates.length; i++) { if (date.getmonth() == closeddates[i][0] - 1 && date.getdate() == closeddates[i][1] && date.getfullyear() == closeddates[i][2]) { return [false]; } } var currentday = new date(); //if it's not past noon, don't need next check //so return true var currenthour = currentday.gethours(); if (currenthour < 12) { return [true]; } //determine if date passed in next delivery day var nextdeliveryday = 0 switch (date.getday()) { case 1: nextdeliveryday = 3; break; case 3: case 5: nextdeliveryday = 2; break; } //if date minus number of days next delivery date //equals today's date, return false var testdate = new date(date); testdate.setdate(testdate.getdate() - nextdeliveryday); //normalize time of day comparison currentday.sethours(0,0,0,0); if (testdate.gettime() == currentday.gettime()) { return[false]; } return [true]; } });
Comments
Post a Comment