-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into USH-1704
- Loading branch information
Showing
70 changed files
with
4,223 additions
and
704 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 22 additions & 10 deletions
32
apps/web-mzima-client/src/app/core/pipes/date-ago.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
@Pipe({ | ||
name: 'dateAgo', | ||
}) | ||
export class DateAgoPipe implements PipeTransform { | ||
constructor(private translate: TranslateService) {} | ||
transform(value: any): unknown { | ||
if (!value) { | ||
return 'a long time ago'; | ||
return this.translate.instant('date.aLongTimeAgo'); | ||
} | ||
let time = (Date.now() - Date.parse(value)) / 1000; | ||
if (time < 10) { | ||
return 'just now'; | ||
return this.translate.instant('date.justNow'); | ||
} else if (time < 60) { | ||
return 'a moment ago'; | ||
return this.translate.instant('date.aMomentAgo'); | ||
} | ||
const divider = [60, 60, 24, 30, 12]; | ||
const string = [' second', ' minute', ' hour', ' day', ' month', ' year']; | ||
let i; | ||
for (i = 0; Math.floor(time / divider[i]) > 0; i++) { | ||
time /= divider[i]; | ||
|
||
const dividers = [60, 60, 24, 30, 12]; | ||
const string = ['second', 'minute', 'hour', 'day', 'month', 'year']; | ||
let i = 0; | ||
|
||
// Calculate the appropriate unit | ||
while (i < dividers.length && Math.floor(time / dividers[i]) > 0) { | ||
time /= dividers[i]; | ||
i++; | ||
} | ||
const plural = Math.floor(time) > 1 ? 's' : ''; | ||
return Math.floor(time) + string[i] + plural + ' ago'; | ||
|
||
const roundedTime = Math.floor(time); | ||
const unit = string[i]; | ||
const pluralization = roundedTime > 1 ? 'plural' : 'singular'; | ||
|
||
// Translate the string based on singular/plural | ||
return this.translate.instant(`date.${unit}.${pluralization}`, { time: roundedTime }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.