This is an automated email from the ASF dual-hosted git repository.

thunguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-seata-go.git


The following commit(s) were added to refs/heads/master by this push:
     new c34171ea fix: make DayValue serialization timezone stable (#1114)
c34171ea is described below

commit c34171eabcf68fd5a34a7f8cd21e58f75f3ce6fc
Author: princejha95 <[email protected]>
AuthorDate: Sat Jul 4 16:33:31 2026 +0530

    fix: make DayValue serialization timezone stable (#1114)
    
    Co-authored-by: ThunGuo <[email protected]>
    Co-authored-by: ssshr-66 <[email protected]>
---
 changes/dev.md               |  1 +
 pkg/util/flagext/day.go      |  8 ++++++--
 pkg/util/flagext/day_test.go | 31 +++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/changes/dev.md b/changes/dev.md
index b45990ce..487c6fab 100755
--- a/changes/dev.md
+++ b/changes/dev.md
@@ -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:
 
diff --git a/pkg/util/flagext/day.go b/pkg/util/flagext/day.go
index 4c15f6a1..9a09cd83 100644
--- a/pkg/util/flagext/day.go
+++ b/pkg/util/flagext/day.go
@@ -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{
@@ -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
@@ -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
 }
diff --git a/pkg/util/flagext/day_test.go b/pkg/util/flagext/day_test.go
index d6d9af58..d7a82bbd 100644
--- a/pkg/util/flagext/day_test.go
+++ b/pkg/util/flagext/day_test.go
@@ -19,6 +19,7 @@ package flagext
 
 import (
        "testing"
+       "time"
 
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/require"
@@ -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 {
+                       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)
+
                var actualStruct TestStruct
                err = yaml.Unmarshal(expected, &actualStruct)
                require.NoError(t, err)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to