diff --git a/main.go b/main.go index 5b1782e..cc0dd62 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "io/ioutil" "log" "os" @@ -22,8 +23,9 @@ func main() { cvOutputPath := cvOutputDir + cvOutputFileName fmap := template.FuncMap{ - "notLastElement": notLastElement, - "join": join, + "notLastElement": notLastElement, + "join": join, + "durationToString": durationToString, } // Read the JSON data @@ -79,3 +81,19 @@ func notLastElement(pos, length int) bool { func join(s []string) string { return strings.Join(s, " ") } + +// durationToString outputs the employment/education +// duration as a formatted string. +func durationToString(d Duration) string { + start := fmt.Sprintf("%s, %s", d.Start.Month, d.Start.Year) + present := strings.ToLower(d.Present) + end := "" + + if present == "yes" || present == "true" { + end = "Present" + } else { + end = fmt.Sprintf("%s, %s", d.End.Month, d.End.Year) + } + + return start + " - " + end +} diff --git a/model.go b/model.go index 836dda5..6724f06 100644 --- a/model.go +++ b/model.go @@ -41,8 +41,9 @@ type Experience struct { } type Duration struct { - Start Date `json:"start"` - End Date `json:"end"` + Start Date `json:"start"` + End Date `json:"end"` + Present string `json:"present"` } type Date struct { diff --git a/template/cv.tex.tmpl b/template/cv.tex.tmpl index fbbebe6..35fe3d1 100644 --- a/template/cv.tex.tmpl +++ b/template/cv.tex.tmpl @@ -28,7 +28,7 @@ \section{EXPERIENCE} <<- range .Employment>> - \jobsection{<<.Company>>}{<<.Location>>}{<<.JobTitle>>}{<<.Duration.Start.Month>>, <<.Duration.Start.Year>> - <<.Duration.End.Month>>, <<.Duration.End.Year>>} + \jobsection{<<.Company>>}{<<.Location>>}{<<.JobTitle>>}{<>} \startitemize <> \item <<.>> @@ -38,7 +38,7 @@ \section{EDUCATION} <> - \jobsection{<<.School>>}{<<.Location>>}{<<.Qualification>>}{<<.Duration.Start.Month>>, <<.Duration.Start.Year>> - <<.Duration.End.Month>>, <<.Duration.End.Year>>} + \jobsection{<<.School>>}{<<.Location>>}{<<.Qualification>>}{<>} \startitemize <> \item <<.>>