1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

Add workaround for non GMT dates (RFC822, RFC850, and RFC1123)

RFC822, RFC850, and RFC1123 are supposed to be always in GMT.

This is a workaround for the one defined in PST timezone.
This commit is contained in:
Frédéric Guillot 2018-12-26 20:24:38 -08:00
parent 078cd0050a
commit 56efd2eb3f
2 changed files with 105 additions and 8 deletions

View file

@ -206,8 +206,15 @@ func Parse(ds string) (t time.Time, err error) {
return t, errors.New("date parser: empty value")
}
for _, f := range dateFormats {
if t, err = time.Parse(f, d); err == nil {
for _, layout := range dateFormats {
switch layout {
case time.RFC822, time.RFC850, time.RFC1123:
if t, err = parseLocalTimeDates(layout, d); err == nil {
return
}
}
if t, err = time.Parse(layout, d); err == nil {
return
}
}
@ -221,6 +228,22 @@ func Parse(ds string) (t time.Time, err error) {
return
}
// According to Golang documentation:
//
// RFC822, RFC850, and RFC1123 formats should be applied only to local times.
// Applying them to UTC times will use "UTC" as the time zone abbreviation,
// while strictly speaking those RFCs require the use of "GMT" in that case.
func parseLocalTimeDates(layout, ds string) (t time.Time, err error) {
loc := time.UTC
// Workaround for dates that don't use GMT.
if strings.HasSuffix(ds, "PST") {
loc, _ = time.LoadLocation("America/Los_Angeles")
}
return time.ParseInLocation(layout, ds, loc)
}
// Replace German and French dates to English.
func replaceNonEnglishWords(ds string) string {
r := strings.NewReplacer(