Return static date prior to input date. Script

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)

Pretty much the same as your logic but sticks to using only the system.date functions:

timeIn = value
timeInDayOfWeek = system.date.getDayOfWeek(timeIn)
sundayWrongTime = system.date.addDays(timeIn, -(timeInDayOfWeek-1))
return system.date.setTime(sundayWrongTime, 22, 0, 0)

I prefer the above option but you could reduce it down to 2 lines of code while maintaining readability:

from system.date import setTime, addDays, getDayOfWeek
return setTime(addDays(value, -(getDayOfWeek(value)-1)), 22, 0, 0)

I use java.time for this:

	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')

@WillMT10 iI was wondering how to do this with the system.time functions. I feel silly for not figuring out now lol

@JordanCClark Thanks for that I am learning Temporal Adjusters right now. Super handy.