Skip to content

Commit 1b652ad

Browse files
committed
feat: remove moment-jalaali
1 parent 0ac2ed3 commit 1b652ad

File tree

10 files changed

+41
-89
lines changed

10 files changed

+41
-89
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
dist
55
build
66
coverage
7+
src/components/icons/*

demo/pages/index.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
</template>
1717

1818
<script>
19-
import moment from 'moment';
20-
2119
import { VuecRangeInput, VuecSingleInput } from '../../src';
20+
import date from '../../src/date';
2221
2322
export default {
2423
components: {
@@ -27,8 +26,8 @@ export default {
2726
},
2827
data() {
2928
return {
30-
now: moment(),
31-
maxDate: moment().add(20, 'day'),
29+
now: date(),
30+
maxDate: date().add(26, 'day'),
3231
};
3332
},
3433
};

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "Vue Calendar",
55
"main": "dist/vuec.cjs.min.js",
66
"web": "dist/vuec.min.js",
7-
"module": "es/vuec.es.js",
8-
"jsnext:main": "es/vuec.es.js",
7+
"module": "dist/vuec.es.js",
8+
"jsnext:main": "dist/vuec.es.js",
99
"license": "MIT",
1010
"scripts": {
1111
"dev": "nuxt dev demo",
@@ -19,8 +19,7 @@
1919
],
2020
"dependencies": {
2121
"dayjs": "^1.7.5",
22-
"moment": "^2.22.2",
23-
"moment-jalaali": "^0.7.4"
22+
"jalaliday": "^1.1.0"
2423
},
2524
"devDependencies": {
2625
"bili": "^3.1.2",

src/components/core/calendar.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
</template>
4444

4545
<script>
46-
import { idate } from '../../date';
46+
import idate from '../../date';
4747
4848
import VuecMonth from './month.vue';
4949
import DefaultDayView from './default-day.vue';
@@ -104,7 +104,7 @@ export default {
104104
},
105105
data() {
106106
return {
107-
now: idate(),
107+
Xdate: this.date,
108108
dateUnderCursor: null,
109109
};
110110
},
@@ -127,13 +127,13 @@ export default {
127127
months() {
128128
const months = [];
129129
130-
let date = idate(this.date);
130+
let date = idate(this.Xdate);
131131
132132
if (this.showPreviousWeeks) {
133133
date.startOf('Month');
134134
}
135135
136-
const end = idate(this.date).add(this.visibleMonths - 1, 'Month').endOf('Month');
136+
const end = idate(this.Xdate).add(this.visibleMonths - 1, 'Month').endOf('Month');
137137
138138
while (date.isBefore(end)) {
139139
const monthKey = date.format('YYYY/MM');
@@ -147,6 +147,7 @@ export default {
147147
date = date.add(1, 'Month').startOf('Month');
148148
}
149149
150+
months.length = this.visibleMonths;
150151
return months;
151152
},
152153
},
@@ -168,12 +169,12 @@ export default {
168169
this.$emit('selectionChange', { date, selected });
169170
},
170171
previousPage() {
171-
this.date = this.date.subtract(this.visibleMonths, 'Month').startOf('Month');
172-
this.$emit('previous-page', this.date);
172+
this.Xdate = this.Xdate.subtract(this.visibleMonths, 'Month').startOf('Month');
173+
this.$emit('previous-page', this.Xdate);
173174
},
174175
nextPage() {
175-
this.date = this.date.add(this.visibleMonths, 'Month').startOf('Month');
176-
this.$emit('next-page', this.date);
176+
this.Xdate = this.Xdate.add(this.visibleMonths, 'Month').startOf('Month');
177+
this.$emit('next-page', this.Xdate);
177178
},
178179
},
179180
};

src/components/core/month.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="vuec-month-days vuec-7col">
2121
<day-view
2222
v-for="(day, i) in days"
23-
:key="i"
23+
:key="day.dayKey"
2424
:index="i"
2525
:data="day.data"
2626
:date="day.date"
@@ -42,7 +42,7 @@
4242
</template>
4343

4444
<script>
45-
import { idate } from '../../date';
45+
import idate from '../../date';
4646
4747
import DayView from './day.vue';
4848
import DefaultDayView from './default-day.vue';
@@ -104,6 +104,7 @@ export default {
104104
const end = idate(this.date).endOf('Month');
105105
106106
const days = [];
107+
107108
while (date.isBefore(end)) {
108109
const dayKey = date.format('YYYY/MM/DD');
109110
if ((this.minDate && date.isBefore(this.minDate, 'day'))

src/components/range-input.vue

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</div>
1010
<transition name="popup-animation">
1111
<div
12-
v-show="visible"
12+
v-if="visible"
1313
:class="{ mobile: mobile }"
1414
class="vuec-popup"
1515
@click="onClickDelegate"
@@ -41,9 +41,8 @@
4141

4242
<script>
4343
import VuecSelectRange from './select-range.vue';
44-
import { formatDate } from '../utils';
4544
import IconClose from './icons/close.vue';
46-
import { idate } from '../date';
45+
import idate from '../date';
4746
4847
export default {
4948
components: {
@@ -93,7 +92,7 @@ export default {
9392
},
9493
format: {
9594
type: String,
96-
default: 'jYYYY/jMM/jDD',
95+
default: 'YYYY/MM/DD',
9796
},
9897
},
9998
data() {
@@ -104,14 +103,14 @@ export default {
104103
fromDate,
105104
toDate,
106105
dates: [
107-
typeof fromDate === 'string' ? idate(fromDate, this.format) : idate(fromDate),
108-
typeof toDate === 'string' ? idate(toDate, this.format) : idate(toDate),
106+
idate(fromDate),
107+
idate(toDate),
109108
],
110109
};
111110
},
112111
computed: {
113112
formattedDates() {
114-
return this.dates.map(date => formatDate(date, this.format));
113+
return this.dates.map(date => date.format(this.format));
115114
},
116115
},
117116
watch: {
@@ -142,8 +141,8 @@ export default {
142141
$event.stopPropagation();
143142
},
144143
onSelectionChange(selections) {
145-
this.fromDate = idate(selections[0], 'jYYYY/jMM/jDD');
146-
this.toDate = idate(selections[selections.length - 1], 'jYYYY/jMM/jDD');
144+
this.fromDate = idate(selections[0]);
145+
this.toDate = idate(selections[selections.length - 1]);
147146
this.$emit('input', [
148147
this.fromDate,
149148
this.toDate,

src/components/single-input.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
<script>
2626
import VuecSingleSelect from './select-single.vue';
27-
import { formatDate } from '../utils';
28-
import { idate } from '../date';
27+
import idate from '../date';
2928
3029
export default {
3130
components: {
@@ -76,7 +75,7 @@ export default {
7675
},
7776
computed: {
7877
formattedDates() {
79-
return this.dates.map(date => formatDate(date));
78+
return this.dates.map(date => date.format('YYYY/MM/DD'));
8079
},
8180
},
8281
watch: {
@@ -107,8 +106,8 @@ export default {
107106
$event.stopPropagation();
108107
},
109108
onSelectionChange(selections) {
110-
this.fromDate = idate(selections[0], 'jYYYY/jMM/jDD');
111-
this.toDate = idate(selections[selections.length - 1], 'jYYYY/jMM/jDD');
109+
this.fromDate = idate(selections[0], 'YYYY/MM/DD');
110+
this.toDate = idate(selections[selections.length - 1], 'YYYY/MM/DD');
112111
this.$emit('input', [
113112
this.fromDate,
114113
this.toDate,

src/date.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import dayjs from 'dayjs';
22
import isBetween from 'dayjs/plugin/isBetween';
3-
import 'dayjs/locale/fa';
3+
import jalaliday from 'jalaliday';
44

55
dayjs.extend(isBetween);
6-
dayjs.locale('fa');
6+
dayjs.extend(jalaliday);
77

8-
export { dayjs as default };
9-
10-
export const idate = dayjs;
8+
dayjs.calendar('jalali');
119

12-
export const setLocale = (locale) => {
13-
dayjs.locale(locale);
14-
};
10+
export { dayjs as default };

src/utils.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import moment from 'moment-jalaali';
2-
3-
moment.loadPersian({
4-
dialect: 'persian-modern',
5-
});
6-
71
/**
82
* Persian numeric characters
93
*/
@@ -48,33 +42,6 @@ export function toEnglishDigits(value) {
4842
.replace(/[٠-٩]/g, w => w.charCodeAt(0) - ARABIC_ZERO_CHAR_CODE);
4943
}
5044

51-
function getFormat(format) {
52-
switch (format) {
53-
case 'jalaliDateTime':
54-
// This filter returns a Jalali date time format like : 12:31 1396/11/4
55-
return 'HH:mm jYYYY/jM/jD';
56-
case 'jalaliDate':
57-
// This filter returns a Jalali date in the following format : 1396/11/4
58-
return 'jYYYY/jM/jD';
59-
default:
60-
return format;
61-
}
62-
}
63-
64-
export function formatDate(date, format = 'jalaliDate', toPersian = true) {
65-
let formattedDate = '';
66-
67-
if (date) {
68-
formattedDate = moment(date).format(getFormat(format));
69-
}
70-
71-
if (toPersian) {
72-
formattedDate = toPersianDigits(formattedDate);
73-
}
74-
75-
return formattedDate;
76-
}
77-
7845
export function weekDays() {
7946
return [
8047
'شنبه',

yarn.lock

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,7 +3204,7 @@ date-time@^2.1.0:
32043204
dependencies:
32053205
time-zone "^1.0.0"
32063206

3207-
dayjs@^1.7.5:
3207+
dayjs@^1.6.3, dayjs@^1.7.5:
32083208
version "1.7.5"
32093209
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.7.5.tgz#14715cb565d1f8cb556a8531cb14bf1fc33067cc"
32103210

@@ -5173,9 +5173,11 @@ istanbul-reports@^1.4.1:
51735173
dependencies:
51745174
handlebars "^4.0.11"
51755175

5176-
jalaali-js@^1.1.0:
5177-
version "1.1.0"
5178-
resolved "https://registry.yarnpkg.com/jalaali-js/-/jalaali-js-1.1.0.tgz#f0e942049273d11f7298a992356fc36ce2784863"
5176+
jalaliday@^1.0.0:
5177+
version "1.0.0"
5178+
resolved "https://registry.yarnpkg.com/jalaliday/-/jalaliday-1.0.0.tgz#8e757dbdb626700e0ad9213a3fb9870c1e182386"
5179+
dependencies:
5180+
dayjs "^1.6.3"
51795181

51805182
jest-changed-files@^23.4.2:
51815183
version "23.4.2"
@@ -6141,18 +6143,6 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkd
61416143
dependencies:
61426144
minimist "0.0.8"
61436145

6144-
moment-jalaali@^0.7.4:
6145-
version "0.7.4"
6146-
resolved "https://registry.yarnpkg.com/moment-jalaali/-/moment-jalaali-0.7.4.tgz#6878971d77c41d49270e61c18c7cb1e5d84528ee"
6147-
dependencies:
6148-
jalaali-js "^1.1.0"
6149-
moment "^2.22.1"
6150-
rimraf "^2.6.2"
6151-
6152-
moment@^2.22.1, moment@^2.22.2:
6153-
version "2.22.2"
6154-
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66"
6155-
61566146
move-concurrently@^1.0.1:
61576147
version "1.0.1"
61586148
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"

0 commit comments

Comments
 (0)