Skip to content

Commit

Permalink
Add option to specify absolute start time
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleibrand authored and ecc1 committed Mar 5, 2018
1 parent 2f694b8 commit f59824d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/glucose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
var (
all = flag.Bool("a", false, "get all records")
duration = flag.Duration("d", time.Hour, "get `duration` worth of previous records")
since = flag.String("t", "", "get records since the specified `time` in RFC3339 format")
format = flag.String("f", textFormat, "format in which to print records (csv, json, ns, or text)")

egv = flag.Bool("e", true, "include EGV records")
Expand Down Expand Up @@ -48,6 +49,7 @@ func main() {
return
}
var cutoff time.Time
var err error
cgm := dexcom.Open()
if cgm.Error() != nil {
log.Fatal(cgm.Error())
Expand All @@ -58,8 +60,15 @@ func main() {
*sensor = true
*calibration = true
*meter = true
} else if *since != "" {
cutoff, err = time.Parse(dexcom.JSONTimeLayout, *since)
if err != nil {
log.Fatal(err)
}
} else {
cutoff = time.Now().Add(-*duration)
}
if !*all {
log.Printf("retrieving records since %s", cutoff.Format(dexcom.UserTimeLayout))
}
scans := scanRecords(cgm, cutoff)
Expand Down
3 changes: 3 additions & 0 deletions time.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
)

const (
// JSONTimeLayout specifies the format for JSON time values.
JSONTimeLayout = time.RFC3339

// UserTimeLayout specifies a consistent, human-readable format for local time.
UserTimeLayout = "2006-01-02 15:04:05"
)
Expand Down

0 comments on commit f59824d

Please sign in to comment.