Skip to content

Conversation

@James-9696
Copy link
Collaborator

@James-9696 James-9696 commented Feb 20, 2025

PR

第一个修改点:
修改前:日历显示有问题,25号,日历视图上显示24号
image
修改后:日期显示正常及悬浮的tooltips上的提示信息事件,显示 2023-5-25 ~ 2023-5-28
image

第二个修改点:
如图:mobile-first新增showBackToday属性,控制左上角按钮是否显示,设置为false,不显示“回今天”的按钮。
image

image

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced the calendar’s event processing to better handle dates missing explicit time details.
    • Improved the logic for parsing dates and adjusting local time settings, ensuring events display accurate timing even when time components are not provided.
    • Added a new property show-back-today to control the visibility of the "back to today" button in the calendar view.
  • Improvements

    • Updated the calendar view to dynamically render the "back to today" button based on the showBackToday property.

@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2025

Walkthrough

The changes update the calendar view’s date handling and introduce a new property for controlling the display of a button. A new function hasNoTime is added to identify when a date string lacks explicit time information, providing default values for hour, minute, and second. The parseDate function now uses separate time parts objects based on the presence of time, and the handleEvents function has been refactored to utilize these new functions to adjust event start and end times accordingly. Additionally, a new property show-back-today is added to the calendar-view component, allowing for toggling the visibility of a "back to today" button.

Changes

File(s) Change Summary
packages/renderless/.../calendar-view/index.ts - Added new functions hasNoTime and timesToGMT8
- Modified parseDate to handle and merge default time values
- Updated handleEvents to use the new logic for processing event start and end times
examples/sites/demos/apis/calendar-view.js - Added new property show-back-today of type boolean with default value true in the props array of the calendar-view component
examples/sites/demos/mobile-first/app/calendar-view/calendar-mode.vue - Introduced :show-back-today prop in <tiny-calendar-view> component, set to false
examples/sites/demos/mobile-first/app/calendar-view/webdoc/calendar-view.js - Updated English and Chinese descriptions for the demo to clarify the functionality of the show-back-today attribute
packages/vue/src/calendar-view/src/index.ts - Added new property showBackToday: { type: Boolean, default: true } in calendarViewProps
packages/vue/src/calendar-view/src/mobile-first.vue - Added conditional rendering for the "backToday" button based on showBackToday
- Updated class binding for tiny-date-picker based on showBackToday
- Declared showBackToday as a prop in the component's interface

Suggested reviewers

  • zzcr

Poem

I'm a bunny with a code so fine,
Hopping through dates and time entwined.
Missing hours? I set defaults on the fly,
With hasNoTime, no moment passes by.
A button to hop back, oh what a delight,
In the calendar's glow, we dance through the night! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/vue/src/calendar-view/src/mobile-first.vue

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8d3399 and 6ef8872.

📒 Files selected for processing (1)
  • packages/vue/src/calendar-view/src/mobile-first.vue (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/vue/src/calendar-view/src/mobile-first.vue
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the bug Something isn't working label Feb 20, 2025
@petercat-assistant
Copy link

Walkthrough

This pull request addresses a bug in the calendar view by modifying the configuration of hours, minutes, and seconds. It introduces functions to handle date-time parsing and conversion, ensuring proper handling of time zones and default values when time parts are missing.

Changes

File Summary
packages/renderless/src/calendar-view/index.ts Refactored to include new functions hasNoTime and timesToGMT8 for handling date-time parsing and conversion. Adjusted logic to handle missing time parts and ensure correct time zone conversion.

// 时间转GMT8
const timesToGMT8 = (date) => {
const originalDate = new Date(date)
const gmt8 = new Date(originalDate.getTime() + 15 * 60 * 60 * 1000)

Choose a reason for hiding this comment

The 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/renderless/src/calendar-view/index.ts (1)

98-132: Simplify and optimize the parseDate function.

The function's logic can be simplified and optimized:

  1. Complex branching with multiple objects
  2. Missing type definitions
  3. Unnecessary object creation and merging

Consider this simplified implementation:

-export const parseDate = (time) => {
+export const parseDate = (time: string): DateTimeParts => {
   /* istanbul ignore next */
-  let date = {}
+  let date = new Date()
 
   if (new Date(time) !== 'Invalid Date') {
     date = new Date(time)
   } else {
     date = new Date()
   }
 
-  // 识别无时分秒的日期时间
   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
+  return timeParts.hours ? {
+    year: date.getFullYear(),
+    month: date.getMonth() + 1,
+    day: date.getDate(),
+    hours: date.getHours(),
+    minutes: date.getMinutes(),
+    seconds: date.getSeconds()
+  } : timeParts
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1957cbf and 39e0c6c.

📒 Files selected for processing (1)
  • packages/renderless/src/calendar-view/index.ts (3 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/renderless/src/calendar-view/index.ts

[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)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (1)
packages/renderless/src/calendar-view/index.ts (1)

246-258:

❓ Verification inconclusive

Verify timezone handling for events.

The event time conversion logic needs careful verification:

  1. Ensure correct handling of events across different timezones
  2. Verify that GMT+8 conversion doesn't cause issues with daylight saving time

Please verify the timezone handling by testing with events from different timezones:


🏁 Script executed:

#!/bin/bash
# Description: Find all event time handling code to verify timezone logic

# Search for timezone-related code
echo "Searching for timezone-related code..."
rg -n "getTime|GMT|timezone|UTC" --type ts

# Search for date manipulation code
echo "Searching for date manipulation code..."
ast-grep --pattern 'new Date($$$)'

Length of output: 65829


Action Required: Verify and Test Timezone Handling for Calendar Events

The updated calendar view conversion logic now uses hasNoTime, getTime, and timesToGMT8 to set event times. Please manually verify the following:

  • Event Time Data: Confirm that events with explicit time values are correctly processed by getTime, while those without time information use the timesToGMT8 conversion.
  • Fixed Offset Logic: Validate that adding a fixed 15-hour offset in timesToGMT8 reliably converts dates to GMT+8 without introducing issues—especially around daylight saving time transitions.
  • Cross-Timezone Scenarios: Test with events originating from multiple timezones to ensure the conversion behaves as expected across diverse settings.

Given the automated search results didn't yield conclusive evidence and potential DST edge cases might exist, please add or update unit tests to cover these scenarios.

Comment on lines +203 to +207
const timesToGMT8 = (date) => {
const originalDate = new Date(date)
const gmt8 = new Date(originalDate.getTime() + 15 * 60 * 60 * 1000)
return gmt8
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve timezone handling in timesToGMT8 function.

The function has several issues:

  1. Hardcoded magic number for hour offset
  2. No type definitions
  3. Potential timezone conversion 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const timesToGMT8 = (date) => {
const originalDate = new Date(date)
const gmt8 = new Date(originalDate.getTime() + 15 * 60 * 60 * 1000)
return gmt8
}
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 utcOffset = originalDate.getTimezoneOffset() / 60;
const offsetHours = GMT_8_OFFSET + utcOffset;
const gmt8 = new Date(originalDate.getTime() + offsetHours * HOURS_TO_MS)
return gmt8
}

Comment on lines +179 to +201
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
}
}
Copy link

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 hasNoTime function.

The function needs better error handling and type safety:

  1. Missing input validation
  2. Potential null/undefined issues with split operations
  3. No TypeScript type definitions

Consider this safer implementation:

-const hasNoTime = (date) => {
+const hasNoTime = (date: string): DateTimeParts => {
+  if (!date || typeof date !== 'string') {
+    throw new Error('Invalid date string provided');
+  }
+
   const datetimeStr = date
   let hoursTime = 0
   let minutesTime = 0
   let secondsTime = 0
-  const [datePart, timePart] = datetimeStr.split(' ')
+  const [datePart = '', timePart] = datetimeStr.split(' ')
-  const [year, month, day] = datePart && datePart.split('-')
+  const [year = '0', month = '0', day = '0'] = datePart?.split('-') ?? []
   if (timePart) {
-    const [hours, minutes, seconds] = timePart && timePart.split(':')
+    const [hours = '0', minutes = '0', seconds = '0'] = timePart?.split(':') ?? []
     hoursTime = hours
     minutesTime = minutes
     secondsTime = seconds
   }
   return {
     year: Number(year),
     month: Number(month),
     day: Number(day),
     hours: hoursTime,
     minutes: minutesTime,
     seconds: secondsTime
   }
}

+interface DateTimeParts {
+  year: number;
+  month: number;
+  day: number;
+  hours: number;
+  minutes: number;
+  seconds: number;
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
}
}
const hasNoTime = (date: string): DateTimeParts => {
if (!date || typeof date !== 'string') {
throw new Error('Invalid date string provided');
}
const datetimeStr = date
let hoursTime = 0
let minutesTime = 0
let secondsTime = 0
const [datePart = '', timePart] = datetimeStr.split(' ')
const [year = '0', month = '0', day = '0'] = datePart?.split('-') ?? []
if (timePart) {
const [hours = '0', minutes = '0', seconds = '0'] = timePart?.split(':') ?? []
hoursTime = hours
minutesTime = minutes
secondsTime = seconds
}
// 提取时间
return {
year: Number(year),
month: Number(month),
day: Number(day),
hours: hoursTime,
minutes: minutesTime,
seconds: secondsTime
}
}
interface DateTimeParts {
year: number;
month: number;
day: number;
hours: number;
minutes: number;
seconds: number;
}
🧰 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)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
examples/sites/demos/mobile-first/app/calendar-view/webdoc/calendar-view.js (1)

27-27: Fix spacing in English description.

Add spaces around the code block for better readability.

-          '<p>The <code>mode</code> attribute specifies that each month of the current year is displayed. The options are <code>month</code> / <code>timeline</code> / <code>schedule</code>. Control the display of the left button through the<code>show back today</code>attribute.</p>\n'
+          '<p>The <code>mode</code> attribute specifies that each month of the current year is displayed. The options are <code>month</code> / <code>timeline</code> / <code>schedule</code>. Control the display of the left button through the <code>show back today</code> attribute.</p>\n'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39e0c6c and a8d3399.

📒 Files selected for processing (5)
  • examples/sites/demos/apis/calendar-view.js (1 hunks)
  • examples/sites/demos/mobile-first/app/calendar-view/calendar-mode.vue (1 hunks)
  • examples/sites/demos/mobile-first/app/calendar-view/webdoc/calendar-view.js (1 hunks)
  • packages/vue/src/calendar-view/src/index.ts (1 hunks)
  • packages/vue/src/calendar-view/src/mobile-first.vue (2 hunks)
🔇 Additional comments (5)
packages/vue/src/calendar-view/src/index.ts (1)

80-83: LGTM! Well-structured prop definition.

The new showBackToday property is correctly defined with appropriate type and default value.

examples/sites/demos/apis/calendar-view.js (1)

175-188: LGTM! Comprehensive API documentation.

The new property is well-documented with:

  • Clear bilingual descriptions
  • Correct type and default value
  • Version tracking via meta information
  • Appropriate demo reference
examples/sites/demos/mobile-first/app/calendar-view/calendar-mode.vue (1)

2-8: LGTM! Clear demonstration of the new property.

The demo effectively shows how to disable the "back to today" button using the new prop.

packages/vue/src/calendar-view/src/mobile-first.vue (2)

23-23: Verify layout consistency when showBackToday is false.

The removal of margin when showBackToday is false could cause layout issues:

  1. The date picker might appear misaligned without the left margin
  2. The spacing between elements might become inconsistent

Please test the component's layout in both states (with and without the "back to today" button) to ensure visual consistency.

Also applies to: 26-26


23-26: Changes seem unrelated to the PR's objective.

The PR aims to fix date display issues (specifically for May 25th), but these changes only affect the UI layout and button visibility. The date parsing and display logic modifications mentioned in the PR objectives are not reflected in these changes.

Could you clarify how these UI changes relate to fixing the date display issue? The core date handling logic might need to be addressed separately.

'mark-color',
'multi-select'
'multi-select',
'showBackToday'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Define prop type and default value for showBackToday.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'showBackToday'
{
name: 'showBackToday',
type: Boolean,
default: true
}

@James-9696 James-9696 changed the title fix(calendar-view): [calendar-view] modify the configuration of calendar view hours, minutes, and seconds fix(calendar-view): [calendar-view] modify the configuration of calendar view hours, minutes, and seconds, and adding an Attribute Feb 20, 2025
@James-9696 James-9696 changed the title fix(calendar-view): [calendar-view] modify the configuration of calendar view hours, minutes, and seconds, and adding an Attribute fix(calendar-view): [calendar-view] modify the configuration of calendar view hours, minutes, and seconds, and adding an attribute Feb 20, 2025
@zzcr zzcr closed this Feb 21, 2025
@zzcr zzcr reopened this Feb 21, 2025
@zzcr zzcr merged commit 43deeb7 into dev Feb 21, 2025
10 of 13 checks passed
@kagol kagol deleted the fix-0220-calendar-view branch April 14, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants