oh-my-posh/src/segment_time.go

33 lines
661 B
Go
Raw Normal View History

2019-03-13 04:14:30 -07:00
package main
import "time"
2019-03-13 04:14:30 -07:00
type tempus struct {
props Properties
env 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
2019-03-13 04:14:30 -07:00
TimeFormat Property = "time_format"
)
func (t *tempus) template() string {
return "{{ .CurrentDate | date \"" + t.props.getString(TimeFormat, "15:04:05") + "\" }}"
}
2019-03-13 04:14:30 -07:00
func (t *tempus) 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
}
2022-01-01 11:09:52 -08:00
func (t *tempus) init(props Properties, env Environment) {
2019-03-13 04:14:30 -07:00
t.props = props
t.env = env
}