addTime - noetl/noetl GitHub Wiki

addTime

E.g. cursorList = addTime("201501", "201505", 2, "m", "%Y%m")

Parameters

  • strDate1: 1st date
  • strDate2: 2nd date
  • increment: Numeric increment value
  • incType: Increment type: "y", "m", "d" (year, month, day)
  • dateFormat: default value = "%Y%m"; format of strDate1 and strDate2 parameters

Key Variables

  • date1: datetime object representing strDate1
  • date2: datetime object representing strDate2
  • currentCursor: list of cursor dates from the expanded range between date1 and date2
  • timeDelta: timedelta object representing the increment in time

Functionality

  • StrDate1 and strDate2 are converted into datetime objects using the dateFormat passed in, and a timeDelta object is created using the increment.
  • While date1 is less than date2, date1 is appended to the currentCursor list and date1 is updated.
  • If incType is year, date1 is set to a new datetime object with the same month and day as the previous date1, but the increment is added to the year.
  • Else if incType is month, date1 is set to a new datetime object. The year is the previous date1 year plus the floored output of the month added with the increment. The month is updated to the modulus of the previous date1 month plus the increment. The day is the same as the previous date1 day.
  • Else if incType is day, date1 is simply set equal to the previous date1 plus the timeDelta object that represents the increment in days.

Except Statement

If there is an error, the date and time, and the error message are printed to the console.

Return Value

Returns currentCursor.