Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UTC explicitly for flagext.DayValue #71

Merged
merged 2 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Changelog

* [CHANGE] Flagext: `DayValue` now always uses UTC when parsing or displaying dates. #71
* [CHANGE] Closer: remove the closer package since it's trivial to just copy/paste. #70
* [CHANGE] Memberlist: allow specifying address and port advertised to the memberlist cluster members by setting the following configuration: #37
* `-memberlist.advertise_addr`
Expand Down
6 changes: 3 additions & 3 deletions flagext/day.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func NewDayValue(t model.Time) DayValue {

// String implements flag.Value
func (v DayValue) String() string {
return v.Time.Time().Format(time.RFC3339)
return v.Time.Time().UTC().Format(time.RFC3339)
}

// Set implements flag.Value
func (v *DayValue) Set(s string) error {
t, err := time.Parse("2006-01-02", s)
t, err := time.ParseInLocation("2006-01-02", s, time.UTC)
if err != nil {
return err
}
Expand All @@ -55,5 +55,5 @@ func (v *DayValue) UnmarshalYAML(unmarshal func(interface{}) error) error {

// MarshalYAML implements yaml.Marshaler.
func (v DayValue) MarshalYAML() (interface{}, error) {
return v.Time.Time().Format("2006-01-02"), nil
return v.Time.Time().UTC().Format("2006-01-02"), nil
}
10 changes: 4 additions & 6 deletions flagext/day_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
)

func TestDayValueYAML(t *testing.T) {
// Test embedding of DayValue.
{
t.Run("embedding DayValue", func(t *testing.T) {
type TestStruct struct {
Day DayValue `yaml:"day"`
}
Expand All @@ -28,10 +27,9 @@ func TestDayValueYAML(t *testing.T) {
err = yaml.Unmarshal(expected, &actualStruct)
require.NoError(t, err)
assert.Equal(t, testStruct, actualStruct)
}
})

// Test pointers of DayValue.
{
t.Run("pointer of DayValue", func(t *testing.T) {
type TestStruct struct {
Day *DayValue `yaml:"day"`
}
Expand All @@ -50,5 +48,5 @@ func TestDayValueYAML(t *testing.T) {
err = yaml.Unmarshal(expected, &actualStruct)
require.NoError(t, err)
assert.Equal(t, testStruct, actualStruct)
}
})
}