I have a question about javascript time ranges
i have two input boxes, the client can give start date and end date
below have 3 seasons with date ranges,i need to count the cost for the user entered date range with the mapping with below seasons with prices
Total is 3 seasons, below is the date ranges:
Low Season
1st May to 30th June 1st September to 14th December
Cost: $5 per day
High Season
11th January to 30th April 1st July to 31st August
Cost: $10 per day
Peak Season
-15th December - 10th January Cost: $2 per day
i write a code for get the date inputs
$('#calculate').click(function(){
//get the first date
da=$('#daydropdowna').val();
ma=$('#monthdropdowna').val();
ya=$('#yeardropdowna').val();
//get the secnd date
dd=$('#daydropdownd').val();
md=$('#monthdropdownd').val();
yd=$('#yeardropdownd').val();
var oneDay = 24*60*60*1000;
var ourstart= new Date(ya,ma,da);
var oursend= new Date(yd,md,dd);
/*
11th January to 30th April
1st July to 31st August
*/
var hsstart= new Date(ya,00,11);
var hsend= new Date(ya,03,11);
var hsstart1= new Date(ya,06,01);
var hsend1= new Date(ya,07,31);
/*
1st May to 30th June
1st September to 14th December
*/
var lsstart=new Date(ya,04,01);
var lsend=new Date(ya,05,30);
var lsstart1=Date(ya,08,01);
var lsend1=new Date(ya,11,14);
/*
-15th December - 10th January
*/
var psstart=new Date(ya,11,15);
var psend=new Date(ya+1,00,10);
var myDate = ourstart;
var myDate1 = oursend;
var startDate = hsstart
var endDate = hsend
//the date range within one high season
if ((startDate < myDate) && (myDate < endDate) && (startDate < myDate1) && (myDate1 < endDate)) {
alert('seasn 1 h');
var diffDays = Math.round(Math.abs((myDate1 .getTime() - myDate .getTime())/(oneDay)));
alert (diffDays);
}
//the date range within secnd high season
var startDate = hsstart1
var endDate = hsend1
if ((startDate < myDate) && (myDate < endDate) && (startDate < myDate1) && (myDate1 < endDate)) {
alert('seasn 2 h');
var diffDays = Math.round(Math.abs((myDate1 .getTime() - myDate .getTime())/(oneDay)));
alert (diffDays);
}
//the date range within first low season
var startDate = lsstart
var endDate = lsend
if ((startDate < myDate) && (myDate < endDate) && (startDate < myDate1) && (myDate1 < endDate)) {
alert('season 1 l');
var diffDays = Math.round(Math.abs((myDate1 .getTime() - myDate .getTime())/(oneDay)));
alert (diffDays);
}
//the date range within second low season
var startDate = lsstart1
var endDate = lsend1
if ((startDate < myDate) && (myDate < endDate) && (startDate < myDate1) && (myDate1 < endDate)) {
alert('season 2 l');
var diffDays = Math.round(Math.abs((myDate1 .getTime() - myDate .getTime())/(oneDay)));
alert (diffDays);
}
//peak
var startDate = psstart
var endDate = psend
if ((startDate < myDate) && (myDate < endDate) && (startDate < myDate1) && (myDate1 < endDate)) {
alert('season p');
var diffDays = Math.round(Math.abs((myDate1 .getTime() - myDate .getTime())/(oneDay)));
alert (diffDays);
}
//if not wihin a specific range cacuate for all
});
so i need to calculate the total price according to the user input, Ex user enters 2012-05-05 - 2013-01-05 this need to calculate price for 3 season dates which is covering the date range. please hep me for solve this problem, thank you...