angular-relative-date

AngularJS relative date filter , support multilingual . e.g: " 1 second ago"

Module License: MIT

Added by: Sam Deering

GitHub

Repository

ariesjia/angular-relative-date

Stats

Stars: 4

Watchers: 4

Forks: 0

Author

Chenjia
Chenjia

Module Description

angular-relative-date


Getting Started

Download the production version or the development version.

Usage

  1. Add the js to your HTML code.
<script src="dist/angular-relative-date.min.js"></script>
  1. Add dependency to your app modules
angular.module('myApp', ['quark.relativeDate'])
  1. use relativeDate or relativeDateFilterin your code
<strong>{{ testDate | relativeDate}}</strong>

or in script

var relativeDate = relativeDateFilter(testDate);

Label

// en  --- default
relativeDateFilterProvider.labelText = {
    now: "now",
    before_second: {"one" : "%n second ago" , "more" : "%n seconds ago"},
    before_minute: {"one" : "%n minute ago" , "more" : "%n minutes ago"},
    before_hour: {"one" : "%n hour ago" , "more" : "%n hours ago"},
    before_day: {"one" : "%n day ago" , "more" : "%n days ago"},

    after_second: {"one" : "%n second left" , "more" : "%n seconds left"},
    after_minute: {"one" : "%n minute left" , "more" : "%n minutes left"},
    after_hour: {"one" : "%n hour left" , "more" : "%n hours left"},
    after_day: {"one" : "%n day left" , "more" : "%n days left"}
};
// zh-cn
relativeDateFilterProvider.labelText = {
    now: "现在",
    before_second: "%n秒钟前",
    before_minute: "%n分钟前",
    before_hour: "%n小时前",
    before_day: "%n天前",

    after_second: "还剩%n秒钟",
    after_minute: "还剩%n分钟",
    after_hour: "还剩%n小时",
    after_day: "还剩%n天"
};

Demo

$scope.testDate = new Date();

testDate | relativeDate
result : now



$scope.testDate1 = new Date() - 1111;

testDate1 | relativeDate
result : 1 second ago



$scope.testDate2 = new Date() - 289733;

testDate2 | relativeDate
result : 4 minutes ago



$scope.testDate3 = new Date() - 872374;

testDate3 | relativeDate
result : 14 minutes ago



$scope.testDate4 = new Date() - 9333333;

testDate4 | relativeDate 
result : 2 hours ago



$scope.testDate5 = new Date() - 847484040;

testDate5 | relativeDate
result : 2014-05-02



$scope.testDate6 = new Date().getTime() + 3000;

testDate6 | relativeDate
result : 3 seconds left



$scope.testDate7 = new Date().getTime() + 848300;

testDate7 | relativeDate
result : 15 minutes left



$scope.testDate9 = new Date().getTime() + 1292228300;

testDate9 | relativeDate
result : 15 days left

generated by angular-component

Module stats last updated: 2015-06-07 05:25:39

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!