Skip to content
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

fix: local fromNow format timezone-aware #219

Merged
merged 2 commits into from
May 6, 2024
Merged

fix: local fromNow format timezone-aware #219

merged 2 commits into from
May 6, 2024

Conversation

duyet
Copy link
Owner

@duyet duyet commented May 6, 2024

Fix #54

Copy link

vercel bot commented May 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clickhouse-monitoring ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2024 11:36am

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @duyet - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 3 issues found
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

components/data-table/cells/related-time-format.tsx Outdated Show resolved Hide resolved
try {
if (!tz) {
// Getting timezone from server
tz = await fetch('/api/timezone')
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code_refinement): Consider error handling for the fetch request to improve reliability.

Adding error handling for the fetch request can prevent the application from breaking if the API call fails.

Suggested change
tz = await fetch('/api/timezone')
try {
const response = await fetch('/api/timezone');
if (!response.ok) {
throw new Error('Failed to fetch timezone');
}
const data = await response.json();
tz = data.tz;
} catch (error) {
console.error('Error fetching timezone:', error);
}

fromNow = parsed.fromNow()
} catch (e) {
console.error('Error parsing time:', e)
fromNow = dayjs(value as string).fromNow()
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Fallback logic in catch block may not consider timezone.

The fallback logic uses the default timezone instead of the server timezone, which might not be intended.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Will not using timezone here

@@ -0,0 +1,28 @@
import dayjs from '@/lib/dayjs'
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Missing test for RelatedTimeFormat component

The new RelatedTimeFormat component handles timezone-aware formatting. It's crucial to ensure this component behaves as expected under various conditions, including edge cases like invalid date formats or null values. Please add unit tests to verify the functionality and error handling.

Suggested change
import dayjs from '@/lib/dayjs'
import dayjs from '@/lib/dayjs'
import timezone from 'dayjs/plugin/timezone'
import utc from 'dayjs/plugin/utc'
dayjs.extend(timezone)
dayjs.extend(utc)

@@ -0,0 +1,13 @@
import dayjs from '@/lib/dayjs'
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Missing test for DurationFormat component

The DurationFormat component has been introduced to handle human-readable duration formatting. Testing this component is essential to ensure it accurately converts various duration inputs into the correct format. Please add tests to cover typical, boundary, and erroneous input scenarios.

@@ -1,10 +1,14 @@
import dayjs from 'dayjs'
import duration from 'dayjs/plugin/duration'
import relativeTime from 'dayjs/plugin/relativeTime'
import timezone from 'dayjs/plugin/timezone'
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Consider adding tests for timezone and UTC configurations in dayjs

With the addition of timezone and UTC plugins to the dayjs configuration, it's important to verify that these settings are correctly applied across the application. This could involve checking the correct timezone adjustments and UTC handling in date/time calculations.

Suggested change
import timezone from 'dayjs/plugin/timezone'
import timezone from 'dayjs/plugin/timezone'
dayjs.extend(timezone)

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Signed-off-by: Duyet Le <5009534+duyet@users.noreply.github.com>
@duyet duyet merged commit f5a211e into main May 6, 2024
10 checks passed
@duyet duyet deleted the fix/timezone branch May 6, 2024 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix timezone on related format
1 participant