This commit is contained in:
2019-03-06 17:23:39 +00:00
parent 85bd23ada2
commit ea7637a227
3 changed files with 17 additions and 14 deletions

View File

@@ -47,7 +47,7 @@ export default {
label: String, label: String,
value: String, value: String,
readonly: { type: Boolean, default: false }, readonly: { type: Boolean, default: false },
dayjs: Function, //dayjs: Function,
locale: Object locale: Object
}, },
watch: { watch: {
@@ -62,42 +62,42 @@ export default {
formatDateTime() { formatDateTime() {
//debugger; //debugger;
return this.value return this.value
? this.dayjs(this.value).add(this.locale.timeZoneOffset, "hour").format(this.locale.formats.shortDateAndTime) ? this.$dayjs(this.value).add(this.locale.timeZoneOffset, "hour").format(this.locale.formats.shortDateAndTime)
: ""; : "";
}, },
formatDate() { formatDate() {
return this.value return this.value
? this.dayjs(this.value).add(this.locale.timeZoneOffset, "hour").format(this.locale.formats.shortDate) ? this.$dayjs(this.value).add(this.locale.timeZoneOffset, "hour").format(this.locale.formats.shortDate)
: ""; : "";
}, },
formatTime() { formatTime() {
//debugger; //debugger;
return this.value return this.value
? this.dayjs(this.value) ? this.$dayjs(this.value)
.add(this.locale.timeZoneOffset, "hour") .add(this.locale.timeZoneOffset, "hour")
.format(this.locale.formats.shortTime) .format(this.locale.formats.shortTime)
: ""; : "";
}, },
dateOnly: { dateOnly: {
get() { get() {
return this.dayjs(this.value).add(this.locale.timeZoneOffset, "hour").format("YYYY-MM-DD"); return this.$dayjs(this.value).add(this.locale.timeZoneOffset, "hour").format("YYYY-MM-DD");
//return this.value ? this.value.substr(0, 10) : null; //return this.value ? this.value.substr(0, 10) : null;
}, },
set(value) { set(value) {
//this .date is always utc so convert back here before setting or all hell will break loose! //this .date is always utc so convert back here before setting or all hell will break loose!
this.date = this.dayjs(value + " " + this.timeOnly).subtract(this.locale.timeZoneOffset, "hour").toISOString(); this.date = this.$dayjs(value + " " + this.timeOnly).subtract(this.locale.timeZoneOffset, "hour").toISOString();
//this.date = value + " " + this.timeOnly; //this.date = value + " " + this.timeOnly;
} }
}, },
timeOnly: { timeOnly: {
get() { get() {
return this.dayjs(this.value).add(this.locale.timeZoneOffset, "hour").format("HH:mm:ss"); return this.$dayjs(this.value).add(this.locale.timeZoneOffset, "hour").format("HH:mm:ss");
//return this.value ? this.value.substr(11, 8) : null; //return this.value ? this.value.substr(11, 8) : null;
}, },
set(value) { set(value) {
//debugger; //debugger;
//this .date is always utc so convert back here before setting or all hell will break loose! //this .date is always utc so convert back here before setting or all hell will break loose!
this.date = this.dayjs(this.dateOnly + " " + value).subtract(this.locale.timeZoneOffset, "hour").toISOString(); this.date = this.$dayjs(this.dateOnly + " " + value).subtract(this.locale.timeZoneOffset, "hour").toISOString();
} }
} }
} }

View File

@@ -13,6 +13,12 @@ import "nprogress/nprogress.css";
import dayjs from "dayjs"; import dayjs from "dayjs";
import gzdateandtimepicker from "./components/gzdateandtimepicker.vue"; import gzdateandtimepicker from "./components/gzdateandtimepicker.vue";
/////////////////////////////////////////////////////////////////
// LIBS
// (https://medium.com/js-dojo/use-any-javascript-library-with-vue-js-3f7e2a4974a8)
//
Object.defineProperty(Vue.prototype, "$dayjs", { value: dayjs });
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// FORM VALIDATION // FORM VALIDATION
// //

View File

@@ -50,11 +50,8 @@
</v-flex> </v-flex>
<v-flex xs12 sm6 lg4 xl3 px-2> <v-flex xs12 sm6 lg4 xl3 px-2>
{{ obj.startDate }}
{{ lc.timeZoneOffset }}
<gz-date-time-picker <gz-date-time-picker
label="Start" label="Start"
:dayjs="this.dayjsLib"
:locale="this.lc" :locale="this.lc"
v-model="obj.startDate" v-model="obj.startDate"
></gz-date-time-picker> ></gz-date-time-picker>
@@ -94,7 +91,7 @@
//import store from "../store"; //import store from "../store";
import locale from "../api/locale"; import locale from "../api/locale";
import api from "../api/apiutil"; import api from "../api/apiutil";
import dayjs from "dayjs"; //import dayjs from "dayjs";
//import _ from "../utils/libs/lodash.js"; //import _ from "../utils/libs/lodash.js";
export default { export default {
components: {}, components: {},
@@ -102,7 +99,7 @@ export default {
return { return {
obj: {}, obj: {},
lc: locale, lc: locale,
dayjsLib: dayjs, // dayjsLib: dayjs,
theDate: new Date(), theDate: new Date(),
date: new Date().toISOString().substr(0, 10), date: new Date().toISOString().substr(0, 10),
menu: false, menu: false,