Skip to content

Commit cfbda57

Browse files
authored
fix: Parse 24h time format from schedule cron in CLI (coder#2586)
* fix: parse 24h time format from schedule cron in cli * add unit test
1 parent b7eeb43 commit cfbda57

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

coderd/autobuild/schedule/schedule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (s Schedule) Time() string {
144144
minute := strings.Fields(s.cronStr)[0]
145145
hour := strings.Fields(s.cronStr)[1]
146146
maybeTime := fmt.Sprintf("%s:%s", hour, minute)
147-
t, err := time.ParseInLocation("3:4", maybeTime, s.sched.Location)
147+
t, err := time.ParseInLocation("15:4", maybeTime, s.sched.Location)
148148
if err != nil {
149149
// return the original cronspec for minute and hour, who knows what's in there!
150150
return fmt.Sprintf("cron(%s %s)", minute, hour)

coderd/autobuild/schedule/schedule_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ func Test_Weekly(t *testing.T) {
5050
expectedString: "CRON_TZ=UTC 30 9 * * 1-5",
5151
expectedTime: "9:30AM",
5252
},
53+
{
54+
name: "24h format",
55+
spec: "30 13 * * 1-5",
56+
at: time.Date(2022, 4, 1, 13, 29, 0, 0, time.UTC),
57+
expectedNext: time.Date(2022, 4, 1, 13, 30, 0, 0, time.UTC),
58+
expectedMin: 24 * time.Hour,
59+
expectedDaysOfWeek: "Mon-Fri",
60+
expectedError: "",
61+
expectedCron: "30 13 * * 1-5",
62+
expectedLocation: time.UTC,
63+
expectedString: "CRON_TZ=UTC 30 13 * * 1-5",
64+
expectedTime: "1:30PM",
65+
},
5366
{
5467
name: "convoluted with timezone",
5568
spec: "CRON_TZ=US/Central */5 12-18 * * 1,3,6",
@@ -141,6 +154,7 @@ func Test_Weekly(t *testing.T) {
141154
require.Equal(t, testCase.expectedString, actual.String())
142155
require.Equal(t, testCase.expectedMin, actual.Min())
143156
require.Equal(t, testCase.expectedDaysOfWeek, actual.DaysOfWeek())
157+
require.Equal(t, testCase.expectedTime, actual.Time())
144158
} else {
145159
require.EqualError(t, err, testCase.expectedError)
146160
require.Nil(t, actual)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy