Skip to content

Commit

Permalink
time comparison also takes year into account
Browse files Browse the repository at this point in the history
[#137037149]

Signed-off-by: Clara Fu <cfu@pivotal.io>
  • Loading branch information
mariash authored and clarafu committed Jan 4, 2017
1 parent a9e4803 commit e120db2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions check/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ var _ = Describe("Check", func() {
})
})

Context("when the resource was triggered last year near the end of the time frame", func() {
BeforeEach(func() {
prev = now.Add(-24 * time.Hour * 365)
version = &models.Version{Time: prev}
})

It("outputs a version containing the current time and supplied version", func() {
Expect(response).To(HaveLen(2))
Expect(response[0].Time.Unix()).To(BeNumerically("~", prev.Unix(), 1))
Expect(response[1].Time.Unix()).To(BeNumerically("~", time.Now().Unix(), 1))
})
})

Context("when the resource was triggered yesterday in the current time frame", func() {
BeforeEach(func() {
prev = now.Add(-24 * time.Hour)
Expand Down
7 changes: 6 additions & 1 deletion lord/time_lord.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ func (tl TimeLord) Check(now time.Time) bool {
return true
}
} else {
if now.UTC().YearDay() > tl.PreviousTime.UTC().YearDay() {
if now.UTC().Year() > tl.PreviousTime.UTC().Year() {
return true
}

if now.UTC().Year() == tl.PreviousTime.UTC().Year() &&
now.UTC().YearDay() > tl.PreviousTime.UTC().YearDay() {
return true
}
}
Expand Down

0 comments on commit e120db2

Please sign in to comment.