abstract2623%python.module
fault.time

Abstract base classes for time measures and points.

Primarily, this module exists to document the interfaces to Point and Measure. The redundant method declarations are intentional.

abstractmethod
import

abstractclassmethod
import

typing0
import

Time0
class

The abstract base class for all Time related types.

Timestart10%
property

The beginning of the range. Inclusive.

Timestop10%
property

The end of the range. Exclusive.

Timemagnitude10%
property

The size of the range in terms of the start.

Time__contains__10%
abstractmethod

__contains__(self, pit)

Whether the given point falls between start, inclusive, and stop, exclusive.

assert self.start >= pit and pit < self.stop

Timeof10%
method

of(Class, *times, **parts)

Create an instance of the type from the sum of the quantities specified by times and parts:

t = Time.of(hour = 33, microsecond = 44)

The above example only shows keyword use that is specific to the standard time context used by fault.time. Variable position arguments, times, must be pre-existing Measure instances.

TimeofParameters

Class

Undocumented.

times

A sequence of Time instances.

parts

Keyword names designate the unit of the corresponding value. The time context dictates what that is.

Timeselect10%
abstractmethod

select(self, part, of, align)

Extract the number of complete parts designated by part after the last complete whole, of, with respect to the alignment, align.

The result is an int or an arbitrary object given that a Container part is referenced.

Common cases:

h = x.select('hour', 'day')
m = x.select('minute', 'hour')
s = x.select('second', 'minute')
u = x.select('microsecond', 'second')

TimeselectParameters

self

Undocumented.

part

The unit whose count is to be returned.

of

The unit whose total wholes are subtracted from self in order to find the correct total parts.

align

How to align the given part. Trivially, this is a difference that is applied prior to removing wholes: value = self - align.

Timeupdate10%
abstractmethod

update(self, part, replacement, of, align)

Construct and return a new instance adjusted by the difference between the selected part and the given value with respect to the specified alignment.

The following holds true:

updated = pit.update(part, replacement, of, align)
adjusted = this.adjust(**{part: replacement - pit.select(part, of, align)})
assert updated == adjusted

It's existence as an interface is due to its utility.

TimeupdateParameters

self

Undocumented.

part

The name of the Part unit to set.

replacement

The new value to set.

of

The name of the Whole unit that defines the boundary of the part.

align

Defaults to zero; the adjustment applied to the boundary.

Timetruncate10%
abstractmethod

truncate(self, unit)

Truncates the time instance to the specified boundary: remove units smaller than the given unit.

TimetruncateParameters

self

Undocumented.

unit

The minimum unit size to allow in the new time instance.

Measure0
class

An abstract quantity time. Usually, identified as a Scalar quantity unless subclassed.

Measurekind10%
property

Classification for the unit type with respect to measurements.

Currently, only three kinds exist: definite, subjective, and indefinite.

Measures and Points of the same unit may have different unit kinds.

Measureunit10%
property

Identifier of the unit of time--usually the english name.

This must be a str where str(unit).isidentifier() is True.

Measurename10%
property

Name of the unit of time. Normally equal to Time.unit, but potentially different in cases where the proper name is not an identifier.

Measurestart10%
property

For Measure instances, this property must be zero.

assert measure.start == 0

Measurestop10%
property

For Measure instances, this property must be the instance, self:

assert measure.stop is measure

Measuremagnitude10%
property

The magnitude of the Time instance. For Measures, this is their integer value:

assert int(measure) == measure.magnitude

Measureincrease10%
abstractmethod

increase(self, *units, **parts)

Increase the measurement, repositioning the stop.

Returns a new Measure instance whose value is self increased by the given parameters.

This is equivalent to:

assert self.increase(*units, **parts) == self.of(self, *units, **parts)

MeasureincreaseParameters

self

Undocumented.

units

Variable number of Measure instances.

parts

Variable keywords whose keys designate the unit.

Measuredecrease10%
abstractmethod

decrease(self, *units, **parts)

Decrease the measurement, repositioning the stop.

Returns a new Measure instance whose value is self decreased by the given parameters.

This is equivalent to:

neg_units = [-unit for unit in units]
neg_parts = {k:-v for (k,v) in parts}

assert self.decrease(*units, **parts) == self.of(self, *neg_units, **neg_parts)

MeasuredecreaseParameters

self

Undocumented.

units

Variable number of Measure instances.

parts

Variable keywords whose keys designate the unit.

Point0
class

A point in time.

Pointkind10%
property

Classification for the unit type with respect to Points in Time.

PointMeasure150%
property
typing.Type[Measure]

The Point's corresponding scalar class used to measure deltas. This provides access to a abstract.Measure whose precision is consistent with the Point.

PointMeasureInvariants

assert point.Measure.unit == point.unit

Pointstart10%
property

Points must return the instance, self:

PointstartInvariants

assert point.start is point

Pointstop10%
property

The next Point according to the unit:

PointstopInvariants

assert point.stop == point.elapse(point.Measure(1))

Pointmagnitude10%
property

The magnitude of the Point. For Points, this must be one:

assert pit.magnitude == 1

Pointmeasure10%
abstractmethod

measure(self, pit)

Return the measurement, Measure instance, between self and the given point in time, pit. The delta between the two points.

Pointelapse10%
abstractmethod

elapse(self, *units, **parts)

Returns an adjusted measure in time by the given arguments and keywords.

Essentially, this is a call to the of method with the instance as the first parameter.

This is shorthand for t.of(t, *units, **parts).

Pointrollback10%
abstractmethod

rollback(self, *units, **parts)

The point in time that occurred the given number of units before this point. The semantics are identical to Point.elapse, but transforms the parameters into negative values.

PointrollbackInvariants

pit == (pit.rollback(*measures, **units)).elapse(*measures, **units)

Pointleads10%
abstractmethod

leads(self, pit)

Returns whether or not the Point in Time, self, comes before the given argument, pit.

Pointfollows10%
abstractmethod

follows(self, pit)

Returns whether or not the Point in Time, self, comes after the given argument, pit.