aboutsummaryrefslogtreecommitdiffstats
path: root/library/moment/src/lib/create/valid.js
diff options
context:
space:
mode:
Diffstat (limited to 'library/moment/src/lib/create/valid.js')
-rw-r--r--library/moment/src/lib/create/valid.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/library/moment/src/lib/create/valid.js b/library/moment/src/lib/create/valid.js
new file mode 100644
index 000000000..ad56bfe06
--- /dev/null
+++ b/library/moment/src/lib/create/valid.js
@@ -0,0 +1,37 @@
+import extend from '../utils/extend';
+import { createUTC } from './utc';
+import getParsingFlags from '../create/parsing-flags';
+
+export function isValid(m) {
+ if (m._isValid == null) {
+ var flags = getParsingFlags(m);
+ m._isValid = !isNaN(m._d.getTime()) &&
+ flags.overflow < 0 &&
+ !flags.empty &&
+ !flags.invalidMonth &&
+ !flags.invalidWeekday &&
+ !flags.nullInput &&
+ !flags.invalidFormat &&
+ !flags.userInvalidated;
+
+ if (m._strict) {
+ m._isValid = m._isValid &&
+ flags.charsLeftOver === 0 &&
+ flags.unusedTokens.length === 0 &&
+ flags.bigHour === undefined;
+ }
+ }
+ return m._isValid;
+}
+
+export function createInvalid (flags) {
+ var m = createUTC(NaN);
+ if (flags != null) {
+ extend(getParsingFlags(m), flags);
+ }
+ else {
+ getParsingFlags(m).userInvalidated = true;
+ }
+
+ return m;
+}