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.add( Calendar.DAY_OF_WEEK, -(cal.get(Calendar.DAY_OF_WEEK)-1))
	var =, cal.get(Calendar.MONTH), cal.get(Calendar.DATE))

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

timeIn = value
timeInDayOfWeek =
sundayWrongTime =, -(timeInDayOfWeek-1))
return, 22, 0, 0)

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

from 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
		tempDate = localDate.with(TA.previous(DayOfWeek.SUNDAY))

	#Return Parsed Date	
	return + ' 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.