2022-01-26 06:54:36 -08:00
|
|
|
package segments
|
2019-03-13 04:14:30 -07:00
|
|
|
|
2022-01-26 01:23:18 -08:00
|
|
|
import (
|
|
|
|
"oh-my-posh/environment"
|
2022-01-26 04:53:35 -08:00
|
|
|
"oh-my-posh/properties"
|
2022-01-26 01:23:18 -08:00
|
|
|
"time"
|
|
|
|
)
|
2019-03-13 04:14:30 -07:00
|
|
|
|
2022-01-26 05:10:18 -08:00
|
|
|
type Time struct {
|
2022-01-26 04:53:35 -08:00
|
|
|
props properties.Properties
|
2022-01-26 01:23:18 -08:00
|
|
|
env environment.Environment
|
2022-01-23 12:37:51 -08:00
|
|
|
|
|
|
|
CurrentDate time.Time
|
2022-02-01 03:10:46 -08:00
|
|
|
Format string
|
2019-03-13 04:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2020-11-12 00:43:32 -08:00
|
|
|
// TimeFormat uses the reference time Mon Jan 2 15:04:05 MST 2006 to show the pattern with which to format the current time
|
2022-01-26 04:53:35 -08:00
|
|
|
TimeFormat properties.Property = "time_format"
|
2019-03-13 04:14:30 -07:00
|
|
|
)
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (t *Time) Template() string {
|
2022-02-01 05:07:58 -08:00
|
|
|
return " {{ .CurrentDate | date .Format }} "
|
2022-01-23 12:37:51 -08:00
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (t *Time) Enabled() bool {
|
2021-03-16 03:36:05 -07:00
|
|
|
// 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")
|
2021-03-16 03:36:05 -07:00
|
|
|
if t.CurrentDate.IsZero() {
|
|
|
|
t.CurrentDate = time.Now()
|
|
|
|
}
|
2022-01-22 10:46:56 -08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (t *Time) Init(props properties.Properties, env environment.Environment) {
|
2019-03-13 04:14:30 -07:00
|
|
|
t.props = props
|
|
|
|
t.env = env
|
|
|
|
}
|