Skip to content

Commit 77aef14

Browse files
authored
Merge pull request #117 from mkalantar/master
2 commits improving picker
2 parents 99355f9 + e23813f commit 77aef14

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ yarn-error.log
55

66
# Editor directories and files
77
.idea
8+
.vscode
89
*.suo
910
*.ntvs*
1011
*.njsproj

src/picker/VuePersianDatetimePicker.vue

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<transition name="slideY">
8282
<span :key="selectedDate.xYear()">
8383
<slot name="header-year" v-bind="{ vm, selectedDate }">
84-
{{ selectedDate.xYear() }}
84+
{{ convertToLocaleNumber(selectedDate.xYear()) }}
8585
</slot>
8686
</span>
8787
</transition>
@@ -94,7 +94,7 @@
9494
<transition name="slideY">
9595
<span :key="formattedDate">
9696
<slot name="header-date" v-bind="{ vm, formattedDate }">
97-
{{ formattedDate }}
97+
{{ convertToLocaleNumber(formattedDate) }}
9898
</slot>
9999
</span>
100100
</transition>
@@ -153,7 +153,9 @@
153153
<slot name="month-name" v-bind="{ vm, date, color }">
154154
<span
155155
:style="{ 'border-color': color, color }"
156-
v-text="date.xFormat('jMMMM jYYYY')"
156+
v-text="
157+
convertToLocaleNumber(date.xFormat('jMMMM jYYYY'))
158+
"
157159
/>
158160
</slot>
159161
</div>
@@ -208,7 +210,7 @@
208210
/>
209211
<span
210212
:class="[prefix('day-text')]"
211-
v-text="day.formatted"
213+
v-text="convertToLocaleNumber(day.formatted)"
212214
/>
213215
</slot>
214216
</template>
@@ -250,7 +252,7 @@
250252
@click="selectYear(year)"
251253
>
252254
<slot name="year-item" v-bind="{ vm, year, color }">
253-
{{ year.xFormat('jYYYY') }}
255+
{{ convertToLocaleNumber(year.xFormat('jYYYY')) }}
254256
</slot>
255257
</div>
256258
</div>
@@ -775,7 +777,13 @@ export default {
775777
* @default true
776778
* @version 2.1.6
777779
*/
778-
showNowBtn: { type: Boolean, default: true }
780+
showNowBtn: { type: Boolean, default: true },
781+
/**
782+
* Convert to locale numbers or not
783+
* @type Boolean
784+
* @default false
785+
*/
786+
convertNumbers: { type: Boolean, default: false }
779787
},
780788
data() {
781789
let defaultLocale = this.locale.split(',')[0]
@@ -1050,7 +1058,7 @@ export default {
10501058
let output = this.output.clone()
10511059
let format = this.selfDisplayFormat
10521060
if (/j\w/.test(format)) output.locale('fa')
1053-
return output.format(format)
1061+
return this.convertToLocaleNumber(output.format(format))
10541062
},
10551063
isDisableTime() {
10561064
return this.hasStep('t') && this.checkDisable('t', this.time)
@@ -1578,6 +1586,18 @@ export default {
15781586
}
15791587
}
15801588
return date.clone()
1589+
},
1590+
convertToLocaleNumber(value) {
1591+
if (this.convertNumbers && this.locale == 'fa') {
1592+
return `${value}`.replace(/\d+/g, function(digit) {
1593+
var ret = ''
1594+
for (var i = 0, len = digit.length; i < len; i++) {
1595+
ret += String.fromCharCode(digit.charCodeAt(i) + 1728)
1596+
}
1597+
return ret
1598+
})
1599+
}
1600+
return value
15811601
}
15821602
},
15831603
install(Vue, options) {

0 commit comments

Comments
 (0)