Skip to content
Snippets Groups Projects
Commit 0f988be1 authored by Klaus-Dieter Quibeldey-Cirkel's avatar Klaus-Dieter Quibeldey-Cirkel
Browse files

Merge branch...

Merge branch '363-time-specifications-do-not-correspond-with-the-language-selection-german' into 'master'

de/en time format questionwall

Closes #363

See merge request arsnova/frag.jetzt!331
parents 8cf897f7 3cf4bbef
No related merge requests found
......@@ -2,9 +2,33 @@ import { Comment } from '../../../models/comment';
export class QuestionWallComment {
public static readonly TIME_FORMAT_DE: string[][] =
[
['vor % Jahr', 'vor % Jahren'],
['vor % Monat', 'vor % Monaten'],
['vor % Tag', 'vor % Tagen'],
['vor % Stunde', 'vor % Stunden'],
['vor % Minute', 'vor % Minuten'],
['vor % Sekunde', 'vor % Sekunden']
];
public static readonly TIME_FORMAT_EN: string[][] = [
['% year ago', '% years ago'],
['% month ago', '% months ago'],
['% day ago', '% days ago'],
['% hour ago', '% hours ago'],
['% minute ago', '% minutes ago'],
['% second ago', '% seconds ago'],
];
public static currentTimeFormat: string[][] = QuestionWallComment.TIME_FORMAT_EN;
public date: Date;
public timeAgo: string;
public static updateTimeFormat(lang: string) {
this.currentTimeFormat = this['TIME_FORMAT_' + lang.toUpperCase()];
}
constructor(
public comment: Comment,
public old: boolean
......@@ -23,21 +47,21 @@ export class QuestionWallComment {
const days = Math.floor(hours / 24);
const months = Math.floor(days / 30);
const years = Math.floor(months / 12);
if (this.setTimeAgo(years, 'year')) {return; }
if (this.setTimeAgo(months, 'month')) {return; }
if (this.setTimeAgo(days, 'day')) {return; }
if (this.setTimeAgo(hours, 'hour')) {return; }
if (this.setTimeAgo(minutes, 'minute')) {return; }
if (this.setTimeAgo(seconds, 'second')) {return; }
this.timeAgo = '1 second ago';
if (this.setTime(years, QuestionWallComment.currentTimeFormat[0])) {return; }
if (this.setTime(months, QuestionWallComment.currentTimeFormat[1])) {return; }
if (this.setTime(days, QuestionWallComment.currentTimeFormat[2])) {return; }
if (this.setTime(hours, QuestionWallComment.currentTimeFormat[3])) {return; }
if (this.setTime(minutes, QuestionWallComment.currentTimeFormat[4])) {return; }
if (this.setTime(seconds, QuestionWallComment.currentTimeFormat[5])) {return; }
this.timeAgo = QuestionWallComment.currentTimeFormat[5][0].replace('%', '1');
}
private setTimeAgo(time: number, name: string): boolean {
private setTime(time: number, format: string[]): boolean {
if (time > 0) {
if (time === 1) {
this.timeAgo = time + ' ' + name + ' ago';
this.timeAgo = format[0].replace('%', time + '');
} else {
this.timeAgo = time + ' ' + name + 's ago';
this.timeAgo = format[1].replace('%', time + '');
}
return true;
} else {
......
......@@ -54,11 +54,15 @@ export class QuestionWallComponent implements OnInit, AfterViewInit, OnDestroy {
this.timeUpdateInterval = setInterval(() => {
this.comments.forEach(e => e.updateTimeAgo());
}, 15000);
this.langService.langEmitter.subscribe(lang => this.translateService.use(lang));
this.langService.langEmitter.subscribe(lang => {
this.translateService.use(lang);
QuestionWallComment.updateTimeFormat(lang);
});
}
ngOnInit(): void {
// StyleDebug.border('c');
QuestionWallComment.updateTimeFormat(localStorage.getItem('currentLang'));
this.translateService.use(localStorage.getItem('currentLang'));
this.commentService.getAckComments(this.roomId).subscribe(e => {
e.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment