Hour

when_exactly.Hour dataclass

Bases: when_exactly.core.custom_interval.CustomInterval

Represents a single hour, from :00 to :00 the next hour.

An Hour is a 60-minute interval. Hours are numbered from 0 to 23.

Attributes:

Name Type Description
start when_exactly.core.moment.Moment

The moment at the start of the hour (inclusive).

stop when_exactly.core.moment.Moment

The moment at the start of the next hour (exclusive).

Example
>>> import when_exactly as wnx
>>> hour = wnx.Hour(2020, 1, 1, 0)
>>> hour
Hour(2020, 1, 1, 0)
>>> str(hour)
'2020-01-01T00'
>>> hour.next
Hour(2020, 1, 1, 1)
>>> hour.minute(30)
Minute(2020, 1, 1, 0, 30)
>>> len(list(hour.minutes()))
60

next property

The next hour.

previous property

The previous hour.

__init__(year, month, day, hour)

Create an Hour from year, month, day, and hour.

Parameters:

Name Type Description Default
year int

The year.

required
month int

The month (1-12).

required
day int

The day of month.

required
hour int

The hour (0-23).

required

Returns:

Type Description
None

An Hour interval.

__repr__()

Return the canonical string representation of the hour.

__str__()

Return the ISO 8601 string representation of the hour.

day()

Get the day containing this hour.

Returns:

Type Description
when_exactly._api.Day

The Day containing this hour.

Example
>>> import when_exactly as wnx
>>> hour = wnx.Hour(2020, 1, 1, 0)
>>> hour.day()
Day(2020, 1, 1)

from_moment(moment) classmethod

Create an Hour from a Moment.

Parameters:

Name Type Description Default
moment when_exactly.core.moment.Moment

The moment to extract the hour from.

required

Returns:

Type Description
when_exactly._api.Hour

The Hour containing the moment.

Example
>>> import when_exactly as wnx
>>> moment = wnx.Moment(2020, 1, 1, 15, 30, 0)
>>> wnx.Hour.from_moment(moment)
Hour(2020, 1, 1, 15)

minute(minute)

Get a specific minute of the hour.

Parameters:

Name Type Description Default
minute int

The minute (0-59).

required

Returns:

Type Description
when_exactly._api.Minute

The Minute for the specified minute.

Example
>>> import when_exactly as wnx
>>> hour = wnx.Hour(2020, 1, 1, 0)
>>> hour.minute(30)
Minute(2020, 1, 1, 0, 30)

minutes()

Generate all 60 minutes in this hour.

Returns:

Type Description
typing.Iterable[when_exactly._api.Minute]

An iterable of Minute objects from :00 to :59.

Example
>>> import when_exactly as wnx
>>> hour = wnx.Hour(2020, 1, 1, 0)
>>> minutes = list(hour.minutes())
>>> len(minutes)
60
>>> minutes[0]
Minute(2020, 1, 1, 0, 0)