go fmt
This commit is contained in:
parent
c6a7816435
commit
a93420eed3
4
item.go
4
item.go
|
@ -3,7 +3,7 @@ package feeder
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
|
@ -29,7 +29,7 @@ type Item struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Item) ParsedPubDate() (time.Time, error) {
|
func (i *Item) ParsedPubDate() (time.Time, error) {
|
||||||
return parseTime(i.PubDate)
|
return parseTime(i.PubDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Item) Key() string {
|
func (i *Item) Key() string {
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
package feeder
|
package feeder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseTime(formatted string) (time.Time, error) {
|
func parseTime(formatted string) (time.Time, error) {
|
||||||
var layouts = [...]string{
|
var layouts = [...]string{
|
||||||
"Mon, _2 Jan 2006 15:04:05 MST",
|
"Mon, _2 Jan 2006 15:04:05 MST",
|
||||||
"Mon, _2 Jan 2006 15:04:05 -0700",
|
"Mon, _2 Jan 2006 15:04:05 -0700",
|
||||||
time.ANSIC,
|
time.ANSIC,
|
||||||
time.UnixDate,
|
time.UnixDate,
|
||||||
time.RubyDate,
|
time.RubyDate,
|
||||||
time.RFC822,
|
time.RFC822,
|
||||||
time.RFC822Z,
|
time.RFC822Z,
|
||||||
time.RFC850,
|
time.RFC850,
|
||||||
time.RFC1123,
|
time.RFC1123,
|
||||||
time.RFC1123Z,
|
time.RFC1123Z,
|
||||||
time.RFC3339,
|
time.RFC3339,
|
||||||
time.RFC3339Nano,
|
time.RFC3339Nano,
|
||||||
"Mon, 2, Jan 2006 15:4",
|
"Mon, 2, Jan 2006 15:4",
|
||||||
"02 Jan 2006 15:04:05 MST",
|
"02 Jan 2006 15:04:05 MST",
|
||||||
}
|
}
|
||||||
var t time.Time
|
var t time.Time
|
||||||
var err error
|
var err error
|
||||||
formatted = strings.TrimSpace(formatted)
|
formatted = strings.TrimSpace(formatted)
|
||||||
for _, layout := range layouts {
|
for _, layout := range layouts {
|
||||||
t, err = time.Parse(layout, formatted)
|
t, err = time.Parse(layout, formatted)
|
||||||
if !t.IsZero() {
|
if !t.IsZero() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t, err
|
return t, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,94 +1,94 @@
|
||||||
package feeder
|
package feeder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"testing"
|
||||||
"testing"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_InvalidDate(t *testing.T) {
|
func Test_InvalidDate(t *testing.T) {
|
||||||
date, err := parseTime("invalid")
|
date, err := parseTime("invalid")
|
||||||
if !date.IsZero() {
|
if !date.IsZero() {
|
||||||
t.Errorf("Invalid date should parse to zero")
|
t.Errorf("Invalid date should parse to zero")
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("error should not be nil")
|
t.Errorf("error should not be nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ParseLayout0(t *testing.T) {
|
func Test_ParseLayout0(t *testing.T) {
|
||||||
date, err := parseTime("2014-03-07T05:38:00-05:00")
|
date, err := parseTime("2014-03-07T05:38:00-05:00")
|
||||||
expected := time.Date(2014, time.March, 7, 5, 38, 0, 0, time.FixedZone("-0500", -18000))
|
expected := time.Date(2014, time.March, 7, 5, 38, 0, 0, time.FixedZone("-0500", -18000))
|
||||||
assertEqualTime(t, expected, date)
|
assertEqualTime(t, expected, date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("err should be nil")
|
t.Errorf("err should be nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ParseLayout1(t *testing.T) {
|
func Test_ParseLayout1(t *testing.T) {
|
||||||
date, err := parseTime("Fri, 07 Mar 2014 17:42:51 GMT")
|
date, err := parseTime("Fri, 07 Mar 2014 17:42:51 GMT")
|
||||||
expected := time.Date(2014, time.March, 7, 17, 42, 51, 0, time.UTC)
|
expected := time.Date(2014, time.March, 7, 17, 42, 51, 0, time.UTC)
|
||||||
assertEqualTime(t, expected, date)
|
assertEqualTime(t, expected, date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("err should be nil")
|
t.Errorf("err should be nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ParseLayout2(t *testing.T) {
|
func Test_ParseLayout2(t *testing.T) {
|
||||||
date, err := parseTime("2014-02-05T23:33:34Z")
|
date, err := parseTime("2014-02-05T23:33:34Z")
|
||||||
expected := time.Date(2014, time.February, 5, 23, 33, 34, 0, time.UTC)
|
expected := time.Date(2014, time.February, 5, 23, 33, 34, 0, time.UTC)
|
||||||
assertEqualTime(t, expected, date)
|
assertEqualTime(t, expected, date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("err should be nil")
|
t.Errorf("err should be nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ParseLayout3(t *testing.T) {
|
func Test_ParseLayout3(t *testing.T) {
|
||||||
date, err := parseTime("Mon, 03 Mar 2014 02:12:25 +0000")
|
date, err := parseTime("Mon, 03 Mar 2014 02:12:25 +0000")
|
||||||
expected := time.Date(2014, time.March, 3, 2, 12, 25, 0, time.UTC)
|
expected := time.Date(2014, time.March, 3, 2, 12, 25, 0, time.UTC)
|
||||||
assertEqualTime(t, expected, date)
|
assertEqualTime(t, expected, date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("err should be nil")
|
t.Errorf("err should be nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ParseLayout4(t *testing.T) {
|
func Test_ParseLayout4(t *testing.T) {
|
||||||
date, err := parseTime("Fri, 21, Mar 2014 10:41")
|
date, err := parseTime("Fri, 21, Mar 2014 10:41")
|
||||||
expected := time.Date(2014, time.March, 21, 10, 41, 0, 0, time.UTC)
|
expected := time.Date(2014, time.March, 21, 10, 41, 0, 0, time.UTC)
|
||||||
assertEqualTime(t, expected, date)
|
assertEqualTime(t, expected, date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("err should be nil")
|
t.Errorf("err should be nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ParseLayout4_1(t *testing.T) {
|
func Test_ParseLayout4_1(t *testing.T) {
|
||||||
date, err := parseTime("Fri, 17, Jan 2014 11:1")
|
date, err := parseTime("Fri, 17, Jan 2014 11:1")
|
||||||
expected := time.Date(2014, time.January, 17, 11, 1, 0, 0, time.UTC)
|
expected := time.Date(2014, time.January, 17, 11, 1, 0, 0, time.UTC)
|
||||||
assertEqualTime(t, expected, date)
|
assertEqualTime(t, expected, date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("err should be nil")
|
t.Errorf("err should be nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ParseLayout4_2(t *testing.T) {
|
func Test_ParseLayout4_2(t *testing.T) {
|
||||||
date, err := parseTime("Thu, 9, Jan 2014 10:19")
|
date, err := parseTime("Thu, 9, Jan 2014 10:19")
|
||||||
expected := time.Date(2014, time.January, 9, 10, 19, 0, 0, time.UTC)
|
expected := time.Date(2014, time.January, 9, 10, 19, 0, 0, time.UTC)
|
||||||
assertEqualTime(t, expected, date)
|
assertEqualTime(t, expected, date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("err should be nil")
|
t.Errorf("err should be nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ParseLayout5(t *testing.T) {
|
func Test_ParseLayout5(t *testing.T) {
|
||||||
date, err := parseTime("22 Jul 2013 14:55:01 EST")
|
date, err := parseTime("22 Jul 2013 14:55:01 EST")
|
||||||
expected := time.Date(2013, time.July, 22, 14, 55, 1, 0, time.FixedZone("EST", -18000))
|
expected := time.Date(2013, time.July, 22, 14, 55, 1, 0, time.FixedZone("EST", -18000))
|
||||||
assertEqualTime(t, expected, date)
|
assertEqualTime(t, expected, date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("err should be nil")
|
t.Errorf("err should be nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertEqualTime(t *testing.T, expected, actual time.Time) {
|
func assertEqualTime(t *testing.T, expected, actual time.Time) {
|
||||||
if !expected.Equal(actual) {
|
if !expected.Equal(actual) {
|
||||||
t.Errorf("expected %v but was %v", expected, actual)
|
t.Errorf("expected %v but was %v", expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue