mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-665 Add time format setting for gCal module
Allows the user to specify either "12" or "24" to set whether or not to display times in AM/PM format or 24-hour format. Example: gcal: enabled: true timeFormat: "12" refreshInterval: 360 Fixes #665
This commit is contained in:
parent
301eddafd4
commit
7c2d6b4c42
@ -25,9 +25,10 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
|
||||
|
||||
color: ymlConfig.UString("color"),
|
||||
font: ymlConfig.UString("font"),
|
||||
hourFormat: ymlConfig.UString("hourFormat"),
|
||||
hourFormat: ymlConfig.UString("hourFormat", "24"),
|
||||
}
|
||||
|
||||
return &settings
|
||||
|
@ -97,12 +97,17 @@ func (calEvent *CalEvent) Start() time.Time {
|
||||
return start
|
||||
}
|
||||
|
||||
func (calEvent *CalEvent) Timestamp() string {
|
||||
func (calEvent *CalEvent) Timestamp(hourFormat string) string {
|
||||
if calEvent.AllDay() {
|
||||
startTime, _ := time.ParseInLocation("2006-01-02", calEvent.event.Start.Date, time.Local)
|
||||
return startTime.Format(utils.FriendlyDateFormat)
|
||||
}
|
||||
|
||||
startTime, _ := time.Parse(time.RFC3339, calEvent.event.Start.DateTime)
|
||||
return startTime.Format(utils.MinimumTimeFormat)
|
||||
|
||||
timeFormat := utils.MinimumTimeFormat24
|
||||
if hourFormat == "12" {
|
||||
timeFormat = utils.MinimumTimeFormat12
|
||||
}
|
||||
return startTime.Format(timeFormat)
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func (widget *Widget) content() (string, string, bool) {
|
||||
}
|
||||
|
||||
for _, calEvent := range calEvents {
|
||||
timestamp := fmt.Sprintf("[%s]%s", widget.eventTimeColor(calEvent), calEvent.Timestamp())
|
||||
timestamp := fmt.Sprintf("[%s]%s", widget.eventTimeColor(calEvent), calEvent.Timestamp(widget.settings.hourFormat))
|
||||
if calEvent.AllDay() {
|
||||
timestamp = ""
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ type Settings struct {
|
||||
displayResponseStatus bool `help:"Whether or not to display your response status to the calendar event." values:"true or false" optional:"true"`
|
||||
email string `help:"The email address associated with your Google account. Necessary for determining 'responseStatus'." values:"A valid email address string."`
|
||||
eventCount int `help:"The number of calendar events to display." values:"A positive integer, 0..n." optional:"true"`
|
||||
hourFormat string `help:"The format of the clock." values:"12 or 24"`
|
||||
multiCalendar bool `help:"Whether or not to display your primary calendar or all calendars you have access to." values:"true or false" optional:"true"`
|
||||
secretFile string `help:"Your Google client secret JSON file." values:"A string representing a file path to the JSON secret file."`
|
||||
showDeclined bool `help:"Whether or not to display events you’ve declined to attend." values:"true or false" optional:"true"`
|
||||
@ -48,6 +49,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
||||
displayResponseStatus: ymlConfig.UBool("displayResponseStatus", true),
|
||||
email: ymlConfig.UString("email", ""),
|
||||
eventCount: ymlConfig.UInt("eventCount", 10),
|
||||
hourFormat: ymlConfig.UString("hourFormat", "24"),
|
||||
multiCalendar: ymlConfig.UBool("multiCalendar", false),
|
||||
secretFile: ymlConfig.UString("secretFile", ""),
|
||||
showDeclined: ymlConfig.UBool("showDeclined", false),
|
||||
|
@ -15,7 +15,8 @@ import (
|
||||
const (
|
||||
SimpleDateFormat = "Jan 2"
|
||||
SimpleTimeFormat = "15:04 MST"
|
||||
MinimumTimeFormat = "15:04"
|
||||
MinimumTimeFormat12 = "3:04 PM"
|
||||
MinimumTimeFormat24 = "15:04"
|
||||
|
||||
FullDateFormat = "Monday, Jan 2"
|
||||
FriendlyDateFormat = "Mon, Jan 2"
|
||||
|
Loading…
x
Reference in New Issue
Block a user