-
Notifications
You must be signed in to change notification settings - Fork 330
fix(calendar-view): [calendar-view] modify the configuration of calendar view hours, minutes, and seconds, and adding an attribute #2932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
39e0c6c
a8d3399
6ef8872
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -104,15 +104,31 @@ export const parseDate = (time) => { | |||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| date = new Date() | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||
| year: date.getFullYear(), | ||||||||||||||||||||||||||||||||
| month: date.getMonth() + 1, | ||||||||||||||||||||||||||||||||
| day: date.getDate(), | ||||||||||||||||||||||||||||||||
| hours: date.getHours(), | ||||||||||||||||||||||||||||||||
| minutes: date.getMinutes(), | ||||||||||||||||||||||||||||||||
| seconds: date.getSeconds() | ||||||||||||||||||||||||||||||||
| // 识别无时分秒的日期时间 | ||||||||||||||||||||||||||||||||
| const timeParts = hasNoTime(time) | ||||||||||||||||||||||||||||||||
| let timesPartsOne = {} | ||||||||||||||||||||||||||||||||
| let timesPartsTwo = {} | ||||||||||||||||||||||||||||||||
| if (!timeParts.hours) { | ||||||||||||||||||||||||||||||||
| timesPartsOne = { | ||||||||||||||||||||||||||||||||
| year: timeParts.year, | ||||||||||||||||||||||||||||||||
| month: timeParts.month, | ||||||||||||||||||||||||||||||||
| day: timeParts.day, | ||||||||||||||||||||||||||||||||
| hours: 0, | ||||||||||||||||||||||||||||||||
| minutes: 0, | ||||||||||||||||||||||||||||||||
| seconds: 0 | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| timesPartsTwo = { | ||||||||||||||||||||||||||||||||
| year: date.getFullYear(), | ||||||||||||||||||||||||||||||||
| month: date.getMonth() + 1, | ||||||||||||||||||||||||||||||||
| day: date.getDate(), | ||||||||||||||||||||||||||||||||
| hours: date.getHours(), | ||||||||||||||||||||||||||||||||
| minutes: date.getMinutes(), | ||||||||||||||||||||||||||||||||
| seconds: date.getSeconds() | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| const timePartsList = Object.assign(timesPartsOne, timesPartsTwo) | ||||||||||||||||||||||||||||||||
| return timePartsList | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| export const computedCalendar = | ||||||||||||||||||||||||||||||||
|
|
@@ -160,6 +176,36 @@ const getCalendarItem = function (item, props, isFunction, type, isNext, isLast) | |||||||||||||||||||||||||||||||
| return res | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const hasNoTime = (date) => { | ||||||||||||||||||||||||||||||||
| const datetimeStr = date | ||||||||||||||||||||||||||||||||
| let hoursTime = 0 | ||||||||||||||||||||||||||||||||
| let minutesTime = 0 | ||||||||||||||||||||||||||||||||
| let secondsTime = 0 | ||||||||||||||||||||||||||||||||
| const [datePart, timePart] = datetimeStr.split(' ') | ||||||||||||||||||||||||||||||||
| const [year, month, day] = datePart && datePart.split('-') | ||||||||||||||||||||||||||||||||
| if (timePart) { | ||||||||||||||||||||||||||||||||
| const [hours, minutes, seconds] = timePart && timePart.split(':') | ||||||||||||||||||||||||||||||||
| hoursTime = hours | ||||||||||||||||||||||||||||||||
| minutesTime = minutes | ||||||||||||||||||||||||||||||||
| secondsTime = seconds | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| // 提取时间 | ||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||
| year: Number(year), | ||||||||||||||||||||||||||||||||
| month: Number(month), | ||||||||||||||||||||||||||||||||
| day: Number(day), | ||||||||||||||||||||||||||||||||
| hours: hoursTime, | ||||||||||||||||||||||||||||||||
| minutes: minutesTime, | ||||||||||||||||||||||||||||||||
| seconds: secondsTime | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| // 时间转GMT8 | ||||||||||||||||||||||||||||||||
| const timesToGMT8 = (date) => { | ||||||||||||||||||||||||||||||||
| const originalDate = new Date(date) | ||||||||||||||||||||||||||||||||
| const gmt8 = new Date(originalDate.getTime() + 15 * 60 * 60 * 1000) | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The conversion to GMT+8 seems incorrect. The offset should be 8 hours, not 15. Please verify the logic for time zone conversion. |
||||||||||||||||||||||||||||||||
| return gmt8 | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+203
to
+207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve timezone handling in The function has several issues:
Consider this improved implementation: -const timesToGMT8 = (date) => {
+const timesToGMT8 = (date: string | number | Date): Date => {
+ const GMT_8_OFFSET = 8; // Hours
+ const HOURS_TO_MS = 60 * 60 * 1000;
+
const originalDate = new Date(date)
- const gmt8 = new Date(originalDate.getTime() + 15 * 60 * 60 * 1000)
+ const utcOffset = originalDate.getTimezoneOffset() / 60;
+ const offsetHours = GMT_8_OFFSET + utcOffset;
+ const gmt8 = new Date(originalDate.getTime() + offsetHours * HOURS_TO_MS)
return gmt8
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| export const handleEvents = | ||||||||||||||||||||||||||||||||
| ({ props, state }) => | ||||||||||||||||||||||||||||||||
| () => { | ||||||||||||||||||||||||||||||||
|
|
@@ -197,14 +243,23 @@ export const handleEvents = | |||||||||||||||||||||||||||||||
| ([lastYear, +state.activeYear, nextYear].includes(endYear) && | ||||||||||||||||||||||||||||||||
| [lastMon, +state.activeMonth, nextMon].includes(endMonth)) | ||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||
| item.start = getTime(item.start) | ||||||||||||||||||||||||||||||||
| item.end = getTime(item.end) | ||||||||||||||||||||||||||||||||
| item.startTime = makeUpZero(startHours) + ':' + makeUpZero(startMinutes) + ':' + makeUpZero(startSeconds) | ||||||||||||||||||||||||||||||||
| item.endTime = makeUpZero(endHours) + ':' + makeUpZero(endMinutes) + ':' + makeUpZero(endSeconds) | ||||||||||||||||||||||||||||||||
| const timeStartPart = hasNoTime(item.start) | ||||||||||||||||||||||||||||||||
| const timeEndPart = hasNoTime(item.end) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| item.start = timeStartPart.hours ? getTime(item.start) : timesToGMT8(item.start) | ||||||||||||||||||||||||||||||||
| item.end = timeEndPart.hours ? getTime(item.end) : timesToGMT8(item.end) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| item.startTime = timeStartPart.hours | ||||||||||||||||||||||||||||||||
| ? makeUpZero(startHours) + ':' + makeUpZero(startMinutes) + ':' + makeUpZero(startSeconds) | ||||||||||||||||||||||||||||||||
| : '' | ||||||||||||||||||||||||||||||||
| item.endTime = timeEndPart.hours | ||||||||||||||||||||||||||||||||
| ? makeUpZero(endHours) + ':' + makeUpZero(endMinutes) + ':' + makeUpZero(endSeconds) | ||||||||||||||||||||||||||||||||
| : '' | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| item.startDay = startYear + '-' + startMonth + '-' + startDay | ||||||||||||||||||||||||||||||||
| item.endDay = endYear + '-' + endMonth + '-' + endDay | ||||||||||||||||||||||||||||||||
| const startTimestamp = getTime(startYear + '-' + startMonth + '-' + startDay) | ||||||||||||||||||||||||||||||||
| const endTimestamp = getTime(endYear + '-' + endMonth + '-' + endDay) | ||||||||||||||||||||||||||||||||
| const startTimestamp = getTime(item.startDay) | ||||||||||||||||||||||||||||||||
| const endTimestamp = getTime(item.endDay) | ||||||||||||||||||||||||||||||||
| const days = Math.abs(endTimestamp - startTimestamp) / dayMillisecond | ||||||||||||||||||||||||||||||||
| item.dayNumber = days >= 1 ? days + 1 : 1 | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,10 +20,10 @@ | |||||||||||||
| </template> | ||||||||||||||
| </tiny-tooltip> | ||||||||||||||
| <div data-tag="tiny-calendar-view-today" class="flex justify-around items-center mb-3"> | ||||||||||||||
| <tiny-button @click="toToday">{{ t('ui.calendarView.backToday') }}</tiny-button> | ||||||||||||||
| <tiny-button v-if="showBackToday" @click="toToday">{{ t('ui.calendarView.backToday') }}</tiny-button> | ||||||||||||||
| <tiny-date-picker | ||||||||||||||
| v-model="state.currentDate" | ||||||||||||||
| class="ml-5 shrink-0" | ||||||||||||||
| :class="[showBackToday ? 'ml-5' : '', 'shrink-0']" | ||||||||||||||
| shape="filter" | ||||||||||||||
| type="month" | ||||||||||||||
| :clearable="false" | ||||||||||||||
|
|
@@ -292,7 +292,7 @@ | |||||||||||||
| :key="idx" | ||||||||||||||
| class="py-1.5 h-auto border border-color-border-separator rounded mb-2 shadow-sm" | ||||||||||||||
| > | ||||||||||||||
| <div class="px-1.5 mb-1.5 border-l-2 border-color-brand">{{ event.title }}</div> | ||||||||||||||
| <div class="px-1.5 mb-1.5 border-l-2 border-color-brand break-all">{{ event.title }}</div> | ||||||||||||||
| <div class="mb-1.5 px-2 text-color-text-placeholder"> | ||||||||||||||
| {{ getEventShowTime('start', event, date.value) }} - {{ getEventShowTime('end', event, date.value) }} | ||||||||||||||
| </div> | ||||||||||||||
|
|
@@ -376,7 +376,8 @@ export default defineComponent({ | |||||||||||||
| 'events', | ||||||||||||||
| 'height', | ||||||||||||||
| 'mark-color', | ||||||||||||||
| 'multi-select' | ||||||||||||||
| 'multi-select', | ||||||||||||||
| 'showBackToday' | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Define prop type and default value for The prop is added without type checking or a default value, which could lead to runtime issues. Add type definition and default value: - 'showBackToday'
+ {
+ name: 'showBackToday',
+ type: Boolean,
+ default: true
+ }📝 Committable suggestion
Suggested change
|
||||||||||||||
| ], | ||||||||||||||
| setup(props, context) { | ||||||||||||||
| return setup({ | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add input validation and type safety to
hasNoTimefunction.The function needs better error handling and type safety:
Consider this safer implementation:
📝 Committable suggestion
🧰 Tools
🪛 Biome (1.9.4)
[error] 185-187: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 187-188: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)