cf.TimeDuration.bounds

TimeDuration.bounds(dt, direction=True)[source]

Return a time interval containing a date-time.

The interval spans the time duration and starts and ends at date-times consistent with the time duration’s offset.

The offset of the time duration is used to modify the bounds.

Added in version 1.2.3.

See also

cf.dt, cf.Datetime, interval, offset

Parameters:
dt: date-time-like

The date-time to be contained by the interval. dt may be any date-time-like object, such as cf.Datetime, datetime.datetime, netCDF4.netcdftime.datetime, etc.

Parameter example:

To find bounds around 1999-16-1 in the Gregorian calendar you could use dt=cf.dt(1999, 1, 16) or dt=datetime.datetime(1999, 1, 16) (See cf.dt for details).

direction: bool, optional

If False then the bounds are decreasing. By default the bounds are increasing. Note that t.bounds(dt, direction=False) is equivalent to t.bounds(dt)[::-1].

Returns:
tuple

The two bounds.

Examples

>>> t = cf.M()
>>> t.bounds(cf.dt(2000, 1, 1))
(cftime.DatetimeGregorian(2000, 1, 1, 0, 0, 0, 0, has_year_zero=False),
 cftime.DatetimeGregorian(2000, 2, 1, 0, 0, 0, 0, has_year_zero=False))
>>> t = cf.M(1)
>>> t.bounds(cf.dt(2000, 3, 1))
(cftime.DatetimeGregorian(2000, 3, 1, 0, 0, 0, 0, has_year_zero=False),
 cftime.DatetimeGregorian(2000, 4, 1, 0, 0, 0, 0, has_year_zero=False))
>>> t = cf.M(1, day=15)
>>> t.bounds(cf.dt(2000, 3, 1))
(cftime.DatetimeGregorian(2000, 2, 15, 0, 0, 0, 0, has_year_zero=False),
 cftime.DatetimeGregorian(2000, 3, 15, 0, 0, 0, 0, has_year_zero=False))
>>> t = cf.M(2, day=15)
>>> t.bounds(cf.dt(2000, 3, 1), direction=False)
(cftime.DatetimeGregorian(2000, 3, 15, 0, 0, 0, 0, has_year_zero=False),
 cftime.DatetimeGregorian(2000, 1, 15, 0, 0, 0, 0, has_year_zero=False))