mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
Merge pull request #63 from icholy/master
improve error output formatting
This commit is contained in:
commit
4109f1d4ab
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/apcera/termtables"
|
"github.com/apcera/termtables"
|
||||||
@ -32,7 +33,7 @@ func main() {
|
|||||||
|
|
||||||
layout, err := dateparse.ParseFormat(datestr)
|
layout, err := dateparse.ParseFormat(datestr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
zonename, _ := time.Now().In(time.Local).Zone()
|
zonename, _ := time.Now().In(time.Local).Zone()
|
||||||
@ -44,7 +45,7 @@ func main() {
|
|||||||
// time-parsing in go
|
// time-parsing in go
|
||||||
l, err := time.LoadLocation(timezone)
|
l, err := time.LoadLocation(timezone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
fatal(err)
|
||||||
}
|
}
|
||||||
loc = l
|
loc = l
|
||||||
zonename, _ := time.Now().In(l).Zone()
|
zonename, _ := time.Now().In(l).Zone()
|
||||||
@ -77,10 +78,6 @@ func main() {
|
|||||||
fmt.Println(table.Render())
|
fmt.Println(table.Render())
|
||||||
}
|
}
|
||||||
|
|
||||||
func stuff() (string, string) {
|
|
||||||
return "more", "stuff"
|
|
||||||
}
|
|
||||||
|
|
||||||
type parser func(datestr string, loc *time.Location, utc bool) string
|
type parser func(datestr string, loc *time.Location, utc bool) string
|
||||||
|
|
||||||
func parseLocal(datestr string, loc *time.Location, utc bool) string {
|
func parseLocal(datestr string, loc *time.Location, utc bool) string {
|
||||||
@ -127,3 +124,8 @@ func parseStrict(datestr string, loc *time.Location, utc bool) string {
|
|||||||
}
|
}
|
||||||
return t.String()
|
return t.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fatal(err error) {
|
||||||
|
fmt.Printf("fatal: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user