Skip to content

Commit

Permalink
Use UTC explicitly for flagext.DayValue
Browse files Browse the repository at this point in the history
Fixes #23

Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
  • Loading branch information
56quarters committed Nov 3, 2021
1 parent 72fa100 commit 0af13f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
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)
}
})
}

0 comments on commit 0af13f7

Please sign in to comment.