Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Adding duration filtering #20

Closed
gabrielstuff opened this issue Nov 3, 2013 · 8 comments
Closed

Adding duration filtering #20

gabrielstuff opened this issue Nov 3, 2013 · 8 comments

Comments

@gabrielstuff
Copy link
Contributor

Hi !
I'm glad you've done this directive. This is very nice.

I was wondering how do you plan to add the duration method ? I have a number of millisecondes that I'd like to show in hours / minutes, this would use the duraction() from momentjs + humanize.

Should I add a filter, such as :

{{data.duration | amDurationFormat}}

Thanks !

@gabrielstuff
Copy link
Contributor Author

Ok looks like it works :

{{data.duration | amDurationFormat:'milliseconds':true}}

And I just add :

.filter('amDurationFormat', ['$window', function ($window) {
        'use strict';

        return function (value, format, suffix) {
            if (typeof value === 'undefined' || value === null) {
                return '';
            }

            if (!isNaN(parseFloat(value)) && isFinite(value)) {
                return '';
            }

            // else assume the given value is a duration in milliseconds
            return $window.moment.duration(value, format).humanize(suffix);
        };
    }])

I'll try to add the text and then pull request.

@urish
Copy link
Owner

urish commented Nov 4, 2013

Thanks Gabriel!

Please also add tests for the new directive (in the file test.js). You can easily run tests (and also code style checks) by running grunt test from command line. In order to setup this, you need 2 simple steps:

  1. If you don't have grunt install, run npm install -g grunt-cli
  2. Run npm install in the angular-moment source directory

This will allow you to run the tests & jshint by simply typing grunt test. The tests are pretty simple and quick to create, just look how they are done for the amDateFormat directive. If you need any assistance with this, please let me know.

Thank you so much!

@urish
Copy link
Owner

urish commented Nov 9, 2013

Hi Gabriel, how is it going with adding the new filter? If you need any assistance feel free to ping me here

@gabrielstuff
Copy link
Contributor Author

Sorry,

Did not get time to do so :)
Going to do it this weekend.

Thanks,

@urish
Copy link
Owner

urish commented Nov 9, 2013

Excellent, thank you very much Gabriel!

@gabrielstuff
Copy link
Contributor Author

done :)

forking and pulling soon. 

@urish
Copy link
Owner

urish commented Nov 9, 2013

Awesome!

@urish urish closed this as completed in 9d5800e Nov 9, 2013
@urish
Copy link
Owner

urish commented Nov 9, 2013

Thanks, released as 0.5.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants