Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix execution datetime parse issue #118

Merged
merged 2 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/main/java/org/rundeck/client/api/model/DateInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -45,7 +47,7 @@ public DateInfo(final String date) {
public DateInfo() {
}
public Date toDate() throws ParseException {
return toDate(ISO);
return toDate(ISO1, ISO2, ISO);
}

/**
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/rundeck/client/tool/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 26 additions & 0 deletions src/test/groovy/org/rundeck/client/api/model/DateInfoSpec.groovy
Original file line number Diff line number Diff line change
@@ -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
}
}