I have a stax doc with some embedded scripting to check if today’s day is a Wed or Sat, after initial formatting the correct day is printed to screen but in the find() method “Wed” is always printed to screen, even on a Sat. Is there a better way to do this compare?
jython code can be run within the script
import java.util.Date
import java.util.Calendar
import java.text.SimpleDateFormat
now = java.util.Date()
dayFormat = java.text.SimpleDateFormat('EEE')
cal = java.util.Calendar.getInstance();
cal.setTime(now);
cal.add(java.util.Calendar.HOUR, 5);
dayBeforeFormat = cal.getTime();
day = str(dayFormat.format(dayBeforeFormat))
print(day)
if day.find('Sat'):
print('Sat')
elif day.find('Wed'):
print('Wed')
When the code runs on a Saturday, the value of
dayis “Sat” and this bit:returns 0. This is the lowest index in the
daystring where the substring “Sat” is found. See http://www.jython.org/docs/library/stdtypes.html#string-methods.0 is equivalent to boolean
False.This will work:
Or simpler: