oh-my-posh/src/segments/time.go

39 lines
800 B
Go
Raw Normal View History

2022-01-26 06:54:36 -08:00
package segments
2019-03-13 04:14:30 -07:00
import (
"oh-my-posh/environment"
"oh-my-posh/properties"
"time"
)
2019-03-13 04:14:30 -07:00
2022-01-26 05:10:18 -08:00
type Time struct {
props properties.Properties
env environment.Environment
CurrentDate time.Time
2022-02-01 03:10:46 -08:00
Format string
2019-03-13 04:14:30 -07:00
}
const (
// TimeFormat uses the reference time Mon Jan 2 15:04:05 MST 2006 to show the pattern with which to format the current time
TimeFormat properties.Property = "time_format"
2019-03-13 04:14:30 -07:00
)
func (t *Time) Template() string {
2022-02-01 05:07:58 -08:00
return " {{ .CurrentDate | date .Format }} "
}
func (t *Time) Enabled() bool {
// if no date set, use now(unit testing)
2022-02-01 03:10:46 -08:00
t.Format = t.props.GetString(TimeFormat, "15:04:05")
if t.CurrentDate.IsZero() {
t.CurrentDate = time.Now()
}
2022-01-22 10:46:56 -08:00
return true
}
func (t *Time) Init(props properties.Properties, env environment.Environment) {
2019-03-13 04:14:30 -07:00
t.props = props
t.env = env
}