spruce/internal/cv/types.go
Dan Anglin fa8dbe68e9
feat(BREAKING): limit shown employment history
Allow users to limit the amount of employment history shown in the PDF
document by specifying a time range. This is a breaking change as the
structure of the CV needs to slightly change. The employment's start and
end dates need to be represented as integers.

Additional refactoring:

- The CV type is now in the internal cv package.
- The template functions are now in the internal templateFuncs package.
2023-03-02 17:40:04 +00:00

67 lines
1.6 KiB
Go

package cv
import (
"fmt"
"time"
)
type CV struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
JobTitle string `json:"jobTitle"`
Contact map[string]string `json:"contact"`
Links map[string]string `json:"links"`
Summary []string `json:"summary"`
Skills []Skills `json:"skills"`
Employment []Experience `json:"employment"`
Education []Experience `json:"education"`
Interests []string `json:"interests"`
}
type Skills struct {
Category string `json:"category"`
Values []string `json:"values"`
}
type Experience struct {
Company string `json:"company"`
School string `json:"school"`
Location string `json:"location"`
JobTitle string `json:"jobTitle"`
Qualification string `json:"qualification"`
Duration Duration `json:"duration"`
Details []string `json:"details"`
}
type Duration struct {
Start Date `json:"start"`
End Date `json:"end"`
Present bool `json:"present"`
}
func (d Duration) After(t time.Time) (bool, error) {
endDate, err := d.End.ParseDate()
if err != nil {
return false, err
}
return endDate.After(t), nil
}
type Date struct {
Year int `json:"year"`
Month int `json:"month"`
Day int `json:"day"`
}
func (d Date) ParseDate() (time.Time, error) {
dateStr := fmt.Sprintf("%d-%02d-%02d", d.Year, d.Month, d.Day)
date, err := time.Parse(time.DateOnly, dateStr)
if err != nil {
return time.Time{}, fmt.Errorf("unable to parse the date; %w", err)
}
return date, nil
}