def test_that_it_produces_a_sequence_of_weekly_time_periods(self): range = WEEK.range(d_tz(2013, 4, 1), d_tz(2013, 4, 15)) assert_that(list(range), contains( (d_tz(2013, 4, 1), d_tz(2013, 4, 8)), (d_tz(2013, 4, 8), d_tz(2013, 4, 15)) ))
def test_that_it_expands_the_limits_of_the_range_if_midweek(self): range = WEEK.range(d_tz(2013, 4, 3), d_tz(2013, 4, 19)) assert_that(list(range), contains( (d_tz(2013, 4, 1), d_tz(2013, 4, 8)), (d_tz(2013, 4, 8), d_tz(2013, 4, 15)), (d_tz(2013, 4, 15), d_tz(2013, 4, 22)) ))
def __init__(self, data): result = validate_record_data(data) if not result.is_valid: raise ValidationError(result.message) self.data = data self.meta = {} if "_timestamp" in self.data: self.meta['_week_start_at'] = WEEK.start(self.data['_timestamp']) self.meta['_month_start_at'] = MONTH.start(self.data['_timestamp'])
def datum(name=None, place=None, age=None, stamp=None, count=1): result = { "_count": count } if name is not None: result['name'] = name if place is not None: result['place'] = place if age is not None: result['age'] = age if stamp is not None: result['_timestamp'] = stamp result['_week_start_at'] = WEEK.start(stamp) result['_month_start_at'] = MONTH.start(stamp) return result
def datum(name=None, version=None, place=None, age=None, stamp=None, count=1): result = {"_count": count} if name is not None: result['name'] = name if version is not None: result['version'] = version if place is not None: result['place'] = place if age is not None: result['age'] = age if stamp is not None: result['_timestamp'] = stamp result['_week_start_at'] = WEEK.start(stamp) result['_month_start_at'] = MONTH.start(stamp) return result
def test_that_it_returns_the_next_monday_for_monday_after_midnight(self): monday = datetime.datetime(2013, 4, 8, 23, 12) end = WEEK.end(monday) assert_that(end, is_(datetime.datetime(2013, 4, 15)))
def test_that_it_truncates_the_time_part(self): tuesday = datetime.datetime(2013, 4, 9, 23, 12) end = WEEK.end(tuesday) assert_that(end, is_(datetime.datetime(2013, 4, 15)))
def test_that_it_returns_next_monday_for_midweek(self): tuesday = datetime.datetime(2013, 4, 9) end = WEEK.end(tuesday) assert_that(end, is_(datetime.datetime(2013, 4, 15)))
def test_start_of_week_is_valid(self): assert_that(WEEK.valid_start_at(d(2013, 4, 8, 0, 0, 0)), is_(True))
def test_that_it_truncates_the_time_part(self): tuesday = datetime.datetime(2013, 4, 9, 23, 12) start = WEEK.start(tuesday) assert_that(start, is_(datetime.datetime(2013, 4, 8)))
def test_start_of_week_plus_second_is_invalid(self): assert_that(WEEK.valid_start_at(d(2013, 4, 8, 0, 0, 1)), is_(False))
def test_start_of_week_plus_day_is_invalid(self): assert_that(WEEK.valid_start_at(d(2013, 4, 9, 0, 0, 0)), is_(False))
def test_start_of_week_plus_minute_is_invalid(self): assert_that(WEEK.valid_start_at(d(2013, 4, 8, 0, 1, 0)), is_(False))
def test_that_it_returns_previous_monday_for_midweek(self): tuesday = datetime.datetime(2013, 4, 9) start = WEEK.start(tuesday) assert_that(start, is_(datetime.datetime(2013, 4, 8)))
def test_that_it_returns_the_same_day_for_monday_midnight(self): monday = datetime.datetime(2013, 4, 8, 0, 0) start = WEEK.start(monday) assert_that(start, is_(datetime.datetime(2013, 4, 8)))