Skip to content

Commit dcaa273

Browse files
committed
add fecha instead of moment
1 parent 4751917 commit dcaa273

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

src/fields/fieldDateTimePicker.vue

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<script>
99
/* global $ */
1010
import abstractField from "./abstractField";
11-
import moment from "moment/min/moment.min";
11+
import fecha from "fecha";
1212
import { defaults } from "lodash";
1313
1414
let inputFormat = "YYYY-MM-DD HH:mm:ss";
@@ -26,19 +26,21 @@
2626
},
2727
2828
formatValueToField(value) {
29-
if (value != null)
30-
return moment(value, this.schema.format).format(this.getDateFormat());
29+
if (value != null) {
30+
let dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value);
31+
return fecha.format(dt, this.getDateFormat());
32+
}
3133
3234
return value;
3335
},
3436
3537
formatValueToModel(value) {
3638
if (value != null) {
37-
let m = moment(value, this.getDateFormat());
39+
let m = fecha.parse(value, this.getDateFormat());
3840
if (this.schema.format)
39-
value = m.format(this.schema.format);
41+
value = fecha.format(m, this.schema.format);
4042
else
41-
value = m.toDate().valueOf();
43+
value = m.valueOf();
4244
}
4345
4446
return value;

src/fields/fieldInput.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@
3737

3838
<script>
3939
import abstractField from "./abstractField";
40-
import moment from "moment/min/moment.min";
40+
import fecha from "fecha";
4141
4242
export default {
4343
mixins: [ abstractField ],
4444
methods: {
4545
formatValueToField(value) {
4646
switch(this.schema.inputType){
4747
case "date":
48-
return moment(value).format("YYYY-MM-DD");
48+
return fecha.format(value, "YYYY-MM-DD");
4949
case "datetime":
50-
return moment(value).format();
50+
return fecha.format(value);
5151
case "datetime-local":
52-
return moment(value).format("YYYY-MM-DDTHH:mm:ss");
52+
return fecha.format(value, "YYYY-MM-DDTHH:mm:ss");
5353
default:
5454
return value;
5555
}

src/fields/fieldPikaday.vue

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<script>
66
import abstractField from "./abstractField";
7-
import moment from "moment/min/moment.min";
7+
import fecha from "fecha";
88
import { defaults } from "lodash";
99
1010
let inputFormat = "YYYY-MM-DD";
@@ -25,20 +25,23 @@
2525
},
2626
2727
formatValueToField(value) {
28-
if (value != null)
29-
return moment(value, this.schema.format).format(this.getDateFormat());
28+
if (value != null) {
29+
let dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value);
30+
return fecha.format(dt, this.getDateFormat());
31+
}
3032
3133
return value;
3234
},
3335
3436
formatValueToModel(value) {
3537
if (value != null) {
36-
let m = moment(value, this.getDateFormat());
38+
let m = fecha.parse(value, this.getDateFormat());
3739
if (this.schema.format)
38-
value = m.format(this.schema.format);
40+
value = fecha.format(m, this.schema.format);
3941
else
40-
value = m.toDate().valueOf();
42+
value = m.valueOf();
4143
}
44+
4245
return value;
4346
}
4447

src/utils/validators.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isNil, isNumber, isString, isArray } from "lodash";
2-
import moment from "moment/min/moment.min";
2+
import fecha from "fecha";
33

44
function checkEmpty(value, required) {
55
if (isNil(value) || value === "") {
@@ -130,22 +130,22 @@ module.exports = {
130130
date(value, field) {
131131
let res = checkEmpty(value, field.required); if (res != null) return res;
132132

133-
let m = moment(value);
134-
if (!m.isValid())
133+
let m = new Date(value);
134+
if (!m)
135135
return [msg(resources.invalidDate)];
136136

137137
let err = [];
138138

139139
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)));
143143
}
144144

145145
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)));
149149
}
150150

151151
return err;

0 commit comments

Comments
 (0)