@@ -15,12 +15,12 @@ import (
15
15
)
16
16
17
17
const autostartDescriptionLong = `To have your workspace build automatically at a regular time you can enable autostart.
18
- When enabling autostart, enter a schedule in the format: start-time [day-of-week] [timezone ].
18
+ When enabling autostart, enter a schedule in the format: start-time [day-of-week] [location ].
19
19
* Start-time (required) is accepted either in 12-hour (hh:mm{am|pm}) format, or 24-hour format hh:mm.
20
20
* Day-of-week (optional) allows specifying in the cron format, e.g. 1,3,5 or Mon-Fri.
21
21
Aliases such as @daily are not supported.
22
22
Default: * (every day)
23
- * Timezone (optional) must be a valid location in the IANA timezone database.
23
+ * Location (optional) must be a valid location in the IANA timezone database.
24
24
If omitted, we will fall back to either the TZ environment variable or /etc/localtime.
25
25
You can check your corresponding location by visiting https://ipinfo.io - it shows in the demo widget on the right.
26
26
`
@@ -85,7 +85,7 @@ func autostartShow() *cobra.Command {
85
85
86
86
func autostartSet () * cobra.Command {
87
87
cmd := & cobra.Command {
88
- Use : "set <workspace_name> <start-time> [day-of-week] [timezone ]" ,
88
+ Use : "set <workspace_name> <start-time> [day-of-week] [location ]" ,
89
89
Args : cobra .RangeArgs (2 , 4 ),
90
90
RunE : func (cmd * cobra.Command , args []string ) error {
91
91
client , err := createClient (cmd )
@@ -156,6 +156,7 @@ func autostartUnset() *cobra.Command {
156
156
157
157
var errInvalidScheduleFormat = xerrors .New ("Schedule must be in the format Mon-Fri 09:00AM America/Chicago" )
158
158
var errInvalidTimeFormat = xerrors .New ("Start time must be in the format hh:mm[am|pm] or HH:MM" )
159
+ var errUnsupportedTimezone = xerrors .New ("The location you provided looks like a timezone. Check https://ipinfo.io for your location." )
159
160
160
161
// parseCLISchedule parses a schedule in the format HH:MM{AM|PM} [DOW] [LOCATION]
161
162
func parseCLISchedule (parts ... string ) (* schedule.Schedule , error ) {
@@ -178,6 +179,10 @@ func parseCLISchedule(parts ...string) (*schedule.Schedule, error) {
178
179
dayOfWeek = parts [1 ]
179
180
loc , err = time .LoadLocation (parts [2 ])
180
181
if err != nil {
182
+ _ , err = time .Parse ("MST" , parts [2 ])
183
+ if err == nil {
184
+ return nil , errUnsupportedTimezone
185
+ }
181
186
return nil , xerrors .Errorf ("Invalid timezone %q specified: a valid IANA timezone is required" , parts [2 ])
182
187
}
183
188
case 2 :
@@ -217,15 +222,20 @@ func parseCLISchedule(parts ...string) (*schedule.Schedule, error) {
217
222
}
218
223
219
224
func parseTime (s string ) (time.Time , error ) {
220
- // Assume only time provided, HH:MM[AM|PM]
221
- t , err := time .Parse (time .Kitchen , s )
222
- if err == nil {
223
- return t , nil
224
- }
225
- // Try 24-hour format without AM/PM suffix.
226
- t , err = time .Parse ("15:04" , s )
227
- if err != nil {
228
- return time.Time {}, errInvalidTimeFormat
225
+ // Try a number of possible layouts.
226
+ for _ , layout := range []string {
227
+ time .Kitchen , // 03:04PM
228
+ "15:04" ,
229
+ "1504" ,
230
+ "3pm" ,
231
+ "3PM" ,
232
+ "3:04pm" ,
233
+ "3:04PM" ,
234
+ } {
235
+ t , err := time .Parse (layout , s )
236
+ if err == nil {
237
+ return t , nil
238
+ }
229
239
}
230
- return t , nil
240
+ return time. Time {}, errInvalidTimeFormat
231
241
}
0 commit comments