diff --git a/src/main/java/org/rundeck/client/api/model/DateInfo.java b/src/main/java/org/rundeck/client/api/model/DateInfo.java index bf38adae..084861c6 100644 --- a/src/main/java/org/rundeck/client/api/model/DateInfo.java +++ b/src/main/java/org/rundeck/client/api/model/DateInfo.java @@ -28,7 +28,9 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class DateInfo { - public static final String ISO = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + public static final String ISO1 = "yyyy-MM-dd'T'HH:mm:ssXXX"; + public static final String ISO2 = "yyyy-MM-dd'T'HH:mm:ssXX"; + public static final String ISO = "yyyy-MM-dd'T'HH:mm:ssX"; public String date; public long unixtime; @@ -45,7 +47,7 @@ public DateInfo(final String date) { public DateInfo() { } public Date toDate() throws ParseException { - return toDate(ISO); + return toDate(ISO1, ISO2, ISO); } /** @@ -59,8 +61,17 @@ public String format(String format) { } } - public Date toDate(final String format) throws ParseException { - SimpleDateFormat asdf = new SimpleDateFormat(format, Locale.US); + public Date toDate(final String... formats) throws ParseException { + for (int i = 0; i < formats.length - 1; i++) { + String format = formats[i]; + try { + + SimpleDateFormat asdf = new SimpleDateFormat(format, Locale.US); + return asdf.parse(date); + } catch (ParseException ignored) { + } + } + SimpleDateFormat asdf = new SimpleDateFormat(formats[formats.length - 1], Locale.US); return asdf.parse(date); } diff --git a/src/main/java/org/rundeck/client/tool/Main.java b/src/main/java/org/rundeck/client/tool/Main.java index e82316fc..13394ca0 100644 --- a/src/main/java/org/rundeck/client/tool/Main.java +++ b/src/main/java/org/rundeck/client/tool/Main.java @@ -172,7 +172,7 @@ public boolean isAnsiEnabled() { } public String getDateFormat() { - return getString("RD_DATE_FORMAT", "yyyy-MM-ddHH:mm:ssZ"); + return getString("RD_DATE_FORMAT", "yyyy-MM-dd'T'HH:mm:ssXX"); } @Override diff --git a/src/main/java/org/rundeck/client/tool/options/RunBaseOptions.java b/src/main/java/org/rundeck/client/tool/options/RunBaseOptions.java index 65be0584..52d18b4b 100644 --- a/src/main/java/org/rundeck/client/tool/options/RunBaseOptions.java +++ b/src/main/java/org/rundeck/client/tool/options/RunBaseOptions.java @@ -40,7 +40,7 @@ public interface RunBaseOptions extends JobIdentOptions, FollowOptions, Optional @Option(shortName = "@", longName = "at", - description = "Run the job at the specified date/time. ISO8601 format (yyyy-MM-dd'T'HH:mm:ss'Z')") + description = "Run the job at the specified date/time. ISO8601 format (yyyy-MM-dd'T'HH:mm:ssXX)") DateInfo getRunAtDate(); boolean isRunAtDate(); diff --git a/src/test/groovy/org/rundeck/client/api/model/DateInfoSpec.groovy b/src/test/groovy/org/rundeck/client/api/model/DateInfoSpec.groovy new file mode 100644 index 00000000..68579153 --- /dev/null +++ b/src/test/groovy/org/rundeck/client/api/model/DateInfoSpec.groovy @@ -0,0 +1,26 @@ +package org.rundeck.client.api.model + +import spock.lang.Specification + +/** + * @author greg + * @since 8/24/17 + */ +class DateInfoSpec extends Specification { + def "parse input correctly"() { + given: + when: + DateInfo info = new DateInfo(input) + then: + info.toDate().time == time + + where: + input | time + '2017-08-24T22:43:18Z' | 1503614598000 + '2017-08-24T15:43:18-07' | 1503614598000 + '2017-08-24T15:43:18-0700' | 1503614598000 + '2017-08-24T15:43:18-07:00' | 1503614598000 + '2017-08-24T15:43:18-0730' | 1503616398000 + '2017-08-24T15:43:18-07:30' | 1503616398000 + } +}