Remove DateLocal.

Fix tests to check Date type.
This commit is contained in:
John Beisley 2021-07-10 16:04:04 +01:00 committed by Huin
parent 2186162cd7
commit 7913f413b8
2 changed files with 6 additions and 57 deletions

View File

@ -784,39 +784,6 @@ func (d *Date) Unmarshal(s string) error {
return nil
}
// DateLocal maps time.Time to the SOAP "date" type. Dates map to midnight in
// the local time zone. The time of day components are ignored when
// marshalling.
type DateLocal time.Time
var _ SOAPValue = &DateLocal{}
func NewDateLocal(v time.Time) *DateLocal {
v2 := DateLocal(v)
return &v2
}
func (v DateLocal) String() string {
return v.ToTime().String()
}
func (v DateLocal) ToTime() time.Time {
return time.Time(v)
}
func (v *DateLocal) Marshal() (string, error) {
return time.Time(*v).In(localLoc).Format("2006-01-02"), nil
}
func (v *DateLocal) Unmarshal(s string) error {
year, month, day, err := parseDateParts(s)
if err != nil {
return err
}
*v = DateLocal(time.Date(year, time.Month(month), day, 0, 0, 0, 0, localLoc))
return nil
}
// MarshalDateTime maps time.Time to SOAP "dateTime" type, with the local timezone.
type DateTimeLocal time.Time

View File

@ -190,20 +190,6 @@ func Test(t *testing.T) {
unmarshalErrs: []string{"aa", ""},
},
{
makeValue: func() SOAPValue { return new(DateLocal) },
isEqual: func(got, want SOAPValue) bool {
return got.(*DateLocal).ToTime().Equal(want.(*DateLocal).ToTime())
},
marshalTests: []marshalCase{
{NewDateLocal(time.Date(2013, 10, 8, 0, 0, 0, 0, localLoc)), "2013-10-08"},
},
unmarshalTests: []unmarshalCase{
{"20131008", NewDateLocal(time.Date(2013, 10, 8, 0, 0, 0, 0, localLoc))},
},
unmarshalErrs: []string{"", "-1"},
},
{
makeValue: func() SOAPValue { return new(TimeOfDay) },
isEqual: func(got, want SOAPValue) bool {
@ -274,22 +260,18 @@ func Test(t *testing.T) {
},
{
makeValue: func() SOAPValue { return new(DateLocal) },
makeValue: func() SOAPValue { return new(Date) },
isEqual: func(got, want SOAPValue) bool {
return got.(*DateLocal).ToTime().Equal(want.(*DateLocal).ToTime())
a, b := got.(*Date), want.(*Date)
return a.Year == b.Year && a.Month == b.Month && a.Day == b.Day
},
marshalTests: []marshalCase{
{NewDateLocal(time.Date(2013, 10, 8, 0, 0, 0, 0, localLoc)), "2013-10-08"},
{&Date{2013, 10, 8}, "2013-10-08"},
},
unmarshalTests: []unmarshalCase{
{"20131008", NewDateLocal(time.Date(2013, 10, 8, 0, 0, 0, 0, localLoc))},
},
unmarshalErrs: []string{
// Unexpected time component.
"2013-10-08T10:30:50",
// Unexpected timezone component.
"2013-10-08+01",
{"20131008", &Date{2013, 10, 8}},
},
unmarshalErrs: []string{"", "-1"},
},
{