Commit fc88a0f4 authored by Russ Cox's avatar Russ Cox

net/mail: expose ParseDate, for use parsing Resent-Date headers

Fixes #16657.

Change-Id: I9425af91a48016b1d7465b9f43cafa792bc00bb3
Reviewed-on: https://go-review.googlesource.com/31581Reviewed-by: default avatarQuentin Smith <quentin@golang.org>
parent 699fb0fc
......@@ -92,7 +92,8 @@ func init() {
}
}
func parseDate(date string) (time.Time, error) {
// ParseDate parses an RFC 5322 date string.
func ParseDate(date string) (time.Time, error) {
for _, layout := range dateLayouts {
t, err := time.Parse(layout, date)
if err == nil {
......@@ -119,7 +120,7 @@ func (h Header) Date() (time.Time, error) {
if hdr == "" {
return time.Time{}, ErrHeaderNotPresent
}
return parseDate(hdr)
return ParseDate(hdr)
}
// AddressList parses the named header field as a list of addresses.
......
......@@ -110,11 +110,16 @@ func TestDateParsing(t *testing.T) {
}
date, err := hdr.Date()
if err != nil {
t.Errorf("Failed parsing %q: %v", test.dateStr, err)
continue
t.Errorf("Header(Date: %s).Date(): %v", test.dateStr, err)
} else if !date.Equal(test.exp) {
t.Errorf("Header(Date: %s).Date() = %+v, want %+v", test.dateStr, date, test.exp)
}
if !date.Equal(test.exp) {
t.Errorf("Parse of %q: got %+v, want %+v", test.dateStr, date, test.exp)
date, err = ParseDate(test.dateStr)
if err != nil {
t.Errorf("ParseDate(%s): %v", test.dateStr, err)
} else if !date.Equal(test.exp) {
t.Errorf("ParseDate(%s) = %+v, want %+v", test.dateStr, date, test.exp)
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment