def timeRange(self , start = None , end = None , interval = "1Y", extend_end = True): (num , timeUnit) = TimeVector.parseTimeUnit( interval ) if start is None: start = self.getDataStartTime( ) if isinstance(start , datetime.date): start = datetime.datetime( start.year , start.month , start.day , 0 , 0 , 0 ) if end is None: end = self.end_time if isinstance(end , datetime.date): end = datetime.datetime( end.year , end.month , end.day , 0 , 0 , 0 ) if end < start: raise ValueError("Invalid time interval start after end") if not timeUnit == "d": year1 = start.year year2 = end.year month1 = start.month month2 = end.month day1 = start.day day2 = end.day if extend_end: if timeUnit == 'm': if day2 > 1: month2 += 1 if month2 == 13: year2 += 1 month2 = 1 elif timeUnit == "y": month1 = 1 if year2 > 1 or day2 > 1: year2 += 1 month2 = 1 day1 = 1 day2 = 1 range_start = datetime.date( year1, month1 , day1) range_end = datetime.date(year2 , month2 , day2) trange = TimeVector.createRegular(range_start , range_end , interval) # If the simulation does not start at the first of the month # the start value will be before the simulation start; we # manually shift the first element in the trange to the start # value; the same for the end of list. if trange[-1] < end: if extend_end: trange.appendTime( num , timeUnit ) else: trange.append( end ) if trange[0] < start: trange[0] = CTime(start) return trange
def timeRange(self, start=None, end=None, interval="1Y", extend_end=True): (num, timeUnit) = TimeVector.parseTimeUnit(interval) if start is None: start = self.getDataStartTime() if isinstance(start, datetime.date): start = datetime.datetime(start.year, start.month, start.day, 0, 0, 0) if end is None: end = self.end_time if isinstance(end, datetime.date): end = datetime.datetime(end.year, end.month, end.day, 0, 0, 0) if end < start: raise ValueError("Invalid time interval start after end") if not timeUnit == "d": year1 = start.year year2 = end.year month1 = start.month month2 = end.month day1 = start.day day2 = end.day if extend_end: if timeUnit == 'm': if day2 > 1: month2 += 1 if month2 == 13: year2 += 1 month2 = 1 elif timeUnit == "y": month1 = 1 if year2 > 1 or day2 > 1: year2 += 1 month2 = 1 day1 = 1 day2 = 1 range_start = datetime.date(year1, month1, day1) range_end = datetime.date(year2, month2, day2) trange = TimeVector.createRegular(range_start, range_end, interval) # If the simulation does not start at the first of the month # the start value will be before the simulation start; we # manually shift the first element in the trange to the start # value; the same for the end of list. if trange[-1] < end: if extend_end: trange.appendTime(num, timeUnit) else: trange.append(end) if trange[0] < start: trange[0] = CTime(start) return trange
def timeRange(self , start = None , end = None , interval = "1Y", extend_end = True): (num , timeUnit) = TimeVector.parseTimeUnit( interval ) if start is None: start = self.getDataStartTime( ) if isinstance(start , datetime.date): start = datetime.datetime( start.year , start.month , start.day , 0 , 0 , 0 ) if end is None: end = self.end_time if isinstance(end , datetime.date): end = datetime.datetime( end.year , end.month , end.day , 0 , 0 , 0 ) if end < start: raise ValueError("Invalid time interval start after end") if not timeUnit == "d": year1 = start.year year2 = end.year month1 = start.month month2 = end.month day1 = start.day day2 = end.day if extend_end: if timeUnit == 'm': if day2 > 1: month2 += 1 if month2 == 13: year2 += 1 month2 = 1 elif timeUnit == "y": month1 = 1 if year2 > 1 or day2 > 1: year2 += 1 month2 = 1 day1 = 1 day2 = 1 start = datetime.date( year1, month1 , day1) end = datetime.date(year2 , month2 , day2) trange = TimeVector.createRegular(start , end , interval) if trange[-1] < end: if extend_end: trange.appendTime( num , timeUnit ) else: trange.append( end ) return trange
def timeRange(self , start = None , end = None , interval = "1Y", extend_end = True): (num , timeUnit) = TimeVector.parseTimeUnit( interval ) if start is None: start = self.start_time if isinstance(start , datetime.date): start = datetime.datetime( start.year , start.month , start.day , 0 , 0 , 0 ) if end is None: end = self.end_time if isinstance(end , datetime.date): end = datetime.datetime( end.year , end.month , end.day , 0 , 0 , 0 ) if end < start: raise ValueError("Invalid time interval start after end") if not timeUnit == "d": year1 = start.year year2 = end.year month1 = start.month month2 = end.month day1 = start.day day2 = end.day if extend_end: if timeUnit == 'm': if day2 > 1: month2 += 1 if month2 == 13: year2 += 1 month2 = 1 elif timeUnit == "y": month1 = 1 if year2 > 1 or day2 > 1: year2 += 1 month2 = 1 day1 = 1 day2 = 1 start = datetime.date( year1, month1 , day1) end = datetime.date(year2 , month2 , day2) trange = TimeVector.createRegular(start , end , interval) if trange[-1] < end: if extend_end: trange.appendTime( num , timeUnit ) else: trange.append( end ) return trange