-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathdate.js
More file actions
executable file
·49 lines (46 loc) · 1.59 KB
/
Copy pathdate.js
File metadata and controls
executable file
·49 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import EmberValidator from 'ember-cp-validations/-private/ember-validator';
import { assert } from '@ember/debug';
/**
* <i class="fa fa-hand-o-right" aria-hidden="true"></i> [See All Options](#method_validate)
*
* Validate over a date range. Uses the native Date and Intl APIs. Will parse strings using `new Date(<string>)`,
* so care must be taken to ensure you use only ISO 8601 strings if you want cross-browser compatibility.
*
* ## Examples
*
* To set `before`, `onOrBefore`, `after`, or `onOrAfter` to the current instant, use a JS getter:
*
* ```javascript
* validator('date', {
* get after(): { return Date.now(); },
* before: '2020/01/01T00:00:00.0000Z', // Must be ISO or Date!
* })
* ```
*
* @class Date
* @module Validators
* @extends Base
*/
export default class DateValidator extends EmberValidator {
_evType = 'date';
validate(value, options) {
// Help applications recognize no longer supported configurations for the default date validator:
assert(
"the default 'date' validator no longer accepts a string 'format' option",
typeof options.format !== 'string'
);
assert(
"the default 'date' validator does not support a 'precision' option",
!options.precision
);
assert(
"the default 'date' validator does not accept the string 'now'; use a getter instead",
options.before !== 'now' &&
options.onOrBefore !== 'now' &&
options.after !== 'now' &&
options.onOrAfter !== 'now'
);
// Use the date validator supplied by ember-validators:
return super.validate(...arguments);
}
}