Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
interval: fix week arithmetic
Before this patch, weeks were ignored in Interval addition
and subtraction. This patch fixes the issue.
  • Loading branch information
DifferentialOrange committed Jul 13, 2023
commit 4ad76aa24c81d98d99072fcc2ba361e0d94aee15
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed
- `tarantool.Interval` arithmetic with weeks

## 1.1.0 - 2023-06-30

### Added
Expand Down
2 changes: 2 additions & 0 deletions tarantool/msgpack_ext/types/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def __add__(self, other):
return Interval(
year=self.year + other.year,
month=self.month + other.month,
week=self.week + other.week,
day=self.day + other.day,
hour=self.hour + other.hour,
minute=self.minute + other.minute,
Expand Down Expand Up @@ -194,6 +195,7 @@ def __sub__(self, other):
return Interval(
year=self.year - other.year,
month=self.month - other.month,
week=self.week - other.week,
day=self.day - other.day,
hour=self.hour - other.hour,
minute=self.minute - other.minute,
Expand Down
22 changes: 22 additions & 0 deletions test/suites/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,28 @@ def test_unknown_adjust_decode(self):
'res_add': tarantool.Interval(year=3, adjust=tarantool.IntervalAdjust.LAST),
'res_sub': tarantool.Interval(year=1, adjust=tarantool.IntervalAdjust.LAST),
},
'weeks': {
'arg_1': tarantool.Interval(week=2),
'arg_2': tarantool.Interval(week=1),
'res_add': tarantool.Interval(week=3),
'res_sub': tarantool.Interval(week=1),
},
'date_with_week': {
'arg_1': tarantool.Interval(year=1, month=2, week=3, day=4),
'arg_2': tarantool.Interval(year=4, month=3, week=2, day=1),
'res_add': tarantool.Interval(year=5, month=5, week=5, day=5),
'res_sub': tarantool.Interval(year=-3, month=-1, week=1, day=3),
},
'datetime_with_week': {
'arg_1': tarantool.Interval(year=1, month=2, week=3, day=4, hour=1, minute=2,
sec=3000, nsec=10000000),
'arg_2': tarantool.Interval(year=2, month=1, week=-1, day=31, hour=-3, minute=0,
sec=1000, nsec=9876543),
'res_add': tarantool.Interval(year=3, month=3, week=2, day=35, hour=-2, minute=2,
sec=4000, nsec=19876543),
'res_sub': tarantool.Interval(year=-1, month=1, week=4, day=-27, hour=4, minute=2,
sec=2000, nsec=123457),
},
}

def test_python_interval_addition(self):
Expand Down