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

Change time formatting for minutes from 1.50min to 1:30 #153

Merged
merged 1 commit into from
Sep 4, 2018

Conversation

alex-dukhno
Copy link

Hi @jlfwong, I made changes to TimeFormatter to fix #90. Now it should render 1:30min instead of 1.50min

However, I am not very proficient in Typescript and I did an ugly workaround. Maybe you can suggest something more elegant?

@coveralls
Copy link

coveralls commented Aug 24, 2018

Coverage Status

Coverage increased (+0.04%) to 42.156% when pulling 6d44149 on Alex-Diez:time-formatting into 828beb7 on jlfwong:master.

Copy link
Owner

@jlfwong jlfwong left a comment

Choose a reason for hiding this comment

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

Hi @alex-diez! Thanks for taking the time to contribute a change, and also for your humility 😄

I have some suggestions inline. If you address those, I'd be happy to merge this change! If you don't have time to do this today, however, you'll have to wait for about a week since I'll be away from computers for the next week.

It would also be helpful to update the PR description since that will be used to form the commit message to something like "Change time formatting for minutes from 1.50min to 1:30".

@@ -7,15 +7,17 @@ describe('TimeFormatter', () => {
expect(f.format(0.04)).toEqual('40.00µs')
expect(f.format(3)).toEqual('3.00ms')
expect(f.format(2070)).toEqual('2.07s')
expect(f.format(1203123)).toEqual('20.05min')
expect(f.format(150000)).toEqual('2:30min')
Copy link
Owner

Choose a reason for hiding this comment

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

I think just "2:30" is okay rather than "2:30min"

@@ -25,7 +25,16 @@ export class TimeFormatter implements ValueFormatter {
formatUnsigned(v: number) {
const s = v * this.multiplier

if (s / 60 >= 1) return `${(s / 60).toFixed(2)}min`
if (s / 60 >= 1) {
Copy link
Owner

@jlfwong jlfwong Aug 24, 2018

Choose a reason for hiding this comment

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

I think you want something like this (I haven't tested this, but it seems closer to what you'd want).

if (s / 60 >= 1) {
  const minutes = Math.floor(s / 60)
  const seconds = Math.floor(s - minutes * 60)
  return `${minutes}:${zeroPad(seconds, 2)}`.
}

Where zeroPad is a function that you can import from utils.ts:

export function zeroPad(s: string, width: number) {

You can use const instead of let here because the variable is never reassigned.

You might already know this, but in case you don't, you can read about this here: https://wesbos.com/let-vs-const/.

@alex-dukhno alex-dukhno changed the title changed time formmating for minutes Change time formatting for minutes from 1.50min to 1:30 Aug 25, 2018
@alex-dukhno
Copy link
Author

ping @jlfwong. If you are around a computer by this time 😄

@jlfwong jlfwong merged commit 944a6cb into jlfwong:master Sep 4, 2018
@jlfwong
Copy link
Owner

jlfwong commented Sep 4, 2018

Thanks @alex-diez! 🎉

@jlfwong
Copy link
Owner

jlfwong commented Sep 5, 2018

This has now been published & deployed as part of speedscope@1.0.2

@alex-dukhno alex-dukhno deleted the time-formatting branch September 5, 2018 07:50
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.

Better labels for the time axis
3 participants