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

37 lines
770 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
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-01-26 04:09:21 -08:00
return "{{ .CurrentDate | date \"" + t.props.GetString(TimeFormat, "15:04:05") + "\" }}"
}
func (t *Time) Enabled() bool {
// if no date set, use now(unit testing)
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
}