Пример #1
0
    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, 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
Пример #3
0
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
Пример #4
0
    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)))
Пример #5
0
    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)))
Пример #6
0
    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)))
Пример #7
0
    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)))
Пример #8
0
    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)))
Пример #9
0
    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)))