Forum Discussion

sarya's avatar
sarya
Frequent Contributor
14 years ago

How to calculate difference in date values in months from different years.


Hi,



I made this script to work on calendar image on the website that I am testing.The only option to scroll through months are the two tabs that go left and right.It works fine but it is not taking into account all the cases.For example- If i need to choose feb2010 and current display shows march 2011 ,it is not going to feb2010 as the difference between the months is 1 and it just goes one month back because of my script. I want to make some changes but I am not sure of how to make script run in thsi situation.Also the date functions in testcomplete don't calcualte the difference so that script goes back to that many number of times.I am also attaching the calendar image that is being used. 



function
clickDate(date,format,page,monthNum) //Click the date on calendar


clickDate(date,format,page,monthNum)

{


b = aqDateTime.GetYear(r2wdate);


c = aqDateTime.GetMonth(r2wdate);


d = aqDateTime.GetDay(r2wdate);


monthNum = aqConvert.IntToStr(monthNum);


if (c < monthNum)


{


counter = aqConvert.IntToStr(c);


for (i =1;i <=counter;i++)


{


page.NativeWebObject.Find("title","Previous month","IMG").Click();


}


var date1 = page.NativeWebObject.Find("innerText",date);


values = date1.parent.FindAll("innerText",date);


values = VBArray(values).toArray();


for (var i=0; i<values.length; i++)


{


if (values.outerHTML.indexOf(format) != -1)


{value = values;break}


}


value.Click();


}


else


{


counter = aqConvert.IntToStr(c-monthNum) ;


for (i =1;i <=counter;i++)


{


page.NativeWebObject.Find("title","Previous month","IMG").Click();


}


var date1 = page.NativeWebObject.Find("innerText",date);


values = date1.parent.FindAll("innerText",date);


values = VBArray(values).toArray();


for (var i=0; i<values.length; i++)


{


if (values.outerHTML.indexOf(format) != -1)


{value = values;break}


}


value.Click();


}


}



Thanks,

Sumedha