Skip to content

Commit f7ccf28

Browse files
committed
log: extend run --at/-@ timezone parsing format support
* support multiple ISO8601 timezones formats: `-01`, `-0100` or `-01:00`
1 parent 097328c commit f7ccf28

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

  • rd-cli-tool/src

rd-cli-tool/src/main/java/org/rundeck/client/tool/commands/Run.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public Integer call() throws IOException, InputError {
161161
request.setOptions(jobopts);
162162
if (options.isRunAtDate()) {
163163
try {
164-
runat = options.getRunAtDate().toDate("yyyy-MM-dd'T'HH:mm:ssXX");
164+
runat = options.getRunAtDate().toDate();
165165
request.setRunAtTime(runat);
166166
} catch (ParseException e) {
167167
throw new InputError("-@/--at date format is not valid", e);

rd-cli-tool/src/test/groovy/org/rundeck/client/tool/commands/RunSpec.groovy

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.rundeck.client.tool.commands
1818

1919
import org.rundeck.client.api.RundeckApi
20+
import org.rundeck.client.api.model.DateInfo
2021
import org.rundeck.client.api.model.ExecOutput
2122
import org.rundeck.client.api.model.Execution
2223
import org.rundeck.client.api.model.JobFileUploadResult
@@ -33,6 +34,9 @@ import retrofit2.Retrofit
3334
import retrofit2.mock.Calls
3435
import spock.lang.Specification
3536
import spock.lang.Unroll
37+
38+
import java.text.SimpleDateFormat
39+
3640
/**
3741
* @author greg
3842
* @since 12/13/16
@@ -111,6 +115,43 @@ class RunSpec extends Specification {
111115
0 * api._(*_)
112116
result == 0
113117

118+
}
119+
def "run at time supports multiple formats"() {
120+
121+
given:
122+
//round to seconds, since the date format does not include milliseconds
123+
long millis = Math.floor(System.currentTimeMillis() / 1000L).toLong()
124+
Date timeToRun = new Date((millis*1000L)+(3L*1000L*60L*24L))
125+
String dateString = new SimpleDateFormat(dateFormat).format(timeToRun)
126+
127+
def api = Mock(RundeckApi)
128+
RdTool rdTool = setupMock(api, 20)
129+
def out = Mock(CommandOutput)
130+
Run command = new Run()
131+
command.rdTool = rdTool
132+
command.rdOutput = out
133+
134+
command.options.project = 'ProjectName'
135+
command.options.job = 'a group/path/a job'
136+
command.options.setRunAtDate(new DateInfo(dateString))
137+
138+
when:
139+
def result = command.call()
140+
141+
then:
142+
1 * api.listJobs('ProjectName', null, null, 'a job', 'a group/path') >>
143+
Calls.response([new JobItem(id: 'fakeid')])
144+
1 * api.runJob('fakeid', {
145+
it.runAtTime==timeToRun
146+
}) >> Calls.response(new Execution(id: 123, description: ''))
147+
0 * api._(*_)
148+
result == 0
149+
where:
150+
dateFormat | _
151+
DateInfo.ISO | _
152+
DateInfo.ISO1 | _
153+
DateInfo.ISO2 | _
154+
114155
}
115156

116157
def "run command loglevel debug"() {

0 commit comments

Comments
 (0)