Skip to content

Commit 54f2c69

Browse files
authored
Merge pull request #16603 from seandenigris/bug_addmonths-respect-offset
[Bug]: Date>>#addMonths: should Respect Offset
2 parents 6b676eb + f5811a2 commit 54f2c69

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/System-Time-Tests/DateTest.class.st

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ DateTest >> testAddDays [
8282
{ #category : 'tests' }
8383
DateTest >> testAddMonths [
8484

85+
| dateOutOfTimeZone |
8586
self assert: (january23rd2004 addMonths: 0) equals: (Date readFrom: '23-1-2004' pattern: 'd-m-y').
8687
self assert: (january23rd2004 addMonths: 1) equals: (Date readFrom: '23-2-2004' pattern: 'd-m-y').
88+
dateOutOfTimeZone := january23rd2004 offset: (january23rd2004 offset + 1 hour).
89+
self assert: (dateOutOfTimeZone addMonths: 1) offset equals: dateOutOfTimeZone offset.
8790
self assert: (january23rd2004 addMonths: 12) equals: (Date readFrom: '23-1-2005' pattern: 'd-m-y')
8891
]
8992

src/System-Time/ChronologyConstants.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Class {
77
#classVars : [
88
'DayNames',
99
'DaysInMonth',
10+
'Epoch',
1011
'HoursInDay',
1112
'MicrosecondsInDay',
1213
'MinutesInHour',
@@ -16,8 +17,7 @@ Class {
1617
'NanosInSecond',
1718
'SecondsInDay',
1819
'SecondsInHour',
19-
'SecondsInMinute',
20-
'Epoch'
20+
'SecondsInMinute'
2121
],
2222
#category : 'System-Time',
2323
#package : 'System-Time'

src/System-Time/Date.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ Date >> addMonths: monthCount [
303303
month := self monthIndex + monthCount - 1 \\ 12 + 1.
304304
maxDaysInMonth := Month daysInMonth: month forYear: year.
305305
day := self dayOfMonth min: maxDaysInMonth.
306-
^ Date year: year month: month day: day
306+
^ (Date year: year month: month day: day) translateTo: self offset
307307
]
308308

309309
{ #category : 'accessing' }

0 commit comments

Comments
 (0)