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-relative-date

v2.1.1

Published

AngularJS filter to provide relative, human-readable dates.

Downloads

4,086

Readme

angular-relative-date

Build Status

AngularJS filter for creating relative, human-readable dates.

A vanilla JavaScript (i.e. not Angular) version of this module is available: wildlyinaccurate/tiny-relative-date

Usage

For regular usage, just download and include dist/angular-relative-date.js in your application.

<script src="angular-relative-date.js"></script>

You can also use the ES6 module directly using a packaging tool like browserify or webpack.

import relativeDate from 'angular-relative-date'

Add the relativeDate module to your application's dependencies.

angular.module('myApp', ['relativeDate']);

Use the filter by passing it date strings or Date objects.

<script>
angular.module('myApp', ['relativeDate']).controller('MainCtrl', function($scope) {
    $scope.dateString = '2015-05-08';
    $scope.dateObject = new Date();
});
</script>

<p>Date strings work: <strong>{{ dateString | relativeDate }}</strong></p>
<p>And so do <code>Date</code> objects: <strong>{{ dateObject | relativeDate }}</strong></p>

The above example will look something like this:

Date strings work: a week ago

And so do Date objects: just now

i18n

Simple internationalisation support is available via the relativeDateTranslations value. See below for all available translation keys.

<script>
angular.module('myApp', ['relativeDate'])
       .value('relativeDateTranslations', {
            just_now: '今'
       })
       .controller('MainCtrl', function($scope) {
            $scope.lastUpdated = new Date();
        });
</script>

<p>Last updated: <strong>{{ lastUpdated | relativeDate }}</strong></p>

The above will output:

Last updated:

As well as the built-in translation, angular-translate is also supported. Simply add the translation keys to your $translateProvider.

myApp.config(function ($translateProvider) {
    $translateProvider.translations('en', {
        just_now: 'just now',
        seconds_ago: '{{time}} seconds ago',
    });

    $translateProvider.translations('de', {
        just_now: 'soeben',
        seconds_ago: 'vor {{time}} stunden',
    });

    $translateProvider.preferredLanguage('en');
});

Translation keys

| Key | Default value | |------------------------|---------------------------| | just_now | just now | | seconds_ago | {{time}} seconds ago | | a_minute_ago | a minute ago | | minutes_ago | {{time}} minutes ago | | an_hour_ago | an hour ago | | hours_ago | {{time}} hours ago | | a_day_ago | yesterday | | days_ago | {{time}} days ago | | a_week_ago | a week ago | | weeks_ago | {{time}} weeks ago | | a_month_ago | a month ago | | months_ago | {{time}} months ago | | a_year_ago | a year ago | | years_ago | {{time}} years ago | | over_a_year_ago | over a year ago | | seconds_from_now | {{time}} seconds from now | | a_minute_from_now | a minute from now | | minutes_from_now | {{time}} minutes from now | | an_hour_from_now | an hour from now | | hours_from_now | {{time}} hours from now | | a_day_from_now | tomorrow | | days_from_now | {{time}} days from now | | a_week_from_now | a week from now | | weeks_from_now | {{time}} weeks from now | | a_month_from_now | a month from now | | months_from_now | {{time}} months from now | | a_year_from_now | a year from now | | years_from_now | {{time}} years from now | | over_a_year_from_now | over a year from now |

Contributing

Please modify angular-relative-date.coffee and then run grunt build to compile and minify the JavaScript (you may need to run npm install first).

Submit your change as a pull request, including a description of the change. Please be sure to add any relevant test cases to test/spec/relativ-date-filter.js.

License

Released under the terms of MIT License:

The MIT License (MIT)

Copyright (c) 2015 Joseph Wynn

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.