Skip to content

Commit

Permalink
fix(GODT-3187): Fix numberOfDay computation when changing date.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlejeune74 committed Jan 2, 2024
1 parent 25ebcff commit 43df20c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
5 changes: 1 addition & 4 deletions internal/configstatus/configuration_progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ func numberOfDay(now, prev time.Time) int {
return 1
}
if now.Year() > prev.Year() {
if now.YearDay() > prev.YearDay() {
return 365 + (now.YearDay() - prev.YearDay()) + (365 * (now.Year() - prev.Year() - 1))
}
return (365 - prev.YearDay()) + now.YearDay() + (365 * (now.Year() - prev.Year() - 1))
return (365 * (now.Year() - prev.Year())) + now.YearDay() - prev.YearDay()
} else if now.YearDay() > prev.YearDay() {
return now.YearDay() - prev.YearDay()
}
Expand Down
29 changes: 0 additions & 29 deletions internal/configstatus/configuration_progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,3 @@ func TestConfigurationProgress_fed_year_change(t *testing.T) {
require.Equal(t, 370, req.Values.NbDay)
require.Equal(t, 2, req.Values.NbDaySinceLast)
}

func TestConfigurationProgress_fed_day_higher(t *testing.T) {
dir := t.TempDir()
file := filepath.Join(dir, "dummy.json")
var data = configstatus.ConfigurationStatusData{
Metadata: configstatus.Metadata{Version: "1.0.0"},
DataV1: configstatus.DataV1{
PendingSince: time.Now().AddDate(-1, 0, -5),
LastProgress: time.Now().AddDate(0, 0, -2),
Autoconf: "Mr TBird",
ClickedLink: 42,
ReportSent: false,
ReportClick: true,
FailureDetails: "Not an error",
},
}
require.NoError(t, dumpConfigStatusInFile(&data, file))

config, err := configstatus.LoadConfigurationStatus(file)
require.NoError(t, err)

var builder = configstatus.ConfigProgressBuilder{}
req := builder.New(config)

require.Equal(t, "bridge.any.configuration", req.MeasurementGroup)
require.Equal(t, "bridge_config_progress", req.Event)
require.Equal(t, 370, req.Values.NbDay)
require.Equal(t, 2, req.Values.NbDaySinceLast)
}

0 comments on commit 43df20c

Please sign in to comment.