Possibly increment or decrement the number of periods to shift based on rollforward/rollbackward conventions. Parameters ---------- other : cftime.datetime n : number of periods to increment, before adjusting for rolling month : int reference month giving the first month of
(
other, n: int, month: int, day_option: DayOption, modby: int = 3
)
| 317 | |
| 318 | |
| 319 | def roll_qtrday( |
| 320 | other, n: int, month: int, day_option: DayOption, modby: int = 3 |
| 321 | ) -> int: |
| 322 | """Possibly increment or decrement the number of periods to shift |
| 323 | based on rollforward/rollbackward conventions. |
| 324 | |
| 325 | Parameters |
| 326 | ---------- |
| 327 | other : cftime.datetime |
| 328 | n : number of periods to increment, before adjusting for rolling |
| 329 | month : int reference month giving the first month of the year |
| 330 | day_option : 'start', 'end' |
| 331 | The convention to use in finding the day in a given month against |
| 332 | which to compare for rollforward/rollbackward decisions. |
| 333 | modby : int 3 for quarters, 12 for years |
| 334 | |
| 335 | Returns |
| 336 | ------- |
| 337 | n : int number of periods to increment |
| 338 | |
| 339 | See Also |
| 340 | -------- |
| 341 | _get_day_of_month : Find the day in a month provided an offset. |
| 342 | """ |
| 343 | |
| 344 | months_since = other.month % modby - month % modby |
| 345 | |
| 346 | if n > 0: |
| 347 | if months_since < 0 or ( |
| 348 | months_since == 0 and other.day < _get_day_of_month(other, day_option) |
| 349 | ): |
| 350 | # pretend to roll back if on same month but |
| 351 | # before compare_day |
| 352 | n -= 1 |
| 353 | elif months_since > 0 or ( |
| 354 | months_since == 0 and other.day > _get_day_of_month(other, day_option) |
| 355 | ): |
| 356 | # make sure to roll forward, so negate |
| 357 | n += 1 |
| 358 | return n |
| 359 | |
| 360 | |
| 361 | def _validate_month(month: int | None, default_month: int) -> int: |
no test coverage detected
searching dependent graphs…