Skip to content

Commit

Permalink
feat(amTimeAgo): align with angular-2.0.0-alpha.37
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed Sep 19, 2015
1 parent 05fcbdf commit 81b6aa1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
node_modules
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.0.2 - 2015-09-18
- Align with angular-2.0.0-alpha.37

## 0.0.1 - 2015-08-25

- Initial release
2 changes: 1 addition & 1 deletion TimeAgoPipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('TimeAgo', () => {
it('should support moment instances', () => {
expect(pipe.supports(moment())).toBe(true);
});

it('should not support string', () => {
expect(pipe.supports('foobar')).toBe(false);
});
Expand Down
28 changes: 14 additions & 14 deletions TimeAgoPipe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* angular2-moment / v0.0.1 / (c) 2015 Uri Shaked / MIT Licence */

/// <reference path="node_modules/angular2/angular2.d.ts" />
/// <reference path="node_modules/angular2/bundles/typings/angular2/angular2.d.ts" />

import {Pipe, ChangeDetectorRef} from 'angular2/angular2';
import * as moment_ from 'moment';
Expand All @@ -10,35 +10,35 @@ const moment = moment_['default'] || moment_;

@Pipe({name: 'amTimeAgo'})
export class TimeAgoPipe implements Pipe {
private _currentTimer: number;
constructor(private _cdRef: ChangeDetectorRef) {
private _currentTimer:number;

constructor(private _cdRef:ChangeDetectorRef) {
}
supports(value:any): boolean {

supports(value:any):boolean {
return value instanceof Date || moment.isMoment(value);
}
transform(value: Date | moment.Moment, args?: List<any>): any {

transform(value:Date | moment.Moment, args?:List<any>):any {
let momentInstance = moment(value);
this._removeTimer();
let timeToUpdate = this._getSecondsUntilUpdate(momentInstance) * 1000;
this._currentTimer = setTimeout(() => this._cdRef.requestCheck(), timeToUpdate);
this._currentTimer = setTimeout(() => this._cdRef.markForCheck(), timeToUpdate);
return moment(value).from(moment());
}
onDestroy(): void {

onDestroy():void {
this._removeTimer();
}

_removeTimer() {
if (this._currentTimer) {
clearTimeout(this._currentTimer);
this._currentTimer = null;
}
}
_getSecondsUntilUpdate(momentInstance: moment.Moment) {

_getSecondsUntilUpdate(momentInstance:moment.Moment) {
var howOld = Math.abs(moment().diff(momentInstance, 'minute'));
if (howOld < 1) {
return 1;
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
},
"homepage": "https://github.com/urish/angular2-moment#readme",
"dependencies": {
"angular2": "^2.0.0-alpha.35",
"angular2": "^2.0.0-alpha.37",
"moment": "^2.10.6"
},
"devDependencies": {
"es6-shim": "^0.33.1",
"es6-shim": "0.33.3",
"es6-symbol": "^2.0.1",
"jasmine-core": "^2.3.4",
"karma": "^0.13.9",
Expand All @@ -35,9 +35,9 @@
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.7.0",
"phantomjs": "^1.9.18",
"reflect-metadata": "^0.1.0",
"typescript": "^1.5.3",
"typescript-simple-loader": "^0.3.4",
"reflect-metadata": "0.1.1",
"typescript": "1.6.2",
"typescript-simple-loader": "0.3.7",
"webpack": "^1.11.0"
}
}

0 comments on commit 81b6aa1

Please sign in to comment.