@@ -9,88 +9,93 @@ import Popover from "@/components/ui/Popover.vue"
99const props = defineProps ({
1010 from: {
1111 type: String ,
12- default: ' ' ,
12+ default: " " ,
1313 },
1414 to: {
1515 type: String ,
16- default: ' ' ,
16+ default: " " ,
1717 },
1818 minDate: {
1919 type: String ,
20- default: ' ' ,
21- }
20+ default: " " ,
21+ },
2222})
2323
2424const emit = defineEmits ([" onUpdate" ])
2525
2626const currentDate = ref (DateTime .now ())
27- const limitMinDate = ref (props .minDate ? DateTime .fromISO (props .minDate ) : ' ' )
27+ const limitMinDate = ref (props .minDate ? DateTime .fromISO (props .minDate ) : " " )
2828const month = ref (currentDate .value .month )
2929const year = ref (currentDate .value .year )
30- const startDate = ref (props .from ? DateTime .fromSeconds (parseInt (props .from )) : {})
31- const endDate = ref (props .to ? DateTime .fromSeconds (parseInt (props .to )) : {})
32- const weekdays = ref (Info .weekdays (' narrow' , { locale: ' en-US' }))
30+ const startDate = ref (props .from ? DateTime .fromSeconds (Number . parseInt (props .from )) : {})
31+ const endDate = ref (props .to ? DateTime .fromSeconds (Number . parseInt (props .to )) : {})
32+ const weekdays = ref (Info .weekdays (" narrow" , { locale: " en-US" }))
3333const days = computed (() => {
34- let rawDays = []
35- const firstDay = DateTime .local (year .value , month .value ).setLocale (' en-US' )
36- const lastDay = firstDay .endOf (' month' )
34+ const rawDays = []
35+ const firstDay = DateTime .local (year .value , month .value ).setLocale (" en-US" )
36+ const lastDay = firstDay .endOf (" month" )
3737
3838 for (let day = firstDay; day <= lastDay; day = day .plus ({ days: 1 })) {
39- rawDays .push (day)
40- }
39+ rawDays .push (day)
40+ }
4141
4242 if (firstDay .weekday !== 1 ) {
4343 let prevDay = firstDay
4444 while (prevDay .weekday !== 1 ) {
45- prevDay = prevDay .minus ({ days: 1 }).startOf (' day' )
45+ prevDay = prevDay .minus ({ days: 1 }).startOf (" day" )
4646 rawDays .unshift (prevDay)
4747 }
4848 }
4949
5050 if (lastDay .weekday !== 7 ) {
5151 let nextDay = lastDay
5252 while (nextDay .weekday !== 7 ) {
53- nextDay = nextDay .plus ({ days: 1 }).startOf (' day' )
53+ nextDay = nextDay .plus ({ days: 1 }).startOf (" day" )
5454 rawDays .push (nextDay)
5555 }
5656 }
5757
58- let resDays = []
58+ const resDays = []
5959 while (rawDays .length ) {
6060 resDays .push (rawDays .splice (0 , 7 ))
6161 }
6262
6363 return resDays
6464})
6565
66- const selectedRange = ref (' ' )
66+ const selectedRange = ref (" " )
6767const updateSelectedRange = (from , to ) => {
6868 if (from? .ts ) {
6969 if (to? .ts ) {
7070 if (from .year === to .year ) {
71- selectedRange .value = from .toFormat (' dd LLL' ) !== to .toFormat (' dd LLL' ) ? ` ${ from .toFormat (' dd LLL' )} - ${ to .toFormat (' dd LLL' )} ` : from .toFormat (' dd LLL' )
71+ selectedRange .value =
72+ from .toFormat (" dd LLL" ) !== to .toFormat (" dd LLL" )
73+ ? ` ${ from .toFormat (" dd LLL" )} - ${ to .toFormat (" dd LLL" )} `
74+ : from .toFormat (" dd LLL" )
7275 } else {
73- selectedRange .value = ` ${ from .toFormat (' dd LLL yyyy' )} - ${ to .toFormat (' dd LLL yyyy' )} `
76+ selectedRange .value = ` ${ from .toFormat (" dd LLL yyyy" )} - ${ to .toFormat (" dd LLL yyyy" )} `
7477 }
7578 } else {
76- selectedRange .value = from .toFormat (' dd LLL' )
79+ selectedRange .value = from .toFormat (" dd LLL" )
7780 }
7881 } else {
79- selectedRange .value = ' '
82+ selectedRange .value = " "
8083 }
8184}
8285updateSelectedRange (startDate .value , endDate .value )
8386
8487const isNextMonthAvailable = computed (() => ! (month .value === currentDate .value .month && year .value === currentDate .value .year ))
85- const isPrevMonthAvailable = computed (() => limitMinDate .value ? limitMinDate .value .ts < days .value [0 ][0 ].ts : true )
88+ const isPrevMonthAvailable = computed (() => ( limitMinDate .value ? limitMinDate .value .ts < days .value [0 ][0 ].ts : true ) )
8689const isDayAvailable = (d ) => {
87- if (d .startOf (' day' ).ts > currentDate .value .startOf (' day' ).ts ) {
90+ if (d .startOf (" day" ).ts > currentDate .value .startOf (" day" ).ts ) {
8891 return false
89- } else if (limitMinDate .value ) {
90- return d .startOf (' day' ).ts >= limitMinDate .value .startOf (' day' ).ts
91- } else {
92- return true
9392 }
93+
94+ if (limitMinDate .value ) {
95+ return d .startOf (" day" ).ts >= limitMinDate .value .startOf (" day" ).ts
96+ }
97+
98+ return true
9499}
95100
96101const handleSelectDate = (d ) => {
@@ -131,18 +136,18 @@ const handleClose = () => {
131136
132137 if (! startDate .value .ts ) {
133138 month .value = currentDate .value .month
134- year .value = currentDate .value .year
139+ year .value = currentDate .value .year
135140 }
136141}
137142
138143const handleApply = () => {
139144 isOpen .value = false
140145
141146 if (! endDate .value .ts ) {
142- endDate .value = startDate .value .endOf (' day' )
147+ endDate .value = startDate .value .endOf (" day" )
143148 }
144149
145- emit (' onUpdate' , { from: parseInt (startDate .value .ts / 1_000 ), to: parseInt (endDate .value .ts / 1_000 ) })
150+ emit (" onUpdate" , { from: Number . parseInt (startDate .value .ts / 1_000 ), to: Number . parseInt (endDate .value .ts / 1_000 ) })
146151}
147152
148153const handleClear = () => {
@@ -151,18 +156,18 @@ const handleClear = () => {
151156 startDate .value = {}
152157 endDate .value = {}
153158
154- emit (' onUpdate' , { clear: true })
159+ emit (" onUpdate" , { clear: true })
155160}
156161
157162const handleMonthChange = (v ) => {
158163 switch (month .value + v) {
159164 case 0 :
160165 month .value = 12
161- year .value --
166+ year .value --
162167 break
163168 case 13 :
164169 month .value = 1
165- year .value ++
170+ year .value ++
166171 break
167172 default :
168173 month .value += v
@@ -172,7 +177,7 @@ const handleMonthChange = (v) => {
172177watch (
173178 () => props .from ,
174179 () => {
175- updateSelectedRange (DateTime .fromSeconds (parseInt (props .from )), DateTime .fromSeconds (parseInt (props .to )))
180+ updateSelectedRange (DateTime .fromSeconds (Number . parseInt (props .from )), DateTime .fromSeconds (Number . parseInt (props .to )))
176181 },
177182)
178183< / script>
0 commit comments