-
Notifications
You must be signed in to change notification settings - Fork 7
Validation Earliest Date
Author needs to be able to specify earliest date validation on Date
and DateRange
answer types.
Earliest date validation is all about restricting dates entered by respondents to say that it must be after some date.
As a somewhat contrived example, if we happened to know the respondent's date of birth, then we could reasonably conclude that the date they started living in the country was on or after this date. We could therefore apply earliest date validation to restrict entry of dates prior to their date of birth.
The earliest date is often specified as being offset from some reference date.
A common example of this in business surveys is to validate that the date entered is within -20 days of the reference start date and +20 days of the reference end date (reference start and end days are defined by the business for a particular collection period and are supplied as metadata).
Another example, from social surveys is to be able to check that a respondent is 16 years or over by asking for dates within the past 16 years from today's date. e.g.
"value": "now",
"offset_by": {
"years": -16
}
}
The offset supported by questionnaire runner can be specified in terms of days, months or years. Only one offset (days, months, or years) may be specified at one time. The schema definition for earliest date offsets can be found here: https://github.com/ONSdigital/eq-schema-validator/blob/master/schemas/common_definitions.json#L261
The before/after of the offset is specified by the sign of the number. Negative numbers indicate an offset before some value and positive numbers indicate an offset after some value.
e.g.
years: -16 = 16 years before
months: 1 = 1 month after
days: -90 = 90 days before
The schema definition for validation within author defines a RelativePosition
enum type to explicitly state that the date is Before/After. So this should be supported by the API that was designed for this solution.
More details about the proposed GraphQL schema changes can be found here: https://github.com/ONSdigital/eq-author/wiki/Validation.