npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-moment-duration-format

v0.2.1

Published

Fiters for use and format Moment.js duration in AngularJS views

Downloads

239

Readme

Angular moment duration format

Fiters for use and format Moment.js duration in AngularJS views

AngularJS filters that lets you use Moment.js duration in your angular views.

Brings moment-duration-format to angular view.

Heavily inpired by angular-moment.


Installation

Node.js

npm install angular-moment-duration-format

Browser

<script src="path/to/angular.js"></script>
<script src="path/to/moment.js"></script>
<script src="path/to/moment-duration-format.js"></script>
<script src="path/to/angular-moment-duration-format.js"></script>

angular-moment-duration-format requires angular.js, moment.js and moment-duration-format.js

Moment is planning to add duration format in its core (see 1048).


Usage

Prerequisite

Add the module angularDurationFormat as a dependency to your app module:

var myapp = angular.module('myapp', ['angularDurationFormat']);

General

Each filter can be used on expression accepted by moment.duration single argument constructor.

Valid inputs:

  • Number length of time in milliseconds
  • Object with seconds, minutes, hours, days, weeks, months, years keys (or short counterpart: y, M, w, d, h, m, s, ms) like {minutes: 2, hours: 2}
  • String hour, minute, second string separated by colons like 23:59:59 or ISO 8601 duration like 'P1Y2M3DT4H5M6S'

To use moment.duration(Number, String) in your view use amdCreate filter, passing the unit as argument.

You can find more detailed information about moment.duration in the official documentation

amdFormat filter

Formats a duration using moment-duration-format format method.

The filter accepts the same parameters of format method:

  • template
  • precision
  • settings

amdHumanize filter

Formats a duration using momentjs humanize() method. See here more info about how moment humanizes duration.

Note that moment documentation has a section about how to customize relative time that be be use to customize output of humanize() and amdHumanize filter.

amdCreate filter

Creates moment.duration specifying unit. Accepts a unit parameter.

Returns ISO string representation of duration, in order to be used together with other filters like amdFormat and amdHumanize

Example:

<span>{{ 15 | amdCreate:'minutes' | amdFormat:'HH:mm' }}</span>
<span>{{ 10 | amdCreate:'hours' | amdHumanize }}</span>

amdAdd filter

Add value to duration. Wraps moment duration add.

Returns ISO string representation of duration.

Example:

<span>{{ myDuration | amdAdd:10:'minutes' | amdFormat:'HH:mm' }}</span>
<span>{{ 10 | amdCreate:'hours' | amdAdd:myOtherDuration | amdFormat:'HH:mm' }}</span>

amdSubtract filter

Subtract value to duration. Wraps moment duration subtract.

Returns ISO string representation of duration.

Example:

<span>{{ myDuration | amdSubtract:10:'minutes' | amdFormat:'HH:mm' }}</span>
<span>{{ 10 | amdCreate:'hours' | amdSubtract:myOtherDuration | amdFormat:'HH:mm' }}</span>

License

Released under the terms of the MIT License.