前段时间有同事问我robot上有没有办法知道指定的某个日期是星期几,当时没有想起来,后来一直忙,直到现在才空下来,有时间解决一下这个问题,关于日期推算星期几,使用到泰勒公式,;
根据 蔡勒(Zeller)公式使用robot编写出如下,供参考(未优化):
${date} Set Variable 2018-01-22
${century} Get Substring ${date} 0 2
${month} Get Substring ${date} 5 7
${yearT} Get Substring ${date} 2 4
${day} Get Substring ${date} 8 10
Comment 转换月份,如果是1、2月,月份加12
${month} set variable if '${month}'=='01' 13
... '${month}'=='02' 14 ${month}
log ${month}
${yearNew} Evaluate ${yearT}-1
${centuryT} Evaluate ${century}-1
Comment 转换年份,如果月份是1、2月,年份减一,00年则取值99
${year} Set Variable If '${month}'=='13' and '${yearT}'=='00' 99
... '${month}'=='14' and '${yearT}'=='00' 99
... '${month}'=='13' ${yearNew}
... '${month}'=='14' ${yearNew} ${yearT}
Comment 如果1、2月,且年份是00年,年份取99,世纪则减一
${century} Set Variable If '${month}'=='13' and '${yearT}'=='00' ${centuryT}
... '${month}'=='14' and '${yearT}'=='00' ${centuryT} ${century}
log ${year}
Comment 分个运算,转成整型
${day} Convert To Integer ${day}
${year4} Evaluate ${year}/4
${year4int} Convert To Integer ${year4}
${century4} Evaluate ${century}/4
${centuryNew} Convert To Integer ${century4}
${monthN} Evaluate 26 * (${month} + 1)/10
${monthNew} Convert To Integer ${monthN}
${week} Evaluate ${year}+${year4int}+${centuryNew}-2*${century}+${monthN}+${day}-1
log ${week}
Comment 如果week小于0
${weekday0} Evaluate (${week} % 7 + 7) % 7
Comment week大于0
${weekDay1} Evaluate ${week}%7
${weekday} set variable if ${week}<0 ${weekday0} ${weekDay1}
log ${date}是星期${weekday}