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
abstractclassmethod
typing0
Time0
The abstract base class for all Time related types.
Timestart10%
The beginning of the range. Inclusive.
Timestop10%
The end of the range. Exclusive.
Timemagnitude10%
The size of the range in terms of the start.
Time__contains__10%
__contains__(self, pit)
Whether the given point falls between start, inclusive, and stop, exclusive.
assert self.start >= pit and pit < self.stop
Timeof10%
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
timesA sequence of Time instances.
Timeselect10%
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
Timeupdate10%
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
Timetruncate10%
truncate(self, unit)
Truncates the time instance to the specified boundary: remove units smaller than the given unit.
TimetruncateParameters
Measure0
An abstract quantity time. Usually, identified as a Scalar quantity unless subclassed.
Measurekind10%
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%
Identifier of the unit of time--usually the english name.
This must be a str where str(unit).isidentifier() is True.
Measurename10%
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%
For Measure instances, this property must be zero.
assert measure.start == 0
Measurestop10%
For Measure instances, this property must be the instance, self:
assert measure.stop is measure
Measuremagnitude10%
The magnitude of the Time instance. For Measures, this is their integer value:
assert int(measure) == measure.magnitude
Measureincrease10%
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
unitsVariable number of Measure instances.
Measuredecrease10%
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
unitsVariable number of Measure instances.
Point0
A point in time.
Pointkind10%
Classification for the unit type with respect to Points in Time.
PointMeasure150%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%
Points must return the instance, self:
PointstartInvariants
assert point.start is point
Pointstop10%
The next Point according to the unit:
PointstopInvariants
assert point.stop == point.elapse(point.Measure(1))
Pointmagnitude10%
The magnitude of the Point. For Points, this must be one:
assert pit.magnitude == 1
Pointmeasure10%
measure(self, pit)
Return the measurement, Measure instance, between self and the given point in time, pit. The delta between the two points.
Pointelapse10%
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%
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%
leads(self, pit)
Returns whether or not the Point in Time, self, comes before the given argument, pit.
Pointfollows10%
follows(self, pit)
Returns whether or not the Point in Time, self, comes after the given argument, pit.