1.1 --- a/imiptools/period.py Mon Oct 26 19:46:49 2015 +0100
1.2 +++ b/imiptools/period.py Tue Oct 27 00:05:46 2015 +0100
1.3 @@ -129,6 +129,10 @@
1.4 return Comparable(ifnone(self.get_end_point(), EndOfTime())) > Comparable(ifnone(other.get_start_point(), StartOfTime())) and \
1.5 Comparable(ifnone(self.get_start_point(), StartOfTime())) < Comparable(ifnone(other.get_end_point(), EndOfTime()))
1.6
1.7 + def within(self, other):
1.8 + return Comparable(ifnone(self.get_start_point(), StartOfTime())) >= Comparable(ifnone(other.get_start_point(), StartOfTime())) and \
1.9 + Comparable(ifnone(self.get_end_point(), EndOfTime())) <= Comparable(ifnone(other.get_end_point(), EndOfTime()))
1.10 +
1.11 def get_key(self):
1.12 return self.get_start(), self.get_end()
1.13
1.14 @@ -239,9 +243,18 @@
1.15
1.16 # Value correction methods.
1.17
1.18 - def get_corrected(self, permitted_values):
1.19 + def with_duration(self, duration):
1.20
1.21 - "Return a corrected version of this period."
1.22 + """
1.23 + Return a version of this period with the same start point but with the
1.24 + given 'duration'.
1.25 + """
1.26 +
1.27 + return self.make_corrected(self.get_start(), self.get_start() + duration)
1.28 +
1.29 + def check_permitted(self, permitted_values):
1.30 +
1.31 + "Check the period against the given 'permitted_values'."
1.32
1.33 start = self.get_start()
1.34 end = self.get_end()
1.35 @@ -249,8 +262,21 @@
1.36 end_errors = check_permitted_values(end, permitted_values)
1.37
1.38 if not (start_errors or end_errors):
1.39 + return None
1.40 +
1.41 + return start_errors, end_errors
1.42 +
1.43 + def get_corrected(self, permitted_values):
1.44 +
1.45 + "Return a corrected version of this period."
1.46 +
1.47 + errors = self.check_permitted(permitted_values)
1.48 +
1.49 + if not errors:
1.50 return self
1.51
1.52 + start_errors, end_errors = errors
1.53 +
1.54 if start_errors:
1.55 start = correct_datetime(start, permitted_values)
1.56 if end_errors: