This commit is contained in:
Nicolas Constant 2018-11-01 22:59:44 -04:00
parent 7cb5b3f226
commit 24be608434
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 0 additions and 58 deletions

View File

@ -40,7 +40,6 @@ import { ThreadComponent } from './components/stream/thread/thread.component';
import { HashtagComponent } from './components/stream/hashtag/hashtag.component';
import { StreamOverlayComponent } from './components/stream/stream-overlay/stream-overlay.component';
import { DatabindedTextComponent } from './components/stream/status/databinded-text/databinded-text.component';
import { MastodonTimePipe } from './pipes/mastodon-time.pipe';
import { TimeAgoPipe } from './pipes/time-ago.pipe';
const routes: Routes = [
@ -75,7 +74,6 @@ const routes: Routes = [
HashtagComponent,
StreamOverlayComponent,
DatabindedTextComponent,
MastodonTimePipe,
TimeAgoPipe
],
imports: [

View File

@ -1,8 +0,0 @@
import { MastodonTimePipe } from './mastodon-time.pipe';
xdescribe('MastodonTimePipe', () => {
// it('create an instance', () => {
// const pipe = new MastodonTimePipe();
// expect(pipe).toBeTruthy();
// });
});

View File

@ -1,48 +0,0 @@
import { Pipe, PipeTransform, Inject, LOCALE_ID } from '@angular/core';
import { formatDate } from '@angular/common';
@Pipe({
name: 'mastodontime',
pure: false
})
export class MastodonTimePipe implements PipeTransform {
constructor(@Inject(LOCALE_ID) private locale: string) { }
// private cachedDict: { [id:string] : string } = {};
// private cached: string;
// private resultCached: string;
transform(value: string): string {
// if (value == this.cached && this.resultCached) {
// return this.resultCached;
// }
// if(this.cachedDict[value]) {
// return this.cachedDict[value];
// }
const date = (new Date(value)).getTime();
const now = Date.now();
const timeDelta = (now - date) / (1000);
if (timeDelta < 60) {
return `${timeDelta | 0}s`;
} else if (timeDelta < 60 * 60) {
return `${timeDelta / 60 | 0}m`;
} else if (timeDelta < 60 * 60 * 24) {
return `${timeDelta / (60 * 60) | 0}h`;
} else if (timeDelta < 60 * 60 * 24 * 31) {
return `${timeDelta / (60 * 60 * 24) | 0}d`;
}
return formatDate(date, 'MM/dd', this.locale);
// this.cachedDict[value] = formatDate(date, 'MM/dd', this.locale);
// // this.cached = value;
// // this.resultCached = formatDate(date, 'MM/dd', this.locale);
// return this.cachedDict[value];
}
}