Skip to content

Commit

Permalink
Github actions replacing travis
Browse files Browse the repository at this point in the history
  • Loading branch information
mchirico authored May 29, 2022
1 parent 96f9913 commit 06c5564
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[![Build Status](https://travis-ci.org/mchirico/date.svg?branch=develop)](https://travis-ci.org/mchirico/date)
[![codecov](https://codecov.io/gh/mchirico/date/branch/develop/graph/badge.svg)](https://codecov.io/gh/mchirico/date)
[![Go](https://github.com/mchirico/date/actions/workflows/go.yml/badge.svg?branch=develop)](https://github.com/mchirico/date/actions/workflows/go.yml)

# date
Go Dateparse
Expand Down
12 changes: 11 additions & 1 deletion parse/dateparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func ifEpoch(s string) (time.Time, error) {
// DateTimeParse -- variety of expected dates
type DateTimeParse string

var lastused = "2006-01-02T15:04:05+07:00"
var layout = []string{

"January 2 2006 3:04 pm",
Expand Down Expand Up @@ -212,7 +213,7 @@ var layout = []string{
"2006-01-02T15:04:05Z07:00",

// Leave this last
//"2006-01-02T15:04:05.999999999Z07:00",
"2006-01-02T15:04:05.999999999Z07:00",
}

// getTime --
Expand All @@ -226,9 +227,14 @@ func (s DateTimeParse) GetTime() (time.Time, error) {
st := strings.Join(strings.Fields(string(s)), " ")
st = strings.ReplaceAll(st, ",", "")

if t, err := time.Parse(lastused, st); err == nil {
return t, err
}

for _, l := range layout {
t, err := time.Parse(l, st)
if err == nil {
lastused = l
return t, err
}

Expand All @@ -254,9 +260,13 @@ func (s DateTimeParse) GetTimeInLocation(zone string) (time.Time, error) {
st := strings.Join(strings.Fields(string(s)), " ")
//fmt.Printf("-->%s\n", st)

if t, err := time.ParseInLocation(lastused, st, loc); err == nil {
return t, err
}
for _, l := range layout {
t, err := time.ParseInLocation(l, st, loc)
if err == nil {
lastused = l
return t, err
}

Expand Down
6 changes: 6 additions & 0 deletions parse/dateparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func TestDateTimeParse(t *testing.T) {
t.Fatalf("Time gave error")
}

s = " Wed, 9 Sep 2020 11:34:00 -0400 (EDT)"
tt, err = DateTimeParse(s).GetTimeLoc()
if err != nil {
t.Fatalf("Time gave error")
}

t3, _ := DateTimeParse(s).GetTimeLocSquish()
fmt.Printf("Time: %v \n",
t3)
Expand Down

0 comments on commit 06c5564

Please sign in to comment.