@sanity/validation 2.29.5 → 2.30.1-pte-instance-props.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"dateValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/dateValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAIxC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAErE;AA8CD,QAAA,MAAM,cAAc,EAAE,UAsDrB,CAAA;AAED,eAAe,cAAc,CAAA"}
1
+ {"version":3,"file":"dateValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/dateValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAA;AAIxC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAErE;AAiDD,QAAA,MAAM,cAAc,EAAE,UAuDrB,CAAA;AAED,eAAe,cAAc,CAAA"}
@@ -38,7 +38,7 @@ var getFormattedDate = function getFormattedDate() {
38
38
 
39
39
  if (type === 'date') {
40
40
  // If the type is date only
41
- return (0, _format.default)(value, format);
41
+ return (0, _format.default)(new Date(value), format);
42
42
  } // If the type is datetime
43
43
 
44
44
 
@@ -48,7 +48,7 @@ var getFormattedDate = function getFormattedDate() {
48
48
  format += ' HH:mm';
49
49
  }
50
50
 
51
- return (0, _format.default)(value, format);
51
+ return (0, _format.default)(new Date(value), format);
52
52
  };
53
53
 
54
54
  function parseDate(date) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/validation",
3
- "version": "2.29.5",
3
+ "version": "2.30.1-pte-instance-props.1+798cab091",
4
4
  "description": "Validation and warning infrastructure for Sanity projects",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./dist/dts",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@sanity/client": "^3.2.0",
36
- "@sanity/schema": "2.29.3"
36
+ "@sanity/schema": "2.30.1-pte-instance-props.1+798cab091"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@sanity/client": "^3.2.0"
@@ -44,9 +44,9 @@
44
44
  }
45
45
  },
46
46
  "dependencies": {
47
- "@sanity/types": "2.29.5",
47
+ "@sanity/types": "2.30.1-pte-instance-props.1+798cab091",
48
48
  "date-fns": "^2.16.1",
49
49
  "lodash": "^4.17.15"
50
50
  },
51
- "gitHead": "ad132541b3fe82d622728ed07dd580361e097e5f"
51
+ "gitHead": "798cab091ce754cee51e4b65d27c7a888b344a7c"
52
52
  }
@@ -16,22 +16,25 @@ interface DateTimeOptions {
16
16
  timeFormat?: string
17
17
  }
18
18
 
19
- const getFormattedDate = (type = '', value: number | Date, options?: DateTimeOptions) => {
19
+ const getFormattedDate = (type = '', value: string | number | Date, options?: DateTimeOptions) => {
20
20
  let format = 'yyyy-MM-dd'
21
21
  if (options && options.dateFormat) {
22
22
  format = options.dateFormat
23
23
  }
24
+
24
25
  if (type === 'date') {
25
26
  // If the type is date only
26
- return formatDate(value, format)
27
+ return formatDate(new Date(value), format)
27
28
  }
29
+
28
30
  // If the type is datetime
29
31
  if (options && options.timeFormat) {
30
32
  format += ` ${options.timeFormat}`
31
33
  } else {
32
34
  format += ' HH:mm'
33
35
  }
34
- return formatDate(value, format)
36
+
37
+ return formatDate(new Date(value), format)
35
38
  }
36
39
 
37
40
  function parseDate(date: unknown): Date | null
@@ -80,6 +83,7 @@ const dateValidators: Validators = {
80
83
  : {}
81
84
 
82
85
  const date = getFormattedDate(context.type.name, minDate, dateTimeOptions)
86
+
83
87
  return message || `Must be at or after ${date}`
84
88
  },
85
89