From a64c9aca4bab172bf3e4a5ded3b38d1b17ae1427 Mon Sep 17 00:00:00 2001 From: Florimond Husquinet Date: Sat, 4 May 2019 13:13:49 +0200 Subject: [PATCH] WithFrom and WithUntil --- v2/options.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/v2/options.go b/v2/options.go index 56254df..db80863 100644 --- a/v2/options.go +++ b/v2/options.go @@ -149,3 +149,22 @@ func WithAtMostOnce() Option { func WithAtLeastOnce() Option { return withQos1 } + +func getUTCTimestamp(input time.Time) int64 { + t := input + if zone, _ := t.Zone(); zone != "UTC" { + loc, _ := time.LoadLocation("UTC") + t = t.In(loc) + } + return t.Unix() +} + +// WithFrom request messages from a point in time. +func WithFrom(from time.Time) Option { + return option("from=" + strconv.FormatInt(getUTCTimestamp(from), 10)) +} + +// WithUntil request messages until a point in time. +func WithUntil(until time.Time) Option { + return option("from=" + strconv.FormatInt(getUTCTimestamp(until), 10)) +}