Skip to content

Commit 23b9c8a

Browse files
Copilotbzimmer
andauthored
Move WithDateRange to strava core
Agent-Logs-Url: https://github.com/bzimmer/activity/sessions/45c0cbe1-768e-45f3-996b-21cc4798ea3a Co-authored-by: bzimmer <12852+bzimmer@users.noreply.github.com>
1 parent f2eefff commit 23b9c8a

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

strava/activity.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"net/url"
1313
"regexp"
1414
"strings"
15-
"time"
1615

1716
"golang.org/x/sync/errgroup"
1817

@@ -28,24 +27,6 @@ type ActivityIterFunc func(*Activity) (bool, error)
2827
// fileNameRE allowable characters
2928
var fileNameRE = regexp.MustCompile("[A-Za-z0-9-]+")
3029

31-
// WithDateRange sets the before and after date range
32-
func WithDateRange(before, after time.Time) APIOption {
33-
return func(v url.Values) error {
34-
if !before.IsZero() && !after.IsZero() {
35-
if after.After(before) {
36-
return errors.New("invalid date range")
37-
}
38-
}
39-
if !before.IsZero() {
40-
v.Set("before", fmt.Sprintf("%d", before.Unix()))
41-
}
42-
if !after.IsZero() {
43-
v.Set("after", fmt.Sprintf("%d", after.Unix()))
44-
}
45-
return nil
46-
}
47-
}
48-
4930
type channelPaginator struct {
5031
count int
5132
options []APIOption

strava/strava.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"net/http"
1010
"net/url"
11+
"time"
1112

1213
"golang.org/x/oauth2"
1314

@@ -24,6 +25,24 @@ const (
2425
// APIOption for configuring API requests
2526
type APIOption func(url.Values) error
2627

28+
// WithDateRange sets the before and after date range.
29+
func WithDateRange(before, after time.Time) APIOption {
30+
return func(v url.Values) error {
31+
if !before.IsZero() && !after.IsZero() {
32+
if after.After(before) {
33+
return errors.New("invalid date range")
34+
}
35+
}
36+
if !before.IsZero() {
37+
v.Set("before", fmt.Sprintf("%d", before.Unix()))
38+
}
39+
if !after.IsZero() {
40+
v.Set("after", fmt.Sprintf("%d", after.Unix()))
41+
}
42+
return nil
43+
}
44+
}
45+
2746
// Endpoint is Strava's OAuth 2.0 endpoint
2847
func Endpoint() oauth2.Endpoint {
2948
return oauth2.Endpoint{ //nolint:gosec // not a secret

0 commit comments

Comments
 (0)