Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1526 from cdowding-sl/feature/friendly_datetimes
Browse files Browse the repository at this point in the history
Added friendly date times
  • Loading branch information
cdowding-sl authored Nov 8, 2019
2 parents 761a29d + e2a69c3 commit 3f941ce
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Feature: User can specify a datetime in a particular format

Background:
Given the generation strategy is full
And there is a nullable field foo
And foo has type "datetime"

Scenario: 'EqualTo' valid date time is successful for date time specified fully
Given foo is equal to 2018-09-01T00:00:00.000Z
And the generator can generate at most 1 rows
Then the following data should be generated:
| foo |
| 2018-09-01T00:00:00.000Z |

Scenario: 'EqualTo' valid date time is successful for date time specified to seconds
Given foo is equal to 2018-09-01T00:00:00
And the generator can generate at most 1 rows
Then the following data should be generated:
| foo |
| 2018-09-01T00:00:00.000Z |

Scenario: 'EqualTo' valid date time is successful for date time specified to minutes
Given foo is equal to 2018-09-01T00:00
And the generator can generate at most 1 rows
Then the following data should be generated:
| foo |
| 2018-09-01T00:00:00.000Z |
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public DateTimeValueStep(CucumberTestState state, CucumberTestHelper helper){
this.helper = helper;
}

@When("^([A-z0-9]+) is equal to ([0-9]{4,5}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z?)$")
@When("^([A-z0-9]+) is equal to (\\d{4,5}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+Z?)?)?)$")
public void equalToDateTimeValue(String fieldName, String value) {
state.addConstraint(fieldName, ConstraintType.EQUAL_TO, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,24 @@ private static DateTimeFormatter getDateTimeFormatter()
.appendPattern("u-MM-dd")
.parseDefaulting(ChronoField.SECOND_OF_DAY,0)
.toFormatter();
DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder()
DateTimeFormatter dateTimeFullFormatter = new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ofPattern("u-MM-dd'T'HH:mm:ss'.'SSS"))
.optionalStart()
.appendOffset("+HH", "Z")
.toFormatter();
DateTimeFormatter dateTimeToSecondsFormatter = new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ofPattern("u-MM-dd'T'HH:mm:ss"))
.optionalStart()
.toFormatter();
DateTimeFormatter dateTimeToMinutesFormatter = new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ofPattern("u-MM-dd'T'HH:mm"))
.optionalStart()
.toFormatter();

return new DateTimeFormatterBuilder()
.appendOptional(dateTimeFormatter)
.appendOptional(dateTimeFullFormatter)
.appendOptional(dateTimeToSecondsFormatter)
.appendOptional(dateTimeToMinutesFormatter)
.appendOptional(dateFormat)
.toFormatter()
.withResolverStyle(ResolverStyle.STRICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@
"default": "2000-01-01T09:00:00.000",
"anyOf": [
{
"pattern": "^(?!0000)[0-9]{4}-([0][0-9]|[1][0-2])-([0-2][0-9]|3[01])T([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9][.][0-9]{3}Z?$"
"pattern": "^(?!0000)\\d{4}-([0]\\d|[1][0-2])-([0-2]\\d|3[01])T[0-2]\\d:[0-5]\\d(?::[0-5]\\d(?:\\.\\d+Z?)?)?"
},
{
"pattern": "^(?!0000)[0-9]{4}-([0][0-9]|[1][0-2])-([0-2][0-9]|3[01])"
"pattern": "^(?!0000)\\d{4}-([0]\\d|[1][0-2])-([0-2]\\d|3[01])"
},
{
"enum": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private static Set<VersionHash> versionToHash() {
"3b812a8dfe5b2a77e2b427f343ffc237e3e31c0364197e820f2b7702fa6ef260"));
versionToHash.add(new VersionHash(
"0.14",
"307d231bede9bcc4e77cd6ac5e3d45ddf427719d688930a45af0c139a314cf92"));
"26ef27557c4b966b786bed79a99e0184b3e4a3c50b98256725a1000250d6fcd0"));
return versionToHash;
}

Expand Down

0 comments on commit 3f941ce

Please sign in to comment.