feat(date-picker): locale.firstDayOfWeek

This commit is contained in:
07akioni 2021-04-09 02:50:02 +08:00
parent f96ffbf593
commit aaa22493d0
7 changed files with 26 additions and 7 deletions

View File

@ -5,6 +5,7 @@
### Feats
- Add `n-skeleton` component.
- `n-data-picker` locale add `firstDayOfWeek`.
### Fixes

View File

@ -5,6 +5,7 @@
### Feats
- 添加 `n-skeleton` 组件
- `n-data-picker` locale 增加 `firstDayOfWeek`
### Fixes

View File

@ -65,7 +65,8 @@ function useCalendar (
return dateArray(
calendarValueRef.value,
ensureValidValue(props.value),
nowRef.value
nowRef.value,
NDatePicker.locale.firstDayOfWeek
)
})
const weekdaysRef = computed(() => {

View File

@ -80,10 +80,20 @@ function useDualCalendar (
else return 'start'
})
const startDateArrayRef = computed(() => {
return dateArray(startCalendarDateTimeRef.value, props.value, nowRef.value)
return dateArray(
startCalendarDateTimeRef.value,
props.value,
nowRef.value,
NDatePicker.locale.firstDayOfWeek
)
})
const endDateArrayRef = computed(() => {
return dateArray(endCalendarDateTimeRef.value, props.value, nowRef.value)
return dateArray(
endCalendarDateTimeRef.value,
props.value,
nowRef.value,
NDatePicker.locale.firstDayOfWeek
)
})
const weekdaysRef = computed(() => {
return startDateArrayRef.value.slice(0, 7).map((dateItem) => {

View File

@ -98,7 +98,8 @@ function dateItem (
function dateArray (
monthTs: number,
valueTs: number | [number, number] | null,
currentTs: number
currentTs: number,
startDay: 0 | 1 | 2 | 3 | 4 | 5 | 6
): DateItem[] {
const displayMonth = getMonth(monthTs)
// First day of current month
@ -107,7 +108,10 @@ function dateArray (
let lastMonthIterator = getTime(addDays(displayMonthIterator, -1))
const calendarDays = []
let protectLastMonthDateIsShownFlag = true
while (getDay(lastMonthIterator) !== 6 || protectLastMonthDateIsShownFlag) {
while (
getDay(lastMonthIterator) !== startDay ||
protectLastMonthDateIsShownFlag
) {
calendarDays.unshift(
dateItem(lastMonthIterator, monthTs, valueTs, currentTs)
)

View File

@ -29,7 +29,8 @@ const enUS = {
endDatePlaceholder: 'End Date',
startDatetimePlaceholder: 'Start Date and Time',
endDatetimePlaceholder: 'End Date and Time',
monthBeforeYear: true
monthBeforeYear: true,
firstDayOfWeek: 6 as 0 | 1 | 2 | 3 | 4 | 5 | 6
},
DataTable: {
confirm: 'Confirm',

View File

@ -31,7 +31,8 @@ const zhCN: NLocale = {
endDatePlaceholder: '结束日期',
startDatetimePlaceholder: '开始日期时间',
endDatetimePlaceholder: '结束日期时间',
monthBeforeYear: false
monthBeforeYear: false,
firstDayOfWeek: 0
},
DataTable: {
confirm: '确认',