aboutsummaryrefslogtreecommitdiffstats
path: root/timetask/http_test.go
diff options
context:
space:
mode:
authorTeddy Wing2017-03-12 13:39:15 +0100
committerTeddy Wing2017-03-12 13:39:15 +0100
commitaee4a11e2d7263e6f2056ff0af8273e842e14ff4 (patch)
tree9831a181a40ff51a1fd8ef338229e15f6b1907e2 /timetask/http_test.go
parente6eee887588efff57d7e8b39894143880357f61c (diff)
downloadtimetasker-aee4a11e2d7263e6f2056ff0af8273e842e14ff4.tar.bz2
Parse timesheet files
Expect a timesheet file as the last argument to the program. Parse the contents into `TimeEntry` objects. `TimeEntry`ies will then be able to be POSTed to Time Task to submit times. The time entries input file is a YAML document in this format: - client: A client project: A project module: A module task: A task work_type: type date: 2017-03-06 time: 7 billable: true description: It contains an array where each element is a time entry. Had a lot of trouble parsing the date into a `time.Time`. Finally realised that my first and biggest problem was somehow I was importing `yaml.v1` instead of `yaml.v2`, and thus my `UnmarshalYAML` function was never getting called. Wanted a way to get the time as a string and parse it myself into a time. At first tried using an `UnmarshalText` function: type Time time.Time func (t *Time) UnmarshalText(text []byte) error { parsed, err := time.Parse("2006-01-02", string(text)) if err == nil { *t = Time(parsed) } return err } But in order to do that I had to make a type alias to `time.Time`. Doing so was not ideal, because then I'd have to convert my `Time` into a `time.Time` any time I wanted to use it for real. Ended up going with a suggestion from here: https://mlafeldt.github.io/blog/decoding-yaml-in-go/ Creating an auxiliary struct in `UnmarshalYAML` to unmarshal the date into a string and then parse it myself as a date. I don't really like it because it's a lot of ceremony just to parse one type myself, but can't come up with a better solution right now so there you have it.
Diffstat (limited to 'timetask/http_test.go')
0 files changed, 0 insertions, 0 deletions