chrono.Time - Main class for time handling

class chrono.Time(time=None, **kwargs)

A class for time handling. For general usage, see the description of chrono.Date in the Usage section, which works in much the same way as chrono.Time.

Valid values for time can be:

  • string: parses time from a string, see chrono.parser.ISOParser for valid formats
  • True: sets the time to the current time
  • chrono.Time: sets time from another Time object
  • datetime.datetime: sets time from a datetime.datetime object
  • datetime.time: sets time from a datetime.time object
  • time.struct_time: sets time from a time.struct_time object
  • None: creates a time with empty attributes
  • False: creates a time with empty attributes

The class can also be instantiated using the keyword arguments hour, minute, and second:

Time(hour=16, minute=27, second=43)

If both time and keywords are specified, time takes precedence.

assert_set()

Makes sure the object has a full time set, ie the attributes chrono.Time.hour, chrono.Time.minute, and chrono.Time.second are not None.

Raises chrono.error.NoDateTimeError on missing attributes.

clear()
Clears the time, by setting chrono.Time.hour, chrono.Time.minute and chrono.Time.second to None.
format(template)

Formats the time using template, replacing variables as supported by chrono.formatter.Formatter.

Raises chrono.error.NoDateTimeError on missing time data.

get()

Returns the time as a tuple of hour, minute, and second.

Raises chrono.error.NoDateTimeError on missing time data.

get_datetime()

Returns a datetime.time instance based on the time.

Raises chrono.error.NoDateTimeError on missing time data.

get_string()

Returns a string represenation (hh:mm:ss) of the time.

Raises chrono.error.NoDateTimeError on missing time data.

is_set()
Returns True if a time is set, ie if the attributes chrono.Time.hour, chrono.Time.minute and chrono.Time.second are not None. Otherwise returns False.
set(hour, minute, second)

Sets the time.

Raises chrono.error.HourError, chrono.error.MinuteError, or chrono.error.SecondError for invalid values.

set_datetime(datetime)
Sets the time from a datetime.time or datetime.datetime object.
set_now()
Sets the time to the current time.
set_string(string)

Sets the time from a string. For valid formats, see the chrono.parser.ISOParser documentation.

Raises chrono.error.ParseError for invalid input format, TypeError for invalid input type, and chrono.error.HourError, chrono.error.MinuteError, or chrono.error.SecondError for invalid time values.

set_struct_time(struct_time)
Sets the time from a time.struct_time (as returned by various Python functions).
hour
Hour, range 0-23
minute
Minute, range 0-59
second
Second, range 0-59

Previous topic

chrono.DateTime - Main class for datetime handling

Next topic

chrono.calendar - Calendar-related classes