chaco.scales.safetime module

This module wraps the standard library time module to gracefully handle bad input values for time.

chaco.scales.safetime.asctime([tuple])string

Convert a time tuple to a string, e.g. ‘Sat Jun 06 16:26:11 1998’. When the time tuple is not present, current time as returned by localtime() is used.

chaco.scales.safetime.clock()floating point number

Return the CPU time or real time since the start of the process or since the first call to clock(). This has as much precision as the system records.

chaco.scales.safetime.ctime(seconds)string

Convert a time in seconds since the Epoch to a string in local time. This is equivalent to asctime(localtime(seconds)). When the time tuple is not present, current time as returned by localtime() is used.

class chaco.scales.safetime.datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])

Bases: datetime.date

The year, month and day arguments are required. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be ints.

astimezone()

tz -> convert to local time in new timezone tz

combine()

date, time -> datetime with same date and time fields

ctime()

Return ctime() style string.

date()

Return date object with same year, month and day.

dst()

Return self.tzinfo.dst(self).

fold
fromtimestamp()

timestamp[, tz] -> tz’s local time from POSIX timestamp.

hour
isoformat()

[sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM]. sep is used to separate the year from the time, and defaults to ‘T’. timespec specifies what components of the time to include (allowed values are ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’, and ‘microseconds’).

max = datetime.datetime(9999, 12, 31, 23, 59, 59, 999999)
microsecond
min = datetime.datetime(1, 1, 1, 0, 0)
minute
now()

Returns new datetime object representing current time local to tz.

tz

Timezone object.

If no tz is specified, uses local timezone.

replace()

Return datetime with new specified fields.

resolution = datetime.timedelta(0, 0, 1)
second
strptime()

string, format -> new datetime parsed from a string (like time.strptime()).

time()

Return time object with same time but with tzinfo=None.

timestamp()

Return POSIX timestamp as float.

timetuple()

Return time tuple, compatible with time.localtime().

timetz()

Return time object with same time and tzinfo.

tzinfo
tzname()

Return self.tzinfo.tzname(self).

utcfromtimestamp()

Construct a naive UTC datetime from a POSIX timestamp.

utcnow()

Return a new datetime representing UTC day and time.

utcoffset()

Return self.tzinfo.utcoffset(self).

utctimetuple()

Return UTC time tuple, compatible with time.localtime().

chaco.scales.safetime.get_clock_info(name: str)dict

Get information of the specified clock.

chaco.scales.safetime.gmtime([seconds])(tm_year, tm_mon, tm_mday, tm_hour, tm_min,

tm_sec, tm_wday, tm_yday, tm_isdst)

Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a. GMT). When ‘seconds’ is not passed in, convert the current time instead.

If the platform supports the tm_gmtoff and tm_zone, they are available as attributes only.

chaco.scales.safetime.localtime([seconds]) -> (tm_year,tm_mon,tm_day,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst)

Convert seconds since the Epoch to a time tuple expressing local time. When ‘seconds’ is not passed in, convert the current time instead.

Modified to accept timestamps before the Epoch.

chaco.scales.safetime.mktime(tuple)floating point number

Convert a time tuple in local time to seconds since the Epoch. Invalid time tuples will be assigned the value 0.0 and a warning will be issued.

chaco.scales.safetime.monotonic()float

Monotonic clock, cannot go backward.

chaco.scales.safetime.perf_counter()float

Performance counter for benchmarking.

chaco.scales.safetime.process_time()float

Process time for profiling: sum of the kernel and user-space CPU time.

chaco.scales.safetime.safe_fromtimestamp(timestamp)UTC time from POSIX timestamp.

Timestamps outside of the valid range will be assigned datetime objects of Jan 1 of either MINYEAR or MAXYEAR, whichever appears closest.

WARNING: This function does not behave properly with Daylight Savings Time, due to a documented issue with datetime arithmetic.

chaco.scales.safetime.sleep(seconds)

Delay execution for a given number of seconds. The argument may be a floating point number for subsecond precision.

chaco.scales.safetime.strftime(format[, tuple])string

Convert a time tuple to a string according to a format specification. See the library reference manual for formatting codes. When the time tuple is not present, current time as returned by localtime() is used.

Commonly used format codes:

%Y Year with century as a decimal number. %m Month as a decimal number [01,12]. %d Day of the month as a decimal number [01,31]. %H Hour (24-hour clock) as a decimal number [00,23]. %M Minute as a decimal number [00,59]. %S Second as a decimal number [00,61]. %z Time zone offset from UTC. %a Locale’s abbreviated weekday name. %A Locale’s full weekday name. %b Locale’s abbreviated month name. %B Locale’s full month name. %c Locale’s appropriate date and time representation. %I Hour (12-hour clock) as a decimal number [01,12]. %p Locale’s equivalent of either AM or PM.

Other codes may be available on your platform. See documentation for the C library strftime function.

chaco.scales.safetime.strptime(string, format)struct_time

Parse a string to a time tuple according to a format specification. See the library reference manual for formatting codes (same as strftime()).

Commonly used format codes:

%Y Year with century as a decimal number. %m Month as a decimal number [01,12]. %d Day of the month as a decimal number [01,31]. %H Hour (24-hour clock) as a decimal number [00,23]. %M Minute as a decimal number [00,59]. %S Second as a decimal number [00,61]. %z Time zone offset from UTC. %a Locale’s abbreviated weekday name. %A Locale’s full weekday name. %b Locale’s abbreviated month name. %B Locale’s full month name. %c Locale’s appropriate date and time representation. %I Hour (12-hour clock) as a decimal number [01,12]. %p Locale’s equivalent of either AM or PM.

Other codes may be available on your platform. See documentation for the C library strftime function.

class chaco.scales.safetime.struct_time

Bases: tuple

The time value as returned by gmtime(), localtime(), and strptime(), and accepted by asctime(), mktime() and strftime(). May be considered as a sequence of 9 integers.

Note that several fields’ values are not the same as those defined by the C language standard for struct tm. For example, the value of the field tm_year is the actual year, not year - 1900. See individual fields’ descriptions for details.

n_fields = 11
n_sequence_fields = 9
n_unnamed_fields = 0
tm_gmtoff

offset from UTC in seconds

tm_hour

hours, range [0, 23]

tm_isdst

1 if summer time is in effect, 0 if not, and -1 if unknown

tm_mday

day of month, range [1, 31]

tm_min

minutes, range [0, 59]

tm_mon

month of year, range [1, 12]

tm_sec

seconds, range [0, 61])

tm_wday

day of week, range [0, 6], Monday is 0

tm_yday

day of year, range [1, 366]

tm_year

year, for example, 1993

tm_zone

abbreviation of timezone name

chaco.scales.safetime.time()floating point number

Return the current time in seconds since the Epoch. Fractions of a second may be present if the system clock provides them.

class chaco.scales.safetime.timedelta

Bases: object

Difference between two datetime values.

timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)

All arguments are optional and default to 0. Arguments may be integers or floats, and may be positive or negative.

days

Number of days.

max = datetime.timedelta(999999999, 86399, 999999)
microseconds

Number of microseconds (>= 0 and less than 1 second).

min = datetime.timedelta(-999999999)
resolution = datetime.timedelta(0, 0, 1)
seconds

Number of seconds (>= 0 and less than 1 day).

total_seconds()

Total seconds in the duration.

chaco.scales.safetime.tzset()

Initialize, or reinitialize, the local timezone to the value stored in os.environ[‘TZ’]. The TZ environment variable should be specified in standard Unix timezone format as documented in the tzset man page (eg. ‘US/Eastern’, ‘Europe/Amsterdam’). Unknown timezones will silently fall back to UTC. If the TZ environment variable is not set, the local timezone is set to the systems best guess of wallclock time. Changing the TZ environment variable without calling tzset may change the local timezone used by methods such as localtime, but this behaviour should not be relied on.