-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguageTimeObjGerman.js
More file actions
104 lines (97 loc) · 2.89 KB
/
languageTimeObjGerman.js
File metadata and controls
104 lines (97 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
class LanguageTimeObjGerman extends LanguageTimeObj {
constructor () {
super();
this.matrix = [
// 01234567890
"ES IST FÜNF",
"ZEHNZWANZIG",
"DREIVIERTEL",
"VOR NACH",
"HALB ELFÜNF",
"EINS ZWEI",
"DREI VIER",
"SECHS ACHT",
"SIEBENZWÖLF",
"ZEHNEUN UHR",
];
this.fillMatrixGaps();
this.itIs = [new word(0, 0, 2), new word(0, 3, 3)];
this.before = [new word(3, 0, 3)];
this.after = [new word(3, 7, 4)];
this.half = [new word(4, 0, 4)];
this.oclock = [new word(9, 8, 3)];
this.minuteWords = [
[new word(0, 7, 4)], // Fünf (nach)
[new word(1, 0, 4)], // Zehn
[new word(2, 4, 7)], // Viertel
[new word(1, 4, 7)], // Zwanzig
[new word(0, 7, 4)], // Fünf (vor halb)
[new word(0, 0, 0)], // Halb (half is reduntant defined for simplicity of code)
[new word(0, 7, 4)], // Fünf (nach halb)
[new word(1, 4, 7)], // Zwanzig (vor)
[new word(2, 4, 7)], // Viertel
[new word(1, 0, 4)], // Zehn
[new word(0, 7, 4)], // Fünf
];
this.hourWords = [
[new word(8, 6, 5)], // 12 at top (index=0)
[new word(5, 0, 4)], // 1
[new word(5, 7, 4)], // 2
[new word(6, 0, 4)], // 3
[new word(6, 7, 4)], // 4
[new word(4, 7, 4)], // 5
[new word(7, 0, 5)], // 6
[new word(8, 0, 6)], // 7
[new word(7, 7, 4)], // 8
[new word(9, 3, 4)], // 9
[new word(9, 0, 4)], // 10
[new word(4, 5, 3)] // 11
];
}
getWordsForTime(h, m) {
// The grammar to create the corrent wording for a given time
// returns an array of words (row, col, len) to be displayed
let wordArr = [];
wordArr = wordArr.concat(this.itIs);
if (m >= 5) {
var mIndex = Math.floor(m / 5) - 1;
wordArr = wordArr.concat(this.minuteWords[mIndex]);
if (m < 25)
wordArr = wordArr.concat(this.after);
else if (m < 30)
wordArr = wordArr.concat(this.before);
else if (m >= 35 && m < 40)
wordArr = wordArr.concat(this.after);
else if (m >= 40)
wordArr = wordArr.concat(this.before);
if (m >= 25 && m < 40) wordArr = wordArr.concat(this.half);
}
var hIndex = h;
if (m < 25)
hIndex = h % 12;
else
hIndex = (h + 1) % 12;
wordArr = wordArr.concat(this.hourWords[hIndex]);
if (m < 5)
wordArr = wordArr.concat(this.oclock);
return wordArr;
}
fillMatrixGaps(fillword) {
if (fillword === undefined) fillword = "";
let gapCount = 0;
for (let i=0; i<this.matrix.length; i++) {
let word = "";
for (let j=0; j<this.matrix[i].length; j++) {
let c = this.matrix[i].substring(j, j+1);
if (c == " ") {
c = (gapCount < fillword.length
? fillword.substr(gapCount, gapCount+1)
: String.fromCharCode(65+Math.floor(Math.random() * 26)));
gapCount++;
}
word = word + c;
}
this.matrix[i] = word;
}
}
}