Skip to content

Commit

Permalink
WithFrom and WithUntil
Browse files Browse the repository at this point in the history
  • Loading branch information
Florimond committed May 4, 2019
1 parent 0bd5959 commit a64c9ac
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions v2/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

2 comments on commit a64c9ac

@postacik
Copy link

@postacik postacik commented on a64c9ac May 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct the WithUntil function:

func WithUntil(until time.Time) Option {
	return option("until=" + strconv.FormatInt(getUTCTimestamp(until), 10))
}

@Florimond
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Sorry about that.

Please sign in to comment.