MCPcopy
hub / github.com/mmcdole/gofeed / ParseDate

Function ParseDate

internal/shared/dateparser.go:191–222  ·  view source on GitHub ↗

ParseDate parses a given date string using a large list of commonly found feed date formats.

(ds string)

Source from the content-addressed store, hash-verified

189// ParseDate parses a given date string using a large
190// list of commonly found feed date formats.
191func ParseDate(ds string) (t time.Time, err error) {
192 d := strings.TrimSpace(ds)
193 if d == "" {
194 return t, fmt.Errorf("Date string is empty")
195 }
196 for _, f := range dateFormats {
197 if t, err = time.Parse(f, d); err == nil {
198 return
199 }
200 }
201 for _, f := range dateFormatsWithNamedZone {
202 t, err = time.Parse(f, d)
203 if err != nil {
204 continue
205 }
206
207 // This is a format match! Now try to load the timezone name
208 loc, err := time.LoadLocation(t.Location().String())
209 if err != nil {
210 // We couldn't load the TZ name. Just use UTC instead...
211 return t, nil
212 }
213
214 if t, err = time.ParseInLocation(f, ds, loc); err == nil {
215 return t, nil
216 }
217 // This should not be reachable
218 }
219
220 err = fmt.Errorf("Failed to parse date: %s", ds)
221 return
222}

Callers 12

parseRootMethod · 0.92
parseEntryMethod · 0.92
parseSourceMethod · 0.92
parseChannelMethod · 0.92
parseItemMethod · 0.92

Calls 2

ParseMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…