chrono.Time - Main class for time handling

class chrono.Time(time=None, parser=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 using the given parser (defaults to the value of chrono.DEFAULT_PARSER, normally chrono.parser.CommonParser)
  • 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.

parser determines which parser to use for parsing times from strings. By default the value of chrono.DEFAULT_PARSER is used - normally chrono.parser.CommonParser, which supports the most common date and time formats. See chrono.parser for a list of available parsers.

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_julian()

Returns a julian time for the set time, as a float between 0 and 1.

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_julian(julian)

Sets the time from a julian time, as a float between 0 and 1. If julian is greather than 1, only the decimal part will be used.

Raises chrono.error.TimeError on invalid julian time.

set_now()
Sets the time to the current time.
set_string(string)

Sets the time from a string, parsed with the parser set in chrono.Date.parser - by default the parser set in chrono.DEFAULT_PARSER, normally chrono.parser.CommonParser.

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
parser
Parser to use for parsing times from strings. See chrono.parser for available parsers.
second
Second, range 0-59

Previous topic

chrono.DateTime - Main class for datetime handling

Next topic

chrono.calendar - Calendar-related classes