Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

- [[#130](https://github.com/apache/incubator-seata-go/pull/130)] getty session auto close bug
- [[#991](https://github.com/apache/incubator-seata-go/issues/991)] fix connection leaks and prevent nil pointer panic in async worker
- [[#887](https://github.com/apache/incubator-seata-go/issues/887)] make DayValue serialization timezone-stable

### optimize:

Expand Down
8 changes: 6 additions & 2 deletions pkg/util/flagext/day.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type DayValue struct {
set bool
}

func (v DayValue) utcTime() time.Time {
return v.Time.Time().UTC()
}

// NewDayValue makes a new DayValue; will round t down to the nearest midnight.
func NewDayValue(t model.Time) DayValue {
return DayValue{
Expand All @@ -42,7 +46,7 @@ func NewDayValue(t model.Time) DayValue {

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

// Set implements flag.Value
Expand Down Expand Up @@ -72,5 +76,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.utcTime().Format("2006-01-02"), nil
}
31 changes: 31 additions & 0 deletions pkg/util/flagext/day_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package flagext

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -63,6 +64,36 @@ func TestDayValueYAML(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, expected, actual)

var actualStruct TestStruct
err = yaml.Unmarshal(expected, &actualStruct)
require.NoError(t, err)
assert.Equal(t, testStruct, actualStruct)
}
// Test UTC-stable string and YAML serialization in western timezones.
{
loc, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
Comment on lines +72 to +75

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

The comment says this block tests "UTC-stable string and YAML serialization", but the test only asserts YAML marshal/unmarshal output and never checks DayValue.String(). Either add an assertion for the String() output under the modified time.Local, or adjust the comment to only mention YAML serialization to keep the test intent accurate.

Copilot uses AI. Check for mistakes.
loc = time.FixedZone("UTC-8", -8*60*60)
}

originalLocal := time.Local
time.Local = loc
defer func() {
time.Local = originalLocal
}()
type TestStruct struct {
Day *DayValue `yaml:"day"`
}
var testStruct TestStruct
testStruct.Day = &DayValue{}
require.NoError(t, testStruct.Day.Set("1985-06-02"))
expected := []byte(`day: "1985-06-02"
`)

actual, err := yaml.Marshal(testStruct)
require.NoError(t, err)
assert.Equal(t, expected, actual)
Comment on lines +84 to +95

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

This new timezone-specific YAML test duplicates the prior "pointers of DayValue" block almost line-for-line. Consider making the pointer test table-driven (e.g., parameterize the location) or extracting a small helper to reduce duplication and make future additions (more timezones) easier.

Copilot uses AI. Check for mistakes.

var actualStruct TestStruct
err = yaml.Unmarshal(expected, &actualStruct)
require.NoError(t, err)
Expand Down
Loading