time-ago-pipe
Advanced tools
Comparing version 1.3.1 to 1.3.2
@@ -30,3 +30,3 @@ (function (global, factory) { | ||
var /** @type {?} */ seconds = Math.round(Math.abs((now.getTime() - d.getTime()) / 1000)); | ||
var /** @type {?} */ timeToUpdate = this.getSecondsUntilUpdate(seconds) * 1000; | ||
var /** @type {?} */ timeToUpdate = (Number.isNaN(seconds)) ? 1000 : this.getSecondsUntilUpdate(seconds) * 1000; | ||
this.timer = this.ngZone.runOutsideAngular(function () { | ||
@@ -45,3 +45,6 @@ if (typeof window !== 'undefined') { | ||
var /** @type {?} */ years = Math.round(Math.abs(days / 365)); | ||
if (seconds <= 45) { | ||
if (Number.isNaN(seconds)) { | ||
return ''; | ||
} | ||
else if (seconds <= 45) { | ||
return 'a few seconds ago'; | ||
@@ -105,3 +108,3 @@ } | ||
if (seconds < min) { | ||
// less than 1 min, update ever 2 secs | ||
// less than 1 min, update every 2 secs | ||
return 2; | ||
@@ -108,0 +111,0 @@ } |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define(["exports","@angular/core"],t):t(e["time-ago-pipe"]={},e.ng.core)}(this,function(e,t){"use strict";var n=function(){function e(e,t){this.changeDetectorRef=e,this.ngZone=t}return e.prototype.transform=function(e){var t=this;this.removeTimer();var n=new Date(e),o=new Date,r=Math.round(Math.abs((o.getTime()-n.getTime())/1e3)),a=1e3*this.getSecondsUntilUpdate(r);this.timer=this.ngZone.runOutsideAngular(function(){return"undefined"!=typeof window?window.setTimeout(function(){t.ngZone.run(function(){return t.changeDetectorRef.markForCheck()})},a):null});var i=Math.round(Math.abs(r/60)),u=Math.round(Math.abs(i/60)),s=Math.round(Math.abs(u/24)),h=Math.round(Math.abs(s/30.416)),c=Math.round(Math.abs(s/365));return r<=45?"a few seconds ago":r<=90?"a minute ago":i<=45?i+" minutes ago":i<=90?"an hour ago":u<=22?u+" hours ago":u<=36?"a day ago":s<=25?s+" days ago":s<=45?"a month ago":s<=345?h+" months ago":s<=545?"a year ago":c+" years ago"},e.prototype.ngOnDestroy=function(){this.removeTimer()},e.prototype.removeTimer=function(){this.timer&&(window.clearTimeout(this.timer),this.timer=null)},e.prototype.getSecondsUntilUpdate=function(e){return e<60?2:e<3600?30:e<86400?300:3600},e}();n.decorators=[{type:t.Pipe,args:[{name:"timeAgo",pure:!1}]}],n.ctorParameters=function(){return[{type:t.ChangeDetectorRef},{type:t.NgZone}]},e.TimeAgoPipe=n,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define(["exports","@angular/core"],t):t(e["time-ago-pipe"]={},e.ng.core)}(this,function(e,t){"use strict";var n=function(){function e(e,t){this.changeDetectorRef=e,this.ngZone=t}return e.prototype.transform=function(e){var t=this;this.removeTimer();var n=new Date(e),o=new Date,r=Math.round(Math.abs((o.getTime()-n.getTime())/1e3)),a=Number.isNaN(r)?1e3:1e3*this.getSecondsUntilUpdate(r);this.timer=this.ngZone.runOutsideAngular(function(){return"undefined"!=typeof window?window.setTimeout(function(){t.ngZone.run(function(){return t.changeDetectorRef.markForCheck()})},a):null});var i=Math.round(Math.abs(r/60)),u=Math.round(Math.abs(i/60)),s=Math.round(Math.abs(u/24)),h=Math.round(Math.abs(s/30.416)),c=Math.round(Math.abs(s/365));return Number.isNaN(r)?"":r<=45?"a few seconds ago":r<=90?"a minute ago":i<=45?i+" minutes ago":i<=90?"an hour ago":u<=22?u+" hours ago":u<=36?"a day ago":s<=25?s+" days ago":s<=45?"a month ago":s<=345?h+" months ago":s<=545?"a year ago":c+" years ago"},e.prototype.ngOnDestroy=function(){this.removeTimer()},e.prototype.removeTimer=function(){this.timer&&(window.clearTimeout(this.timer),this.timer=null)},e.prototype.getSecondsUntilUpdate=function(e){return e<60?2:e<3600?30:e<86400?300:3600},e}();n.decorators=[{type:t.Pipe,args:[{name:"timeAgo",pure:!1}]}],n.ctorParameters=function(){return[{type:t.ChangeDetectorRef},{type:t.NgZone}]},e.TimeAgoPipe=n,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=time-ago-pipe.umd.min.js.map |
@@ -25,3 +25,3 @@ import { Pipe, NgZone, ChangeDetectorRef } from '@angular/core'; | ||
let /** @type {?} */ seconds = Math.round(Math.abs((now.getTime() - d.getTime()) / 1000)); | ||
let /** @type {?} */ timeToUpdate = this.getSecondsUntilUpdate(seconds) * 1000; | ||
let /** @type {?} */ timeToUpdate = (Number.isNaN(seconds)) ? 1000 : this.getSecondsUntilUpdate(seconds) * 1000; | ||
this.timer = this.ngZone.runOutsideAngular(() => { | ||
@@ -40,3 +40,6 @@ if (typeof window !== 'undefined') { | ||
let /** @type {?} */ years = Math.round(Math.abs(days / 365)); | ||
if (seconds <= 45) { | ||
if (Number.isNaN(seconds)) { | ||
return ''; | ||
} | ||
else if (seconds <= 45) { | ||
return 'a few seconds ago'; | ||
@@ -100,3 +103,3 @@ } | ||
if (seconds < min) { | ||
// less than 1 min, update ever 2 secs | ||
// less than 1 min, update every 2 secs | ||
return 2; | ||
@@ -103,0 +106,0 @@ } |
@@ -25,3 +25,3 @@ import { Pipe, NgZone, ChangeDetectorRef } from '@angular/core'; | ||
var /** @type {?} */ seconds = Math.round(Math.abs((now.getTime() - d.getTime()) / 1000)); | ||
var /** @type {?} */ timeToUpdate = this.getSecondsUntilUpdate(seconds) * 1000; | ||
var /** @type {?} */ timeToUpdate = (Number.isNaN(seconds)) ? 1000 : this.getSecondsUntilUpdate(seconds) * 1000; | ||
this.timer = this.ngZone.runOutsideAngular(function () { | ||
@@ -40,3 +40,6 @@ if (typeof window !== 'undefined') { | ||
var /** @type {?} */ years = Math.round(Math.abs(days / 365)); | ||
if (seconds <= 45) { | ||
if (Number.isNaN(seconds)) { | ||
return ''; | ||
} | ||
else if (seconds <= 45) { | ||
return 'a few seconds ago'; | ||
@@ -100,3 +103,3 @@ } | ||
if (seconds < min) { | ||
// less than 1 min, update ever 2 secs | ||
// less than 1 min, update every 2 secs | ||
return 2; | ||
@@ -103,0 +106,0 @@ } |
{ | ||
"name": "time-ago-pipe", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "A really simple, lightweight Angular pipe for converting a date string into a time ago", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -43,2 +43,4 @@ # time-ago-pipe | ||
``` | ||
where "your_date" is a local date string, which could be parsed by the standard Js Date() | ||
where "your_date" is a local date string, which could be parsed by the standard Js Date() | ||
If this value is null or not parsable as a date, then the pipe will display nothing |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
41852
434
45