1
0
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:
Chris Cummer 2019-10-01 21:34:52 -07:00
parent 301eddafd4
commit 7c2d6b4c42
5 changed files with 17 additions and 8 deletions

View File

@ -24,10 +24,11 @@ type Settings struct {
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
settings := Settings{ settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
color: ymlConfig.UString("color"), color: ymlConfig.UString("color"),
font: ymlConfig.UString("font"), font: ymlConfig.UString("font"),
hourFormat: ymlConfig.UString("hourFormat"), hourFormat: ymlConfig.UString("hourFormat", "24"),
} }
return &settings return &settings

View File

@ -97,12 +97,17 @@ func (calEvent *CalEvent) Start() time.Time {
return start return start
} }
func (calEvent *CalEvent) Timestamp() string { func (calEvent *CalEvent) Timestamp(hourFormat string) string {
if calEvent.AllDay() { if calEvent.AllDay() {
startTime, _ := time.ParseInLocation("2006-01-02", calEvent.event.Start.Date, time.Local) startTime, _ := time.ParseInLocation("2006-01-02", calEvent.event.Start.Date, time.Local)
return startTime.Format(utils.FriendlyDateFormat) return startTime.Format(utils.FriendlyDateFormat)
} }
startTime, _ := time.Parse(time.RFC3339, calEvent.event.Start.DateTime) 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)
} }

View File

@ -48,7 +48,7 @@ func (widget *Widget) content() (string, string, bool) {
} }
for _, calEvent := range calEvents { 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() { if calEvent.AllDay() {
timestamp = "" timestamp = ""
} }

View File

@ -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"` 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."` 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"` 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"` 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."` 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 youve declined to attend." values:"true or false" optional:"true"` showDeclined bool `help:"Whether or not to display events youve 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), displayResponseStatus: ymlConfig.UBool("displayResponseStatus", true),
email: ymlConfig.UString("email", ""), email: ymlConfig.UString("email", ""),
eventCount: ymlConfig.UInt("eventCount", 10), eventCount: ymlConfig.UInt("eventCount", 10),
hourFormat: ymlConfig.UString("hourFormat", "24"),
multiCalendar: ymlConfig.UBool("multiCalendar", false), multiCalendar: ymlConfig.UBool("multiCalendar", false),
secretFile: ymlConfig.UString("secretFile", ""), secretFile: ymlConfig.UString("secretFile", ""),
showDeclined: ymlConfig.UBool("showDeclined", false), showDeclined: ymlConfig.UBool("showDeclined", false),

View File

@ -13,9 +13,10 @@ import (
) )
const ( const (
SimpleDateFormat = "Jan 2" SimpleDateFormat = "Jan 2"
SimpleTimeFormat = "15:04 MST" SimpleTimeFormat = "15:04 MST"
MinimumTimeFormat = "15:04" MinimumTimeFormat12 = "3:04 PM"
MinimumTimeFormat24 = "15:04"
FullDateFormat = "Monday, Jan 2" FullDateFormat = "Monday, Jan 2"
FriendlyDateFormat = "Mon, Jan 2" FriendlyDateFormat = "Mon, Jan 2"