String/Date functions 2 (WinRunner, TSL)
Parent page: Service Functions – String / WinRunner
Date to Dictionary
public function str_date_split(in date, inout dtVector[]) {
delete dtVector[];
date = str_date_align(date);
dtVector["month"] = substr(date,1,2);
dtVector["day"] = substr(date,4,2);
dtVector["year"] = substr(date,7,4);
}
Date comparison
# suppose dates are aligned
# format is mm/dd/yyyy
public function str_date_compare(in date1, in date2) {
auto dtDate1[], dtDate2[];
if (date1 == date2)
return(0);
str_date_split(date1, dtDate1);
str_date_split(date2, dtDate2);
# Year level
if (dtDate1["year"] > dtDate2["year"])
return(1);
if (dtDate1["year"] < dtDate2["year"])
return(-1);
# Month level
if (dtDate1["month"] > dtDate2["month"])
return(1);
if (dtDate1["month"] < dtDate2["month"])
return(-1);
# Day level
if (dtDate1["day"] > dtDate2["day"])
return(1);
if (dtDate1["day"] < dtDate2["day"])
return(-1);
return(0);
}
###
public function str_date_belongs(in date, in date_min, in date_max) {
auto rc;
rc = str_date_compare(date_min, date);
if (rc == 1) return(FALSE);
rc = str_date_compare(date, date_max);
if (rc == 1) return(FALSE);
return(TRUE);
}

