diff --git a/go.mod b/go.mod index b22ec623..dc18dd0c 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,6 @@ require ( github.com/godbus/dbus v4.1.0+incompatible // indirect github.com/google/go-github/v26 v26.1.3 github.com/gophercloud/gophercloud v0.5.0 // indirect - github.com/hashicorp/go-cleanhttp v0.5.1 // indirect github.com/hekmon/cunits v2.0.1+incompatible // indirect github.com/hekmon/transmissionrpc v0.0.0-20190525133028-1d589625bacd github.com/imdario/mergo v0.3.8 // indirect diff --git a/go.sum b/go.sum index 94efa37d..0d36a641 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,6 @@ github.com/adlio/trello v1.7.0 h1:syLRJ27wCM8URf7zOBWGr981cG+dpmLSyMqjEoQc+4g= github.com/adlio/trello v1.7.0/go.mod h1:l2068AhUuUuQ9Vsb95ECMueHThYyAj4e85lWPmr2/LE= github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U= github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI= -github.com/alecthomas/chroma v0.7.1 h1:G1i02OhUbRi2nJxcNkwJaY/J1gHXj9tt72qN6ZouLFQ= -github.com/alecthomas/chroma v0.7.1/go.mod h1:gHw09mkX1Qp80JlYbmN9L3+4R5o6DJJ3GRShh+AICNc= github.com/alecthomas/chroma v0.7.2 h1:B76NU/zbQYIUhUowbi4fmvREmDUJLsUzKWTZmQd3ABY= github.com/alecthomas/chroma v0.7.2/go.mod h1:fv5SzZPFJbwp2NXJWpFIX7DZS4HgV1K4ew4Pc2OZD9s= github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo= @@ -132,10 +130,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= -github.com/digitalocean/godo v1.32.0 h1:ljfhYi/IqDYiZcBYV7nUPzw1Q7NlmPSFDtI69UeRThk= -github.com/digitalocean/godo v1.32.0/go.mod h1:iJnN9rVu6K5LioLxLimlq0uRI+y/eAQjROUmeU/r0hY= -github.com/digitalocean/godo v1.33.1 h1:W5e7EgW8EVOM+ycZ6z+LU/WTZrxohIkgxbVwLOU/Q6s= -github.com/digitalocean/godo v1.33.1/go.mod h1:gfLm3JSupWD9V/ibQygXWW3IVz7hranzckH5UimhZsI= github.com/digitalocean/godo v1.34.0 h1:OXJhLLJS2VTB5SziTyCq8valKVZ0uBHCFQsDW3/HF78= github.com/digitalocean/godo v1.34.0/go.mod h1:gfLm3JSupWD9V/ibQygXWW3IVz7hranzckH5UimhZsI= github.com/digitalocean/godo v1.35.1 h1:3P5timR4LTqcCafzrCgV2j83ck4aWb937ybFC7YQVFw= @@ -305,6 +299,7 @@ github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FK github.com/hashicorp/go-cleanhttp v0.0.0-20160407174126-ad28ea4487f0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= @@ -477,8 +472,6 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d h1:AREM5mwr4u1 github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU= github.com/ncw/swift v0.0.0-20171019114456-c95c6e5c2d1a h1:SAjW6pL/9NssyKM1Qvyy5/V4kR3z76qlTbaqJLixhP4= github.com/ncw/swift v0.0.0-20171019114456-c95c6e5c2d1a/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= -github.com/nicklaw5/helix v0.5.7 h1:DvNyoKkuLYrqZv5/yugL18Ud99UeQoXzzAsg4OwU8uY= -github.com/nicklaw5/helix v0.5.7/go.mod h1:nRcok4VLg8ONQYW/iXBZ24wcfiJjTlDbhgk0ZatOrUY= github.com/nicklaw5/helix v0.5.8 h1:RG1vV/XDI6Kc0V/KvoUzRb3Q/7rmAQvVuisfxxYg1ZY= github.com/nicklaw5/helix v0.5.8/go.mod h1:nRcok4VLg8ONQYW/iXBZ24wcfiJjTlDbhgk0ZatOrUY= github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= @@ -595,8 +588,6 @@ github.com/sethgrid/pester v0.0.0-20171127025028-760f8913c048/go.mod h1:Ad7IjTpv github.com/sguiheux/go-coverage v0.0.0-20190710153556-287b082a7197 h1:qu90yDtRE5WEfRT5mn9v0Xz9RaopLguhbPwZKx4dHq8= github.com/sguiheux/go-coverage v0.0.0-20190710153556-287b082a7197/go.mod h1:0hhKrsUsoT7yvxwNGKa+TSYNA26DNWMqReeZEQq/9FI= github.com/shirou/gopsutil v0.0.0-20170406131756-e49a95f3d5f8/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/shirou/gopsutil v2.20.2+incompatible h1:ucK79BhBpgqQxPASyS2cu9HX8cfDVljBN1WWFvbNvgY= -github.com/shirou/gopsutil v2.20.2+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v2.20.3+incompatible h1:0JVooMPsT7A7HqEYdydp/OfjSOYSjhXV7w1hkKj/NPQ= github.com/shirou/gopsutil v2.20.3+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= @@ -657,10 +648,6 @@ github.com/wtfutil/spotigopher v0.0.0-20191127141047-7d8168fe103a/go.mod h1:AlO4 github.com/wtfutil/todoist v0.0.2-0.20191216004217-0ec29ceda61a h1:nD8ALd4TSo+zPHK5MqQWFj01G8fMMHFfC3rWvoq/9JA= github.com/wtfutil/todoist v0.0.2-0.20191216004217-0ec29ceda61a/go.mod h1:YuuGLJSsTK6DGBD5Zaf3J8LSMfpEC2WtzYPey3XVOdI= github.com/xanzy/go-gitlab v0.15.0/go.mod h1:8zdQa/ri1dfn8eS3Ir1SyfvOKlw7WBJ8DVThkpGiXrs= -github.com/xanzy/go-gitlab v0.28.0 h1:nsyjDVvBrP4KRXEN4b1m1ewiqmTNL4BOWW041nKGV7k= -github.com/xanzy/go-gitlab v0.28.0/go.mod h1:t4Bmvnxj7k37S4Y17lfLx+nLqkf/oQwT2HagfWKv5Og= -github.com/xanzy/go-gitlab v0.29.0 h1:9tMvAkG746eIlzcdpnRgpcKPA1woUDmldMIjR/E5OWM= -github.com/xanzy/go-gitlab v0.29.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug= github.com/xanzy/go-gitlab v0.31.0 h1:+nHztQuCXGSMluKe5Q9IRaPdz6tO8O0gMkQ0vqGpiBk= github.com/xanzy/go-gitlab v0.31.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= @@ -810,8 +797,6 @@ google.golang.org/api v0.3.2/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMt google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.20.0 h1:jz2KixHX7EcCPiQrySzPdnYT7DbINAypCqKZ1Z7GM40= -google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= google.golang.org/api v0.21.0 h1:zS+Q/CJJnVlXpXQVIz+lH0ZT2lBuT2ac7XD8Y/3w6hY= google.golang.org/api v0.21.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= google.golang.org/api v0.22.0 h1:J1Pl9P2lnmYFSJvgs70DKELqHNh8CNWXPbud4njEE2s= diff --git a/modules/gcal/cal_event.go b/modules/gcal/cal_event.go index 19944974..2c122300 100644 --- a/modules/gcal/cal_event.go +++ b/modules/gcal/cal_event.go @@ -1,6 +1,7 @@ package gcal import ( + "fmt" "time" "github.com/wtfutil/wtf/utils" @@ -97,17 +98,23 @@ func (calEvent *CalEvent) Start() time.Time { return start } -func (calEvent *CalEvent) Timestamp(hourFormat string) string { +func (calEvent *CalEvent) Timestamp(hourFormat string, showEndTime bool) 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) + endTime, _ := time.Parse(time.RFC3339, calEvent.event.End.DateTime) timeFormat := utils.MinimumTimeFormat24 if hourFormat == "12" { timeFormat = utils.MinimumTimeFormat12 } + + if showEndTime { + return fmt.Sprintf("%s-%s", startTime.Format(timeFormat), endTime.Format(timeFormat)) + } + return startTime.Format(timeFormat) } diff --git a/modules/gcal/display.go b/modules/gcal/display.go index 34e62a2c..effb5f15 100644 --- a/modules/gcal/display.go +++ b/modules/gcal/display.go @@ -37,7 +37,8 @@ func (widget *Widget) content() (string, string, bool) { continue } - timestamp := fmt.Sprintf("[%s]%s", widget.eventTimeColor(calEvent), calEvent.Timestamp(widget.settings.hourFormat)) + ts := calEvent.Timestamp(widget.settings.hourFormat, widget.settings.showEndTime) + timestamp := fmt.Sprintf("[%s]%s", widget.eventTimeColor(calEvent), ts) if calEvent.AllDay() { timestamp = "" } diff --git a/modules/gcal/display_test.go b/modules/gcal/display_test.go new file mode 100644 index 00000000..e2dc71c1 --- /dev/null +++ b/modules/gcal/display_test.go @@ -0,0 +1,58 @@ +package gcal + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/wtfutil/wtf/cfg" + "google.golang.org/api/calendar/v3" +) + +func Test_display_content(t *testing.T) { + startTime := &calendar.EventDateTime{DateTime: "1986-04-19T01:00:00.00Z"} + endTime := &calendar.EventDateTime{DateTime: "1986-04-19T02:00:00.00Z"} + event := &calendar.Event{Summary: "Foo", Start: startTime, End: endTime} + + testCases := []struct { + descriptionWanted string + events []*CalEvent + name string + settings *Settings + }{ + { + name: "Event content without any events", + settings: &Settings{common: &cfg.Common{}}, + events: nil, + descriptionWanted: "No calendar events", + }, + { + name: "Event content with a single event, without end times displayed", + settings: &Settings{common: &cfg.Common{}, showEndTime: false}, + events: []*CalEvent{NewCalEvent(event)}, + descriptionWanted: "[]Saturday, Apr 19\n []01:00 []Foo[white]\n \n", + }, + { + name: "Event content with a single event without showEndTime explictily set in settings", + settings: &Settings{common: &cfg.Common{}}, + events: []*CalEvent{NewCalEvent(event)}, + descriptionWanted: "[]Saturday, Apr 19\n []01:00 []Foo[white]\n \n", + }, + { + name: "Event content with a single event with end times displayed", + settings: &Settings{common: &cfg.Common{}, showEndTime: true}, + events: []*CalEvent{NewCalEvent(event)}, + descriptionWanted: "[]Saturday, Apr 19\n []01:00-02:00 []Foo[white]\n \n", + }, + } + + for _, tt := range testCases { + t.Run(tt.name, func(t *testing.T) { + w := &Widget{calEvents: tt.events, settings: tt.settings, err: nil} + _, description, err := w.content() + + assert.Equal(t, false, err, tt.name) + assert.Equal(t, tt.descriptionWanted, description, tt.name) + }) + } + +} diff --git a/modules/gcal/settings.go b/modules/gcal/settings.go index 3fa39300..82569e6d 100644 --- a/modules/gcal/settings.go +++ b/modules/gcal/settings.go @@ -35,6 +35,7 @@ type Settings struct { secretFile string `help:"Your Google client secret JSON file." values:"A string representing a file path to the JSON secret file."` showAllDay bool `help:"Whether or not to display all-day events" values:"true or false" optional:"true" default:"true"` showDeclined bool `help:"Whether or not to display events you’ve declined to attend." values:"true or false" optional:"true"` + showEndTime bool `help:"Display the end time of events, in addition to start time." values:"true or false" optional:"true" default:"false"` withLocation bool `help:"Whether or not to show the location of the appointment." values:"true or false"` timezone string `help:"The time zone used to display calendar event times." values:"A valid TZ database time zone string" optional:"true"` calendarReadLevel string `help:"The calender read level specifies level you want to read events. Default: writer " values:"reader, writer" optional:"true"` @@ -54,6 +55,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co multiCalendar: ymlConfig.UBool("multiCalendar", false), secretFile: ymlConfig.UString("secretFile", ""), showAllDay: ymlConfig.UBool("showAllDay", true), + showEndTime: ymlConfig.UBool("showEndTime", false), showDeclined: ymlConfig.UBool("showDeclined", false), withLocation: ymlConfig.UBool("withLocation", true), timezone: ymlConfig.UString("timezone", ""),