Skip to content

Commit

Permalink
Added "year-month" type
Browse files Browse the repository at this point in the history
fixes #70
  • Loading branch information
talkhabi committed Jul 31, 2019
1 parent 2136bb7 commit 91bcbfd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/components/examples/SimpleDate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<br />
<date-picker v-model="time" type="time" />
<br />
<date-picker v-model="yearMonth" type="year-month" />
<br />
<date-picker v-model="year" type="year" min="1350" max="1410" />
<br />
<date-picker v-model="month" type="month" />
Expand All @@ -31,6 +33,9 @@
<highlight-code lang="html" v-pre>
&lt;date-picker v-model="time" type="time" /&gt;
</highlight-code>
<highlight-code lang="html" v-pre>
&lt;date-picker v-model="yearMonth" type="year-month" /&gt;
</highlight-code>
<highlight-code lang="html" v-pre>
&lt;date-picker v-model="year" type="year" /&gt;
</highlight-code>
Expand All @@ -52,6 +57,7 @@ export default {
return {
date: '',
time: '',
yearMonth: '',
datetime: '',
year: '',
month: ''
Expand Down
41 changes: 23 additions & 18 deletions src/picker/VuePersianDatetimePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
:style="{ 'background-color': color }"
>
<div
v-if="type === 'date' || type === 'datetime'"
v-if="['date', 'datetime', 'year-month'].indexOf(type) !== -1"
:class="[prefix('year-label'), directionClass]"
@click="goStep('y')"
>
Expand All @@ -84,6 +84,7 @@
</transition>
</div>
<div
v-if="type !== 'year-month'"
:class="[prefix('date'), directionClass]"
:style="{ 'font-size': type === 'datetime' ? '22px' : '' }"
>
Expand Down Expand Up @@ -203,6 +204,7 @@
</div>
</div>
</template>

<div v-else style="height:250px" />

<transition name="fade">
Expand Down Expand Up @@ -372,7 +374,7 @@

<transition name="fade">
<span
v-if="steps.length > 1 && currentStep !== 'd'"
v-if="steps.length > 1 && currentStep !== 'd' && hasStep('d')"
:class="[prefix('close-addon')]"
@click="goStep('d')"
>x</span
Expand Down Expand Up @@ -785,21 +787,14 @@ export default {
return this.steps[this.step]
},
formattedDate() {
let t = this.steps
let f = ''
if (t.indexOf('y') !== -1) {
f = 'jYYYY'
}
if (t.indexOf('m') !== -1) {
f += ' jMMMM '
}
if (t.indexOf('d') !== -1) {
f = 'ddd jDD jMMMM'
}
if (t.indexOf('t') !== -1) {
f += ' HH:mm '
}
return f ? this.selectedDate.xFormat(f) : ''
let format = ''
if (this.hasStep('y')) format = 'jYYYY'
if (this.hasStep('m')) format += ' jMMMM '
if (this.hasStep('d')) format = 'ddd jDD jMMMM'
if (this.hasStep('t')) format += ' HH:mm '
return format ? this.selectedDate.xFormat(format) : ''
},
month() {
if (!this.hasStep('d')) return []
Expand Down Expand Up @@ -960,6 +955,9 @@ export default {
case 'month':
format = 'MM'
break
case 'year-month':
format = 'YYYY-MM'
break
}
}
return this.output ? this.output.format(format) : ''
Expand All @@ -983,6 +981,9 @@ export default {
case 'month':
format = 'jMM'
break
case 'year-month':
format = 'jYYYY/jMM'
break
}
}
return format
Expand Down Expand Up @@ -1257,7 +1258,7 @@ export default {
this.selectedDate = this.selectedDate.set(t).clone()
}
if (['year', 'month'].indexOf(this.type) !== -1)
if (['year', 'month', 'year-month'].indexOf(this.type) !== -1)
this.selectedDate = this.date.clone()
this.output = this.selectedDate.clone()
Expand Down Expand Up @@ -1326,6 +1327,10 @@ export default {
this.steps = ['t']
this.goStep('t')
break
case 'year-month':
this.steps = ['y', 'm']
this.goStep('y')
break
}
},
setView() {
Expand Down

0 comments on commit 91bcbfd

Please sign in to comment.