pf-relative

Angular Live Relative Time


Keywords
angular, ng, live, refresh, relative, time, ago, timeago, petrofeed, petro, feed
License
CC-BY-4.0
Install
bower install pf-relative

Documentation

PetroFeed Relative

An AngularJS directive that provides a live relative date (time ago) with cut-off support.

Installation

bower install pf-relative

Usage

angular.module('MyModule', ['pf-relative']);
<time pf-relative="model.createdAt">…</time>

Options

This is how you can set your options (the example uses the default values):

angular.module('MyModule', ['pf-relative'])
.config(function (RelativeDateProvider) {

  var one = RelativeDateProvider.one;

  RelativeDateProvider.options.extend({
    cutoff       : Infinity, // in milliseconds
    cutoffFormat : '%B %d, %Y',
    refreshRates : {
      now        : one.millisecond,
      second     : one.second,
      minute     : one.minute,
      hour       : one.hour,
      day        : one.day,
      weeks      : one.week,
      months     : one.month,
      years      : one.year
    }
  });

});

So, the RelativeDateProvider object exposes the following:

  • RelativeDateProvider.options: where you can read the defined options or call .extend to override the existing ones.
  • RelativeDateProvider.one: A convenience object that provides milliseconds of anything.
  • RelativeDateProvider.ms: The milliseconds module. It can be used when setting { cutoff: ms.days(5) } for example.

Acknowledgements

  • strftime: To provide the cutoffFormat functionality, so please refer to it when defining how your dates should be formatted when they make the cut-off threshold.
  • timeago: Converts a date into a relative, human readable, sentence.

License Creative Commons License

Creative Commons Attribution 4.0 International


Proudly brought to you by PetroFeed.

Pedro