Skip to content
This repository has been archived by the owner on Sep 6, 2020. It is now read-only.

feat: Using a single short duration display format #68

Merged
merged 3 commits into from
Oct 12, 2016

Conversation

yock
Copy link
Contributor

@yock yock commented Oct 12, 2016

re: #67

Copy link
Owner

@J3RN J3RN left a comment

Choose a reason for hiding this comment

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

Hey @yock! 👋

Thanks for the PR! I've got a suggestion to simplify this a little bit, but other than that, this looks great!

hour_string = hours > 0 ? "#{hours} #{'hour'.pluralize(hours)}" : ""

"#{hour_string} #{minute_string}".strip
"#{hour_string}:#{minute_string}".strip
Copy link
Owner

Choose a reason for hiding this comment

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

This implementation yield some odd results, based on how the previous one worked. In the previous implementation, I didn't want to have results like "0h 1m" or "1h 0m", so I made it produce "1m" and "1h" instead, respectively. I did this by setting hour_string or minute string to an empty string if the hour or minute was 0, respectively, up on lines 18 and 19.

All that to say, to simplify this a bit, this line should be "#{'%02d' % hours}:#{'%02d' % minutes}" and lines 18 and 19 removed.

Copy link
Contributor Author

@yock yock Oct 12, 2016

Choose a reason for hiding this comment

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

Thanks @J3RN. I've added a new PR which formats things with leading zeros. I was able to get Postgres (and then the app) running and eyeballed this myself. Now, for instance, a 30 minute duration reads as "00:30" using your specified change. I'd be keen to find a more readable way to write this, but if you're happy, I'm happy.

Copy link
Owner

Choose a reason for hiding this comment

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

@yock Thanks for those, this looks great!

I understand your concern about readability, and it's a concern that I share. RuboCop suggests using hours.format('%02d') over '%02d' % hours (likewise for minutes, of course). Does that seem like a reasonable readability improvement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like it. I'll make the change and push it up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@J3RN Fixnum doesn't contain the format method, but it is on Kernel. The change I pushed up calls format('%02d', hours) instead.

Copy link
Owner

Choose a reason for hiding this comment

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

Whoops! Good call. These changes look ready-to-merge now!

@J3RN
Copy link
Owner

J3RN commented Oct 12, 2016

Fixes #67

@J3RN J3RN merged commit ebb1f0a into J3RN:master Oct 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants