kevinkhill / php-duration

Convert durations of time between colon-formatted, human-readable, and seconds
MIT License
158 stars 26 forks source link

Feature request: force displaying minutes/hours #7

Closed gitomato closed 6 years ago

gitomato commented 8 years ago

Thank you for this library which covers almost all of my needs.

I suggest a feature: if the duration is less than 1 minute, I would like to display 0:32 instead of 32

We could imagine the same for hours: 0:00:32

What do you think?

kevinkhill commented 8 years ago

So adding a zero fill to the humanize method? I don't think it's a bad idea at all. The only problem is that I don't have free time to work on this project. If you feel like adding the feature and writing a test for the test suite and prove it works, I'd happily accept a merge request

AntonLazarev commented 7 years ago

I would try to implement this feature, but I'm thinking of making different method, something like formattedWithZeroes($showHoursOnZero = false). Parameter $showHoursOnZero decides how to show string 0:32 or 0:00:32. What do you think about it?

kevinkhill commented 7 years ago

If you want to implement this, by all means go ahead! I'd be happy to merge it.

All I ask is that you please follow my coding style and write tests for the feature.

Ydalb commented 6 years ago

Heya folk's, just opened a PR for this. Tell me how it looks like.

// Tests :
        $this->assertEquals('0:00:04', $this->d->formatted(4, true));
        $this->assertEquals('0:00:09', $this->d->formatted(9, true));
        $this->assertEquals('0:00:42', $this->d->formatted(42, true));
        $this->assertEquals('0:01:02', $this->d->formatted(62, true));
        $this->assertEquals('0:01:09', $this->d->formatted(69, true));
        $this->assertEquals('0:01:42', $this->d->formatted(102, true));
        $this->assertEquals('0:10:47', $this->d->formatted(647, true));
        $this->assertEquals('1:00:00', $this->d->formatted(3600, true));
        $this->assertEquals('1:00:01', $this->d->formatted(3601, true));
        $this->assertEquals('1:00:11', $this->d->formatted(3611, true));
        $this->assertEquals('1:01:00', $this->d->formatted(3660, true));
        $this->assertEquals('1:01:14', $this->d->formatted(3674, true));
        $this->assertEquals('1:04:25', $this->d->formatted(3865, true));
        $this->assertEquals('1:09:09', $this->d->formatted(4149, true));

Regards,

kevinkhill commented 6 years ago

Merged!

kevinkhill commented 6 years ago

Thanks for the contribution 😊