Dan Anglin
9e0f5af2e6
- Use go generate and a third party tool called jsonschemagen to auto-generate the CV data type from the JSON schema. - Update the schema by changing number to integer to ensure that the integers are set to the correct type. - Refactor some code.
36 lines
663 B
Go
36 lines
663 B
Go
package templateFuncs
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"codeflow.dananglin.me.uk/apollo/spruce/internal/cv"
|
|
)
|
|
|
|
// FormatDuration outputs the employment/education
|
|
// duration as a formatted string.
|
|
func FormatDuration(d cv.Duration) string {
|
|
var start string
|
|
|
|
startDate, err := d.Start.Parse()
|
|
|
|
if err != nil {
|
|
start = "Unknown"
|
|
} else {
|
|
start = fmt.Sprintf("%s, %d", startDate.Month().String(), startDate.Year())
|
|
}
|
|
|
|
var end string
|
|
|
|
if d.Present {
|
|
end = "Present"
|
|
} else {
|
|
endDate, err := d.End.Parse()
|
|
if err != nil {
|
|
end = "Unknown"
|
|
} else {
|
|
end = fmt.Sprintf("%s, %d", endDate.Month().String(), endDate.Year())
|
|
}
|
|
}
|
|
|
|
return start + " - " + end
|
|
}
|