Skip to content

Commit

Permalink
improvements per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pivotal-david-osullivan committed Jan 29, 2024
1 parent 87bd425 commit 878b3fe
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,30 @@ func (l *LayerContributor) normalizeDependencyDeprecationDate(input map[string]i
if dep, ok := input["dependency"].(map[string]interface{}); ok {
for k, v := range dep {
if k == "deprecation_date" {
deprecationDate, err := l.parseDeprecationDate(v)
if err != nil {
if err := l.replaceDeprecationDate(dep, v); err != nil {
return err
}
dep["deprecation_date"] = deprecationDate
break
}
}
} else if depr_date, ok := input["deprecation_date"]; ok {
deprecationDate, err := l.parseDeprecationDate(depr_date)
if err != nil {
if err := l.replaceDeprecationDate(input, depr_date); err != nil {
return err
}
input["deprecation_date"] = deprecationDate
}

return nil
}

func (l *LayerContributor) replaceDeprecationDate(metadata map[string]interface{}, value interface{}) error {
deprecationDate, err := l.parseDeprecationDate(value)
if err != nil {
return err
}
metadata["deprecation_date"] = deprecationDate
return nil
}

// parseDeprecationDate accepts both string and time.Time as input, and returns
// a truncated time.Time value.
func (l *LayerContributor) parseDeprecationDate(v interface{}) (deprecationDate time.Time, err error) {
Expand Down

0 comments on commit 878b3fe

Please sign in to comment.