mengxiong10 / vue2-datepicker

A datepicker / datetimepicker component for Vue2
https://mengxiong10.github.io/vue2-datepicker/index.html
MIT License
1.51k stars 405 forks source link

[Bug] #666

Closed VictorPulzz closed 2 years ago

VictorPulzz commented 2 years ago

Vue2-datepicker version:3.4.1 Vue version: 2.6.12 Browser: Chrome

Hello! Thanks for you cool plugin. But I faced with problem. In my service, the user can select his timezone, which will differ from the local one. And I would like the selected date or for example in the parameter: disabled-date. The time zone was taken into account. Could you add property :timezone="Europe / Berlin"

Thanks A lot!

mengxiong10 commented 2 years ago

You can use a computed value to transform timezone.

<date-picker v-model="date" />
data() {
  return { value: new Date() }
},
computed: {
  date: {
    get() {
      if (this.value) {
        return new Date(this.value.getTime() + this.timezoneOffset * 60 * 1000)
      }
      return this.value
    },
    set(val) {
      if (val) {
        this.value = new Date(this.value.getTime() - this.timezoneOffset * 60 * 1000)
      }
      this.value = val
    }
  }
}
VictorPulzz commented 2 years ago

Hmmm, how this work in disabled-date ?

mengxiong10 commented 2 years ago

use disabled-date as usual.

disabledDate(date) {
   return date < new Date()
}