From e2a69c333044106d60ab4014fc705c4d63934ef1 Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Fri, 8 Nov 2019 12:19:01 +0000 Subject: [PATCH] feat(#1426): Added more friendly datetime formats --- .../operators/temporal/DateTime.feature | 27 +++++++++++++++++++ .../steps/DateTimeValueStep.java | 2 +- .../profile/factories/DateTimeFactory.java | 15 +++++++++-- .../profileschema/datahelix.schema.json | 4 +-- .../ProfileSchemaImmutabilityTests.java | 2 +- 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/DateTime.feature diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/DateTime.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/DateTime.feature new file mode 100644 index 000000000..5548aa294 --- /dev/null +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/DateTime.feature @@ -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 | diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateTimeValueStep.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateTimeValueStep.java index 60d2da7d9..2a14c5bb9 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateTimeValueStep.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateTimeValueStep.java @@ -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); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java index b47180e1a..c032155cd 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java @@ -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); diff --git a/profile/src/main/resources/profileschema/datahelix.schema.json b/profile/src/main/resources/profileschema/datahelix.schema.json index e26fb2169..809c6f481 100644 --- a/profile/src/main/resources/profileschema/datahelix.schema.json +++ b/profile/src/main/resources/profileschema/datahelix.schema.json @@ -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": [ diff --git a/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java b/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java index 56d55bb36..1eb867639 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java @@ -116,7 +116,7 @@ private static Set versionToHash() { "3b812a8dfe5b2a77e2b427f343ffc237e3e31c0364197e820f2b7702fa6ef260")); versionToHash.add(new VersionHash( "0.14", - "307d231bede9bcc4e77cd6ac5e3d45ddf427719d688930a45af0c139a314cf92")); + "26ef27557c4b966b786bed79a99e0184b3e4a3c50b98256725a1000250d6fcd0")); return versionToHash; }