Skip to content
Permalink
Browse files

feat: joi dateStringCalendarAccuracy (credit to @oskojo)

  • Loading branch information...
kirillgroshkov committed Feb 16, 2019
1 parent d3731ba commit 6464267661bcf22fcae2d31440a8204690c0fb37
Showing with 4 additions and 1 deletion.
  1. +1 −1 src/validation/joi/joi.extensions.test.ts
  2. +3 −0 src/validation/joi/joi.extensions.ts
@@ -1,5 +1,5 @@
import { DateTime } from 'luxon'
import { LUXON_ISO_DATE_FORMAT } from '../..'
import { LUXON_ISO_DATE_FORMAT } from '../../util/localDate.util'
import { Joi } from './joi.extensions'
import { stringSchema } from './joi.shared.schemas'
import { joiValidationService } from './joi.validation.service'
@@ -40,6 +40,7 @@ function dateStringExtension (joi: typeof JoiLib): Extension {
dateString: 'needs to be a date string (yyyy-mm-dd)',
dateStringMin: 'needs to be not earlier than {{min}}',
dateStringMax: 'needs to be not later than {{max}}',
dateStringCalendarAccuracy: 'needs to be a calendar accurate date',
},
rules: [
{
@@ -73,6 +74,8 @@ function dateStringExtension (joi: typeof JoiLib): Extension {
err = 'string.dateStringMin'
} else if (max && v > max) {
err = 'string.dateStringMax'
} else if (!DateTime.fromFormat(v, LUXON_ISO_DATE_FORMAT).isValid) {
err = 'string.dateStringCalendarAccuracy'
}

if (err) {

0 comments on commit 6464267

Please sign in to comment.
You can’t perform that action at this time.