def timeWindowMod(runtimeWindow, alternative, computeOptions):
	originalRTW = computeOptions.getRunTimeWindow()
	
	dssFile = DSS.open(computeOptions.getDssFilename(), originalRTW.getTimeWindowString())
	# pathname for breaches
	twmTSM = TimeSeriesMath(alternative.getTimeSeries()) # assumes this is the mapped input to TWM
	twmPath = twmTSM.getPath().split("/") # use this for e/f parts
	breachPath = "/".join(["", "","BREACHTRACKER-TIMESTEPS REMAINING","TIMESTEPS REMAINING","",twmPath[5], twmPath[6], ""])

	# find start and end of breach timeseries
	breaches = dssFile.read(breachPath)
	dssFile.done()
	breachTSC = breaches.getData()
	
	start, end = None, None
	rtwStart = runtimeWindow.getStartTime().value()
	newStart = HecTime() # keep track of start time that is a valid ResSim timestep
	for t,v in zip(breachTSC.times, breachTSC.values):
		if v > 0:
			if start is None: # first non-zero
				start = t
			end = t
		# update until original start time occurs, make sure this is prev. timestep in ResSim
		# avoids interpolated input on start timestep in RAS
		if t <= rtwStart:
			newStart.set(t)

	# no breach
	if start is None: 
		runtimeWindow.setStartTime(newStart)
		return runtimeWindow

	# compare and adjust if needed
	startTime = HecTime()
	startTime.set(start)
	startTime.subtractDays(RAS_START_BUFFER) # add days to give RAS a little spin up time
	if startTime <= runtimeWindow.getStartTime():
		runtimeWindow.setStartTime(startTime)
		
	endTime = HecTime()
	endTime.set(end)
	endTime.addDays(RAS_END_BUFFER) # buffer at end
	if endTime >= runtimeWindow.getEndTime():
		runtimeWindow.setEndTime(endTime)

	alternative.addComputeMessage("New time window set: %s" % runtimeWindow.getTimeWindowString())
	
	return runtimeWindow
#Use ListSelection to open manual data entry dialog and save to mydb.dss

from hec.script import Plot, MessageBox
# from hec.io import TimeSeriesContainer
# from hec.io import PairedDataContainer
# from hec.hecmath import TimeSeriesMath
# from hec.hecmath import PairedDataMath
from hec.heclib.dss import HecDss, DSSPathname
from hec.dssgui import ListSelection
from hec.heclib.util import HecTime
import java
import sys

mw = ListSelection.getMainWindow()
mw.setIsInteractive(1, 0)  # Turn off popups
mw.open(sys.argv[1] + "\\mydb.dss")

time = HecTime()
time.setCurrent()
time.setTime("0800")
time.addDays(-5)

mw.timeSeriesDataEntry("/GREEN/OAK/FLOW//1DAY/OBS", time.dateAndTime(4))
# mw.finish()  # Batch mode only