fix: correct parsing of maintenance window (#649)

* fix: correct parsing of maintenance window

* refactored dateparsing

* chore: fix go lint warnings

* fix: fix review finding

* fix: another review finding
This commit is contained in:
Rüdiger Schmitz 2025-01-27 12:17:51 +01:00 committed by GitHub
parent 2ec95dc20f
commit 2990f4507e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 71 additions and 4 deletions

View file

@ -1225,6 +1225,14 @@ func toExtensionsPayload(ctx context.Context, m *Model) (*ske.Extension, error)
}, nil
}
func parseMaintenanceWindowTime(t string) (time.Time, error) {
v, err := time.Parse("15:04:05-07:00", t)
if err != nil {
v, err = time.Parse("15:04:05Z", t)
}
return v, err
}
func toMaintenancePayload(ctx context.Context, m *Model) (*ske.Maintenance, error) {
if m.Maintenance.IsNull() || m.Maintenance.IsUnknown() {
return nil, nil
@ -1238,8 +1246,7 @@ func toMaintenancePayload(ctx context.Context, m *Model) (*ske.Maintenance, erro
var timeWindowStart *time.Time
if !(maintenance.Start.IsNull() || maintenance.Start.IsUnknown()) {
// API expects RFC3339 datetime
tempTime, err := time.Parse(time.RFC3339, maintenance.Start.ValueString())
tempTime, err := parseMaintenanceWindowTime(maintenance.Start.ValueString())
if err != nil {
return nil, fmt.Errorf("converting maintenance object: %w", err)
}
@ -1248,8 +1255,7 @@ func toMaintenancePayload(ctx context.Context, m *Model) (*ske.Maintenance, erro
var timeWindowEnd *time.Time
if !(maintenance.End.IsNull() || maintenance.End.IsUnknown()) {
// API expects RFC3339 datetime
tempTime, err := time.Parse(time.RFC3339, maintenance.End.ValueString())
tempTime, err := parseMaintenanceWindowTime(maintenance.End.ValueString())
if err != nil {
return nil, fmt.Errorf("converting maintenance object: %w", err)
}