Time Module
This module provides advanced time handling utilities with extended support for time zones, localization, and time-based operations.
Classes
TimeFormat
- class true.time.TimeFormat(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumEnum for different time formats.
An enumeration for different time formats.
HOUR_12: 12-hour format
HOUR_24: 24-hour format
ISO: ISO format
CUSTOM: Custom format
- HOUR_12 = '12'
- HOUR_24 = '24'
- ISO = 'iso'
- CUSTOM = 'custom'
TimeUnit
- class true.time.TimeUnit(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumEnum for time units.
An enumeration for time units.
MILLISECONDS: Milliseconds unit
SECONDS: Seconds unit
MINUTES: Minutes unit
HOURS: Hours unit
DAYS: Days unit
WEEKS: Weeks unit
MONTHS: Months unit
YEARS: Years unit
- MILLISECONDS = 'milliseconds'
- SECONDS = 'seconds'
- MINUTES = 'minutes'
- HOURS = 'hours'
- DAYS = 'days'
- WEEKS = 'weeks'
- MONTHS = 'months'
- YEARS = 'years'
TimeConfig
- class true.time.TimeConfig(default_timezone='UTC', default_format=TimeFormat.HOUR_24, date_separator='-', time_separator=':', datetime_separator=' ')[source]
Bases:
objectConfiguration class for Time settings.
Configuration class for Time settings.
- Parameters:
default_timezone – Default timezone (default: “UTC”)
default_format – Default time format (default: TimeFormat.HOUR_24)
date_separator – Separator for date components (default: “-“)
time_separator – Separator for time components (default: “:”)
datetime_separator – Separator between date and time (default: “ “)
-
default_format:
TimeFormat= '24'
- __init__(default_timezone='UTC', default_format=TimeFormat.HOUR_24, date_separator='-', time_separator=':', datetime_separator=' ')
Time
- class true.time.Time(time_input=None, timezone_name=None, config=None)[source]
Bases:
objectAdvanced Time handling class with localization support and extended functionality.
Advanced Time handling class with localization support and extended functionality.
Key Features:
Time rounding, flooring, and ceiling based on time units
Time difference calculations with specified units
Conversion to different time zones
Flexible formatting with locale support
Support for checking if a time instance is within DST
Serialization to dictionary format
- is_between(start, end, inclusive=True)[source]
Check if time is between start and end times.
- Return type:
- with_timezone(timezone_name)[source]
Return new Time instance with different timezone.
- Return type:
- with_time(hour=0, minute=0, second=0, microsecond=0)[source]
Return new Time instance with specified time components.
- Return type:
- with_date(year=None, month=None, day=None)[source]
Return new Time instance with specified date components.
- Return type:
- static _parse_input(time_input)[source]
Parse various input formats to a datetime object.
- Return type:
- format(format_type=TimeFormat.HOUR_24, custom_format=None, locale_name=None)[source]
Format time according to specified format and locale.
- difference(other, unit=TimeUnit.SECONDS)[source]
Calculate time difference in specified unit.
- Return type:
- _add_months(months)[source]
Helper method to calculate the timedelta for adding months.
- Return type:
Event
- class true.time.Event(name, start_time, end_time, description=None, recurrence=None, tags=None, priority=0, metadata=None)[source]
Bases:
objectRepresents a scheduled event with comprehensive time management capabilities.
Represents a scheduled event with comprehensive time management capabilities.
- Parameters:
name – Event name
start_time – Event start time
end_time – Event end time
description – Optional event description
recurrence – Optional recurrence pattern
tags – Optional list of tags
priority – Event priority (default: 0)
metadata – Optional metadata dictionary
- __init__(name, start_time, end_time, description=None, recurrence=None, tags=None, priority=0, metadata=None)
Schedule
- class true.time.Schedule(timezone_name=None)[source]
Bases:
objectAdvanced scheduling system with support for complex time-based operations.
Features: - Event management (add, remove, update) - Conflict detection and resolution - Recurring events support - Event filtering and searching - Schedule optimization - Time block allocation - Schedule statistics and analytics
Advanced scheduling system with support for complex time-based operations.
Features:
Event management (add, remove, update)
Conflict detection and resolution
Recurring events support
Event filtering and searching
Schedule optimization
Time block allocation
Schedule statistics and analytics
- add_event(event, check_conflicts=True)[source]
Add an event to the schedule with optional conflict checking.
- Return type:
- update_event(event_name, **kwargs)[source]
Update an existing event with new attributes.
- Return type:
- get_events(start, end, tags=None, priority_min=None)[source]
Get events within a time range with optional filtering.
- find_free_slots(start, end, duration, unit=TimeUnit.MINUTES)[source]
Find available time slots of specified duration.
Functions
timeout
- true.time.timeout(timeout_)[source]
Decorator that raises TimeoutError if function execution exceeds specified timeout in seconds.
Decorator that raises TimeoutError if function execution exceeds specified timeout in seconds.
- Parameters:
timeout – Maximum execution time in seconds
- Raises:
TimeoutError if execution time exceeds the specified timeout
timer
- true.time.timer(func, per_counter=False)[source]
Decorator that measures and prints function execution time.
Decorator that measures and prints function execution time.
- Parameters:
per_counter – Use performance counter for higher precision if True
- Returns:
Wrapped function that prints execution time