Skip to content

Commit

Permalink
fix: avoid duration format error on other page
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed Jun 29, 2020
1 parent 672b550 commit a1c4f75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/app/pages/pages.component.ts
@@ -1,7 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { NbMenuItem, NbSidebarService } from '@nebular/theme';
import { HumanizeDuration } from 'humanize-duration-ts';
import { ResponsiveSizeInfoRx } from 'ngx-responsive';
import { ForamtDuration } from '../utils/format-duration';
import { langService } from '../utils/format-duration';
import { ConnectionService } from './connection.service';
import { CurrentUserService } from './current-user.service';
import { MENU_ITEMS } from './pages-menu';
Expand Down Expand Up @@ -110,10 +111,14 @@ export class PagesComponent implements OnInit {
this.menu[0].title = this.currUser + ' ∞';
return;
}
this.menu[0].title = `${this.currUser} ${ForamtDuration.humanize(x[0]['response-time'], {
const ForamtDuration = new HumanizeDuration(langService);
ForamtDuration.setOptions({
language: 'shortEn',
round: true,
units: ['m', 's', 'ms'],
largest: 2,
})}`;
});
this.menu[0].title = `${this.currUser} ${ForamtDuration.humanize(x[0]['response-time'])}`;
});
}
}
3 changes: 2 additions & 1 deletion src/app/utils/format-duration.ts
@@ -1,6 +1,6 @@
import { HumanizeDuration, HumanizeDurationLanguage } from 'humanize-duration-ts';

const langService = new HumanizeDurationLanguage();
export const langService = new HumanizeDurationLanguage();
langService.addLanguage('shortEn', {
y: () => 'y',
mo: () => 'mo',
Expand All @@ -17,4 +17,5 @@ ForamtDuration.setOptions({
language: 'shortEn',
round: true,
units: ['y', 'mo', 'd', 'h', 'm', 's'],
largest: 6,
});

0 comments on commit a1c4f75

Please sign in to comment.