Skip to content

Commit 4ad76aa

Browse files
interval: fix week arithmetic
Before this patch, weeks were ignored in Interval addition and subtraction. This patch fixes the issue.
1 parent bca64f5 commit 4ad76aa

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased
8+
9+
### Fixed
10+
- `tarantool.Interval` arithmetic with weeks
11+
712
## 1.1.0 - 2023-06-30
813

914
### Added

Diff for: tarantool/msgpack_ext/types/interval.py

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def __add__(self, other):
145145
return Interval(
146146
year=self.year + other.year,
147147
month=self.month + other.month,
148+
week=self.week + other.week,
148149
day=self.day + other.day,
149150
hour=self.hour + other.hour,
150151
minute=self.minute + other.minute,
@@ -194,6 +195,7 @@ def __sub__(self, other):
194195
return Interval(
195196
year=self.year - other.year,
196197
month=self.month - other.month,
198+
week=self.week - other.week,
197199
day=self.day - other.day,
198200
hour=self.hour - other.hour,
199201
minute=self.minute - other.minute,

Diff for: test/suites/test_interval.py

+22
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,28 @@ def test_unknown_adjust_decode(self):
283283
'res_add': tarantool.Interval(year=3, adjust=tarantool.IntervalAdjust.LAST),
284284
'res_sub': tarantool.Interval(year=1, adjust=tarantool.IntervalAdjust.LAST),
285285
},
286+
'weeks': {
287+
'arg_1': tarantool.Interval(week=2),
288+
'arg_2': tarantool.Interval(week=1),
289+
'res_add': tarantool.Interval(week=3),
290+
'res_sub': tarantool.Interval(week=1),
291+
},
292+
'date_with_week': {
293+
'arg_1': tarantool.Interval(year=1, month=2, week=3, day=4),
294+
'arg_2': tarantool.Interval(year=4, month=3, week=2, day=1),
295+
'res_add': tarantool.Interval(year=5, month=5, week=5, day=5),
296+
'res_sub': tarantool.Interval(year=-3, month=-1, week=1, day=3),
297+
},
298+
'datetime_with_week': {
299+
'arg_1': tarantool.Interval(year=1, month=2, week=3, day=4, hour=1, minute=2,
300+
sec=3000, nsec=10000000),
301+
'arg_2': tarantool.Interval(year=2, month=1, week=-1, day=31, hour=-3, minute=0,
302+
sec=1000, nsec=9876543),
303+
'res_add': tarantool.Interval(year=3, month=3, week=2, day=35, hour=-2, minute=2,
304+
sec=4000, nsec=19876543),
305+
'res_sub': tarantool.Interval(year=-1, month=1, week=4, day=-27, hour=4, minute=2,
306+
sec=2000, nsec=123457),
307+
},
286308
}
287309

288310
def test_python_interval_addition(self):

0 commit comments

Comments
 (0)