Skip to content

Commit

Permalink
Fix the default language selection if the user language is not suppor…
Browse files Browse the repository at this point in the history
…ted (#12)
  • Loading branch information
FabienM authored May 19, 2019
1 parent dc5e62e commit 5fa45e5
Show file tree
Hide file tree
Showing 3 changed files with 934 additions and 903 deletions.
15 changes: 12 additions & 3 deletions app/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ const midnightTable: {[k: string]: string} = {
'en': 'midnight',
'fr': 'minuit'
};
const supportedLanguages: {[k: string]: boolean} = {
'en': true,
'fr': true
};
const defaultLanguage: string = 'en';

export function getDateInWordsInstance(is12h: boolean, date: Date, locale: string) {
let language = locale.split('-')[0];
if (!supportedLanguages[language]) {
language = defaultLanguage;
}
if (is12h) {
return new DateTimeInWords12h(date, locale);
return new DateTimeInWords12h(date, language);
}
return new DateTimeInWords24h(date, locale);
return new DateTimeInWords24h(date, language);
}

export class DateTimeInWords12h {
Expand All @@ -34,7 +43,7 @@ export class DateTimeInWords12h {
constructor(date: Date, language:string) {
this.date = date;
this.pm = date.getHours() >= 12;
this.language = language.split('-')[0];
this.language = language;
}

protected formatNumber(n: number): string {
Expand Down
Loading

0 comments on commit 5fa45e5

Please sign in to comment.