Handle feeds with dates formatted as Unix timestamp

This commit is contained in:
Frédéric Guillot 2018-05-08 20:41:24 -07:00
parent 39c4452142
commit 0c2e5ff0dc
2 changed files with 7 additions and 0 deletions

View File

@ -7,6 +7,7 @@ package date
import (
"errors"
"fmt"
"strconv"
"strings"
"time"
)
@ -194,6 +195,11 @@ var dateFormats = []string{
// Parse parses a given date string using a large
// list of commonly found feed date formats.
func Parse(ds string) (t time.Time, err error) {
timestamp, err := strconv.ParseInt(ds, 10, 64)
if err == nil {
return time.Unix(timestamp, 0), nil
}
ds = replaceNonEnglishWords(ds)
d := strings.TrimSpace(ds)
if d == "" {

View File

@ -51,6 +51,7 @@ func TestParseWeirdDateFormat(t *testing.T) {
"Di, 23 Jan 2018 00:00:00 +0100",
"Do, 29 Mär 2018 00:00:00 +0200",
"mer, 9 avr 2018 00:00:00 +0200",
"1520932969",
}
for _, date := range dates {