Skip to content

Commit 9de492a

Browse files
committed
Revert "refactor(isodate): make it so an hour divides a day"
This reverts commit 6fe23ee.
1 parent 6fe23ee commit 9de492a

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

pkg/isodate/date.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ func (p Period) DivisibleBy(smaller Period) (bool, error) {
137137
return true, nil // Years/months always contain days
138138
}
139139

140-
// Days are conceptually divisible by hours/minutes/seconds
141-
if p.isDayLike() && smaller.isTimeLike() {
142-
return true, nil // Days always contain hours/minutes/seconds
143-
}
144-
145140
var err error
146141
per := smaller
147142
for i := 1; i < MAX_SAFE_ITERATION_COUNT; i++ {
@@ -180,19 +175,6 @@ func (p Period) isDay() bool {
180175
p.Period.Hours() == 0 && p.Period.Minutes() == 0 && p.Period.Seconds() == 0
181176
}
182177

183-
// isDayLike returns true if the period contains only days (potentially more than 1)
184-
func (p Period) isDayLike() bool {
185-
return p.Period.Days() > 0 &&
186-
p.Period.Years() == 0 && p.Period.Months() == 0 && p.Period.Weeks() == 0 &&
187-
p.Period.Hours() == 0 && p.Period.Minutes() == 0 && p.Period.Seconds() == 0
188-
}
189-
190-
// isTimeLike returns true if the period contains only hours, minutes, and/or seconds
191-
func (p Period) isTimeLike() bool {
192-
return (p.Period.Hours() != 0 || p.Period.Minutes() != 0 || p.Period.Seconds() != 0) &&
193-
p.Period.Years() == 0 && p.Period.Months() == 0 && p.Period.Weeks() == 0 && p.Period.Days() == 0
194-
}
195-
196178
func Between(start time.Time, end time.Time) Period {
197179
per := period.Between(start, end)
198180
return Period{per}

pkg/isodate/date_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,45 +179,45 @@ func TestDivisibleBy(t *testing.T) {
179179
hasError: false,
180180
},
181181
{
182-
name: "1 day divisible by 1 hour",
182+
name: "1 day not divisible by 1 hour (different units)",
183183
larger: "P1D",
184184
smaller: "PT1H",
185-
expected: true,
185+
expected: false,
186186
hasError: false,
187187
},
188188
{
189-
name: "1 day divisible by 2 hours",
189+
name: "1 day not divisible by 2 hours (different units)",
190190
larger: "P1D",
191191
smaller: "PT2H",
192-
expected: true,
192+
expected: false,
193193
hasError: false,
194194
},
195195
{
196-
name: "1 day divisible by 4 hours",
196+
name: "1 day not divisible by 4 hours (different units)",
197197
larger: "P1D",
198198
smaller: "PT4H",
199-
expected: true,
199+
expected: false,
200200
hasError: false,
201201
},
202202
{
203-
name: "1 day divisible by 6 hours",
203+
name: "1 day not divisible by 6 hours (different units)",
204204
larger: "P1D",
205205
smaller: "PT6H",
206-
expected: true,
206+
expected: false,
207207
hasError: false,
208208
},
209209
{
210-
name: "1 day divisible by 8 hours",
210+
name: "1 day not divisible by 8 hours (different units)",
211211
larger: "P1D",
212212
smaller: "PT8H",
213-
expected: true,
213+
expected: false,
214214
hasError: false,
215215
},
216216
{
217-
name: "1 day divisible by 12 hours",
217+
name: "1 day not divisible by 12 hours (different units)",
218218
larger: "P1D",
219219
smaller: "PT12H",
220-
expected: true,
220+
expected: false,
221221
hasError: false,
222222
},
223223
{

0 commit comments

Comments
 (0)