mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Cleaner pretty dates
This commit is contained in:
parent
59676ca344
commit
a82db2bea8
@ -2,11 +2,10 @@ package bamboohr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
//"time"
|
||||||
)
|
|
||||||
|
|
||||||
// DateFormat defines the format we expect to receive dates from BambooHR in
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
const DateFormat = "2006-01-02"
|
)
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
Employee Employee `xml:"employee"`
|
Employee Employee `xml:"employee"`
|
||||||
@ -20,7 +19,7 @@ func (item *Item) String() string {
|
|||||||
return fmt.Sprintf("Item: %s, %s, %s, %s", item.Type, item.Employee.Name, item.Start, item.End)
|
return fmt.Sprintf("Item: %s, %s, %s, %s", item.Type, item.Employee.Name, item.Start, item.End)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Public Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (item *Item) IsOneDay() bool {
|
func (item *Item) IsOneDay() bool {
|
||||||
return item.Start == item.End
|
return item.Start == item.End
|
||||||
@ -35,12 +34,9 @@ func (item *Item) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (item *Item) PrettyStart() string {
|
func (item *Item) PrettyStart() string {
|
||||||
newTime, _ := time.Parse(DateFormat, item.Start)
|
return wtf.PrettyDate(item.Start)
|
||||||
return fmt.Sprint(newTime.Format("Jan 2, 2006"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (item *Item) PrettyEnd() string {
|
func (item *Item) PrettyEnd() string {
|
||||||
newTime, _ := time.Parse(DateFormat, item.End)
|
return wtf.PrettyDate(item.End)
|
||||||
end := fmt.Sprint(newTime.Format("Jan 2, 2006"))
|
|
||||||
return end
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DateFormat defines the format we expect to receive dates from BambooHR in
|
||||||
|
const DateFormat = "2006-01-02"
|
||||||
|
|
||||||
func CenterText(str string, width int) string {
|
func CenterText(str string, width int) string {
|
||||||
return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))
|
return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))
|
||||||
}
|
}
|
||||||
@ -31,6 +34,11 @@ func ExecuteCommand(cmd *exec.Cmd) string {
|
|||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PrettyDate(dateStr string) string {
|
||||||
|
newTime, _ := time.Parse(DateFormat, dateStr)
|
||||||
|
return fmt.Sprint(newTime.Format("Jan 2, 2006"))
|
||||||
|
}
|
||||||
|
|
||||||
func Today() string {
|
func Today() string {
|
||||||
localNow := time.Now().Local()
|
localNow := time.Now().Local()
|
||||||
return localNow.Format("2006-01-02")
|
return localNow.Format("2006-01-02")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user