-
Notifications
You must be signed in to change notification settings - Fork 5
/
timeWords.js
182 lines (163 loc) · 4.15 KB
/
timeWords.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
const str = 12
console.log(str[0])
const time = (h,m) => {
let strM = m.toString()
let arrM = []
for (let i = 0; i<strM.length; i++){
arrM[i]=strM[i]
}
console.log(m)
console.log (h)
const minute = (m) => {
switch (m) {
case 0:
break
case 1:
return 'one'
case 2:
return 'two'
case 3:
return 'three'
case 4:
return 'four'
case 5:
return 'five'
case 6:
return 'six'
case 7:
return 'seven'
case 8:
return 'eight'
case 9:
return 'nine'
case 10:
return 'ten'
case 11:
return 'eleven'
case 12:
return 'twelve'
case 13:
return 'thirteen'
case 9:
return 'one'
case 58:
return 'two'
case 57:
return 'three'
case 56:
return 'four'
case 55:
return 'five'
case 54:
return 'six'
case 53:
return 'seven'
case 52:
return 'eight'
case 51:
return 'nine'
case 50:
return 'ten'
case 49:
return 'eleven'
case 48:
return 'twelve'
case 47:
return 'thirteen'
case 30:
return 'half'
case 15:
return 'quarter'
case 45:
return 'quarter'
default:
const minutes2 = (arrM) => {
switch (arrM[1]||arrM) {
case '0':
break
case '1':
return 'one'
case '2':
return 'two'
case '3':
return 'three'
case '4':
return 'four'
case '5':
return 'five'
case '6':
return 'six'
case '7':
return 'seven'
case '8':
return 'eight'
case '9':
return 'nine'
}
}
const minutes1 = (arrM) => {
switch (arrM[0]) {
case '1':
return minutes2(arrM) + 'teen'
case '2':
return 'twenty ' + minutes2(arrM)
case '3':
return 'twenty ' + minutes2(Math.abs(parseInt(arrM[1]) - 10).toString())
case '4':
return minutes2(Math.abs(parseInt(arrM[1]) - 10).toString()) + 'teen'
}
}
return minutes1(arrM);
}}
const hour = (h) => {
switch (h) {
case 1:
return 'one'
case 2:
return 'two'
case 3:
return 'three'
case 4:
return 'four'
case 5:
return 'five'
case 6:
return 'six'
case 7:
return 'seven'
case 8:
return 'eight'
case 9:
return 'nine'
case 10:
return 'ten'
case 11:
return 'eleven'
case 12:
return 'twelve'
default:
break
}
}
console.log(m)
if (m === 30 || m === 15) {
return `${minute(m)} past ${hour(h)}`
}
if (m === 45) {
return `${minute(m)} to ${hour((h === 12) ? 1 : h + 1)}`
}
if (m === 0) {
return `${hour(h)} o' clock`
}
if (m === 1) {
return `${minute(m)} minute past ${hour(h)}`
}
if (m < 30 && m > 0) {
return `${minute(m)} minutes past ${hour(h)}`
}
if (m > 30 && m < 60) {
return `${minute(m)} minutes to ${hour((h === 12) ? 1 : h + 1)}`
}
err;
}
console.log(time(5,45))