Socket
Socket
Sign inDemoInstall

angular-relative-date

Package Overview
Dependencies
2
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    angular-relative-date

AngularJS filter to provide relative, human-readable dates.


Version published
Weekly downloads
6.7K
increased by2023.42%
Maintainers
1
Install size
2.32 MB
Created
Weekly downloads
 

Readme

Source

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

KeyDefault value
just_nowjust now
seconds_ago{{time}} seconds ago
a_minute_agoa minute ago
minutes_ago{{time}} minutes ago
an_hour_agoan hour ago
hours_ago{{time}} hours ago
a_day_agoyesterday
days_ago{{time}} days ago
a_week_agoa week ago
weeks_ago{{time}} weeks ago
a_month_agoa month ago
months_ago{{time}} months ago
a_year_agoa year ago
years_ago{{time}} years ago
over_a_year_agoover a year ago
seconds_from_now{{time}} seconds from now
a_minute_from_nowa minute from now
minutes_from_now{{time}} minutes from now
an_hour_from_nowan hour from now
hours_from_now{{time}} hours from now
a_day_from_nowtomorrow
days_from_now{{time}} days from now
a_week_from_nowa week from now
weeks_from_now{{time}} weeks from now
a_month_from_nowa month from now
months_from_now{{time}} months from now
a_year_from_nowa year from now
years_from_now{{time}} years from now
over_a_year_from_nowover 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.

FAQs

Last updated on 02 Jul 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc