Skip to content

- Clock Widget: fix bug, better default Handling for: use12Hour, showSeconds#982

Merged
Lissy93 merged 4 commits intoLissy93:masterfrom
Totto16:master
Nov 26, 2022
Merged

- Clock Widget: fix bug, better default Handling for: use12Hour, showSeconds#982
Lissy93 merged 4 commits intoLissy93:masterfrom
Totto16:master

Conversation

@Totto16
Copy link
Copy Markdown
Contributor

@Totto16 Totto16 commented Nov 22, 2022

Totto16 Quick Totto16 /master ↄ1�7 Lissy93/dashy Commits: 4 | Files Changed: 2 | Additions: 2 Label

Category:

Bugfix / Improvement

Overview

config: use12Hour Expected behavior Previous Behavior is correct PR Behavior is correct
unset default to the DateTimeFormat format (eg. en-US true, de-DE false ❄1�7 ✔️
true show AM/PM, always! ❄1�7 ✔️
false show no AM/PM, never! ❄1�7 ✔️

The previous version of the function use12Hour was implemented wrong, it didn't separate the cases, where the options was set or unset. I fixed the behavior and added a lookup in the case, it's unset, now it behaves as expected.

I used the function resolvedOptions() from the DateTimeFormat API, to determine if it's using the 12 Hour format, according to timeZone and format.

Additionally I simplified the function showSeconds, so that the default is set explicitly determined, and not implictly true.

Code Quality Checklist (Please complete)

  • All changes are backwards compatible
  • All lint checks and tests are passing
  • There are no (new) build warnings or errors
  • (If a new config option is added) Attribute is outlined in the schema and documented
  • (If a new dependency is added) Package is essential, and has been checked out for security or performance
  • Bumps version, if new feature added

@Totto16 Totto16 requested a review from Lissy93 as a code owner November 22, 2022 09:58
@netlify
Copy link
Copy Markdown

netlify Bot commented Nov 22, 2022

✄1�7 Deploy Preview for dashy-dev ready!

Name Link
🔨 Latest commit 74370ac
🔍 Latest deploy log https://app.netlify.com/sites/dashy-dev/deploys/637e939d7294bf000860d530
😎 Deploy Preview https://deploy-preview-982--dashy-dev.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@viezly
Copy link
Copy Markdown

viezly Bot commented Nov 22, 2022

Changes preview:

Legend:

👀 Review pull request on Viezly

Comment thread src/components/Widgets/Clock.vue Outdated
return !this.options.hideSeconds;
if (this.options.hideSeconds) return !this.options.hideSeconds;
// this is the default
return true;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Since the ! is converting to a bool as well as negating, there shouldn't be a need to explicitly return true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I know, but its more cleaner and the default is clearly visible, the main question here is, can this defaukt change, here I think it wan't so I agree that the ! is cleaner.

return !this.options.use12Hour;
if (this.options.use12Hour) return this.options.use12Hour;
// this is the default, it gets computed by the DateTimeFormat implementation
return Intl.DateTimeFormat(this.timeFormat, { timeZone: this.timeZone, hour: 'numeric' }).resolvedOptions().hour12 ?? false;
Copy link
Copy Markdown
Owner

@Lissy93 Lissy93 Nov 23, 2022

Choose a reason for hiding this comment

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

👍

Comment thread src/components/Widgets/Clock.vue Outdated
},
use12Hour() {
return !this.options.use12Hour;
if (this.options.use12Hour) return this.options.use12Hour;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

If the user set this.options.use12Hour: false (because they wanted 24-hr), then the first statement would skip, and would user the systems current time. I think to continue with this approach, we'd need to explicitly check for a bool (e.g. typeof this.options.use12Hour == "boolean")

Copy link
Copy Markdown
Owner

@Lissy93 Lissy93 left a comment

Choose a reason for hiding this comment

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

Looks good - thanks for this :)

@Lissy93 Lissy93 merged commit 475a9a1 into Lissy93:master Nov 26, 2022
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.

2 participants