darrenfang / vuetify-datetime-picker

DatetimePicker component for Vuetify.js. https://darrenfang.github.io/vuetify-datetime-picker/
MIT License
175 stars 127 forks source link

Date and time selection limits #61

Open damiansimanuk opened 4 years ago

damiansimanuk commented 4 years ago

Hello,

I have downloaded the .vue and modified the source code. Date and time selection limits added.

This way, when the date is selected and equals date limit, then it sets the time limit

modifications

// template:
<v-time-picker 
  ...
  :max="maxTime"  
// ... 

props:
// ...
datetimeMax: {
  type: [Date],
  default: null,
},
// ...

computed: {
// ....
  maxDate() {
    return this.datetimeMax
      ? this.datetimeMax.toISOString().substr(0, 10)
      : null;
  },
  maxTime() {
    if (!this.datetimeMax || !this.date) 
      return null;
    var eqDay =
      new Date(this.date).toISOString().substr(0, 10) ==
      this.datetimeMax.toISOString().substring(0, 10); 
    return eqDay 
      ? this.datetimeMax.toLocaleTimeString() 
      : null;
  },
// ...