Initial commit: runnable Ask a Plumber First server.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package pacific
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
_ "time/tzdata"
|
||||
)
|
||||
|
||||
const Layout = "2006-01-02"
|
||||
|
||||
var Loc *time.Location
|
||||
|
||||
func init() {
|
||||
loc, err := time.LoadLocation("America/Los_Angeles")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
Loc = loc
|
||||
}
|
||||
|
||||
func HuntDate(t time.Time) string {
|
||||
return t.In(Loc).Format(Layout)
|
||||
}
|
||||
|
||||
func Today() string {
|
||||
return HuntDate(time.Now())
|
||||
}
|
||||
|
||||
func Yesterday() string {
|
||||
now := time.Now().In(Loc)
|
||||
y := time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, Loc)
|
||||
return y.Format(Layout)
|
||||
}
|
||||
|
||||
func Parse(date string) (time.Time, error) {
|
||||
return time.ParseInLocation(Layout, date, Loc)
|
||||
}
|
||||
|
||||
func Label(date string) string {
|
||||
t, err := Parse(date)
|
||||
if err != nil {
|
||||
return date
|
||||
}
|
||||
return t.Format("January 2, 2006")
|
||||
}
|
||||
|
||||
func IsToday(date string) bool {
|
||||
return date == Today()
|
||||
}
|
||||
|
||||
func IsYesterday(date string) bool {
|
||||
return date == Yesterday()
|
||||
}
|
||||
Reference in New Issue
Block a user