|
1 | 1 | import { isNil, isNumber, isString, isArray } from "lodash"; |
2 | | -import moment from "moment/min/moment.min"; |
| 2 | +import fecha from "fecha"; |
3 | 3 |
|
4 | 4 | function checkEmpty(value, required) { |
5 | 5 | if (isNil(value) || value === "") { |
@@ -130,22 +130,22 @@ module.exports = { |
130 | 130 | date(value, field) { |
131 | 131 | let res = checkEmpty(value, field.required); if (res != null) return res; |
132 | 132 |
|
133 | | - let m = moment(value); |
134 | | - if (!m.isValid()) |
| 133 | + let m = new Date(value); |
| 134 | + if (!m) |
135 | 135 | return [msg(resources.invalidDate)]; |
136 | 136 |
|
137 | 137 | let err = []; |
138 | 138 |
|
139 | 139 | if (!isNil(field.min)) { |
140 | | - let min = moment(field.min); |
141 | | - if (m.isBefore(min)) |
142 | | - err.push(msg(resources.dateIsEarly, m.format("L"), min.format("L"))); |
| 140 | + let min = new Date(field.min); |
| 141 | + if (m.valueOf() < min.valueOf()) |
| 142 | + err.push(msg(resources.dateIsEarly, fecha.format(m), fecha.format(min))); |
143 | 143 | } |
144 | 144 |
|
145 | 145 | if (!isNil(field.max)) { |
146 | | - let max = moment(field.max); |
147 | | - if (m.isAfter(max)) |
148 | | - err.push(msg(resources.dateIsLate, m.format("L"), max.format("L"))); |
| 146 | + let max = new Date(field.max); |
| 147 | + if (m.valueOf() > max.valueOf()) |
| 148 | + err.push(msg(resources.dateIsLate, fecha.format(m), fecha.format(max))); |
149 | 149 | } |
150 | 150 |
|
151 | 151 | return err; |
|
0 commit comments