creation of a pipe for displaying the time
This commit is contained in:
parent
a22b16c74e
commit
6af023fbbd
|
@ -40,6 +40,7 @@ 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';
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: "", redirectTo: "home", pathMatch: "full" },
|
||||
|
@ -72,7 +73,8 @@ const routes: Routes = [
|
|||
ThreadComponent,
|
||||
HashtagComponent,
|
||||
StreamOverlayComponent,
|
||||
DatabindedTextComponent
|
||||
DatabindedTextComponent,
|
||||
MastodonTimePipe
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
</span>
|
||||
</a>
|
||||
<div class="status__created-at" title="{{ displayedStatus.created_at | date: 'full' }}">{{
|
||||
getCompactRelativeTime(status.created_at) }}</div>
|
||||
status.created_at | mastodontime }}</div>
|
||||
<!-- <div #content class="status__content" innerHTML="{{displayedStatus.content}}"></div> -->
|
||||
|
||||
<app-databinded-text class="status__content" [text]="displayedStatus.content" (accountSelected)="accountSelected($event)" (hashtagSelected)="hashtagSelected($event)" (textSelected)="textSelected()"></app-databinded-text>
|
||||
|
|
|
@ -28,8 +28,7 @@ export class UserProfileComponent implements OnInit {
|
|||
//set currentAccount(account: Account) {
|
||||
set currentAccount(accountName: string) {
|
||||
this.statuses.length = 0;
|
||||
this.isLoading = true;
|
||||
this.statusLoading = true;
|
||||
this.isLoading = true;
|
||||
|
||||
this.loadAccount(accountName)
|
||||
.then((account: Account) => {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
import { MastodonTimePipe } from './mastodon-time.pipe';
|
||||
|
||||
xdescribe('MastodonTimePipe', () => {
|
||||
// it('create an instance', () => {
|
||||
// const pipe = new MastodonTimePipe();
|
||||
// expect(pipe).toBeTruthy();
|
||||
// });
|
||||
});
|
|
@ -0,0 +1,48 @@
|
|||
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];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue