add minutes format pipe
This commit is contained in:
1 parent
bba03c214a
commit
7d10fc2ded
2 files changed
+25
No files matched your search
@@ -0,0 +1,22 @@
|
|||||||
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
||||||
|
@Pipe({
|
||||||
|
name: 'minutesFormat',
|
||||||
|
})
|
||||||
|
export class MinutesFormatPipe implements PipeTransform {
|
||||||
|
transform(value: string | number, target: string = 'hours'): number {
|
||||||
|
const minutes = Number.parseInt(value.toString()) || 0;
|
||||||
|
|
||||||
|
if (minutes == 0) return 0;
|
||||||
|
|
||||||
|
if (target == 'hours') {
|
||||||
|
return Math.trunc(minutes / 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target == 'days') {
|
||||||
|
return Math.trunc(minutes / 60 / 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import { EpisodeSeenModalComponent } from './components/modals/episode-seen-moda
|
|||||||
import { MainCardComponent } from './components/cards/main-card/main-card.component';
|
import { MainCardComponent } from './components/cards/main-card/main-card.component';
|
||||||
import { DynamicEntryListComponent } from './components/lists/dynamic-entry-list/dynamic-entry-list.component';
|
import { DynamicEntryListComponent } from './components/lists/dynamic-entry-list/dynamic-entry-list.component';
|
||||||
import { NotificationPopupComponent } from './components/notification-popup/notification-popup.component';
|
import { NotificationPopupComponent } from './components/notification-popup/notification-popup.component';
|
||||||
|
import { MinutesFormatPipe } from './pipes/minutes-format/minutes-format.pipe';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -31,6 +32,7 @@ import { NotificationPopupComponent } from './components/notification-popup/noti
|
|||||||
// * pipes
|
// * pipes
|
||||||
DateFormatPipe,
|
DateFormatPipe,
|
||||||
FloatFormatPipe,
|
FloatFormatPipe,
|
||||||
|
MinutesFormatPipe,
|
||||||
|
|
||||||
// ? modals
|
// ? modals
|
||||||
SeenModalComponent,
|
SeenModalComponent,
|
||||||
@@ -46,6 +48,7 @@ import { NotificationPopupComponent } from './components/notification-popup/noti
|
|||||||
// * pipes
|
// * pipes
|
||||||
DateFormatPipe,
|
DateFormatPipe,
|
||||||
FloatFormatPipe,
|
FloatFormatPipe,
|
||||||
|
MinutesFormatPipe,
|
||||||
|
|
||||||
FormsModule,
|
FormsModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
|
|||||||
Reference in new issue
Block a user