I was wondering if anyone wanted to demonstrate a more concise way of doing this. Returning a static date prior to an input date. I am returning the Sunday at 10:00 pm prior to any input date. Needs to work on any input date and always return the Sunday prior or if in date is sunday return that date at 10:00pm
timeIn = value
from java.util import Calendar
cal=Calendar.getInstance()
cal.set(system.date.getYear(timeIn),system.date.getMonth(timeIn),system.date.getDayOfMonth(timeIn))
cal.add( Calendar.DAY_OF_WEEK, -(cal.get(Calendar.DAY_OF_WEEK)-1))
var = system.date.getDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE))
return system.date.setTime(var,22,0,0)
from java.time import ZoneId, DayOfWeek
import java.time.temporal.TemporalAdjusters as TA
timeIn = value
# Convert to java.time.LocalDate
localDate = timeIn.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()
# Check if Sunday, else set to previous Sunday
if localDate.dayOfWeek == DayOfWeek.SUNDAY:
tempDate = localDate
else:
tempDate = localDate.with(TA.previous(DayOfWeek.SUNDAY))
#Return Parsed Date
return system.date.parse(tempDate.toString() + ' 22:00:00')