-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage.html
More file actions
359 lines (311 loc) · 11.9 KB
/
coverage.html
File metadata and controls
359 lines (311 loc) · 11.9 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>bublyk: Go Coverage Report</title>
<style>
body {
background: black;
color: rgb(80, 80, 80);
}
body, pre, #legend span {
font-family: Menlo, monospace;
font-weight: bold;
}
#topbar {
background: black;
position: fixed;
top: 0; left: 0; right: 0;
height: 42px;
border-bottom: 1px solid rgb(80, 80, 80);
}
#content {
margin-top: 50px;
}
#nav, #legend {
float: left;
margin-left: 10px;
}
#legend {
margin-top: 12px;
}
#nav {
margin-top: 10px;
}
#legend span {
margin: 0 5px;
}
.cov0 { color: rgb(192, 0, 0) }
.cov1 { color: rgb(128, 128, 128) }
.cov2 { color: rgb(116, 140, 131) }
.cov3 { color: rgb(104, 152, 134) }
.cov4 { color: rgb(92, 164, 137) }
.cov5 { color: rgb(80, 176, 140) }
.cov6 { color: rgb(68, 188, 143) }
.cov7 { color: rgb(56, 200, 146) }
.cov8 { color: rgb(44, 212, 149) }
.cov9 { color: rgb(32, 224, 152) }
.cov10 { color: rgb(20, 236, 155) }
</style>
</head>
<body>
<div id="topbar">
<div id="nav">
<select id="files">
<option value="file0">github.com/kaatinga/bublyk/models.go (97.3%)</option>
</select>
</div>
<div id="legend">
<span>not tracked</span>
<span class="cov0">not covered</span>
<span class="cov8">covered</span>
</div>
</div>
<div id="content">
<pre class="file" id="file0" style="display: none">package bublyk
import (
"errors"
"time"
faststrconv "github.com/kaatinga/strconv"
)
const (
yearMask = 0b1111111000000000
monthMask = 0b0000000111100000
dayMask = 0b0000000000011111
maximumDate Date = 0b1111111110011111 // 2127-12-31
minimumDate Date = 0b0000000000100001 // 2000-01-01
noDate Date = 0
postgreSQLFormat = "2006-01-02"
)
func Now() Date <span class="cov8" title="1">{
now := time.Now().UTC()
return NewDateFromTime(&now)
}</span>
func CurrentMonth() Date <span class="cov8" title="1">{
now := Now()
return NewDate(now.Year(), now.Month(), 1)
}</span>
// Date represents a calendar date starting 2000 year and finishing the year 2127.
type Date uint16
func (thisDate Date) Year() uint16 <span class="cov8" title="1">{
return uint16(thisDate>>9) + 2000
}</span>
func (thisDate Date) Month() byte <span class="cov8" title="1">{
return byte((thisDate & monthMask) >> 5)
}</span>
func (thisDate Date) Day() byte <span class="cov8" title="1">{
return byte(thisDate & dayMask)
}</span>
func (thisDate Date) IsSet() bool <span class="cov8" title="1">{
return thisDate != 0
}</span>
func (thisDate Date) IsFuture() bool <span class="cov8" title="1">{
return thisDate > Now()
}</span>
// MonthAfter checks whether the date at least one month after the target date or not.
func (thisDate Date) MonthAfter(date Date) bool <span class="cov8" title="1">{
if thisDate.Year() == date.Year() </span><span class="cov8" title="1">{
return thisDate.Month() > date.Month()
}</span>
<span class="cov8" title="1">return thisDate.Year() > date.Year()</span>
}
// MonthBefore checks whether the date at least one month before the target date or not.
func (thisDate Date) MonthBefore(date Date) bool <span class="cov8" title="1">{
if thisDate.Year() == date.Year() </span><span class="cov8" title="1">{
return thisDate.Month() < date.Month()
}</span>
<span class="cov8" title="1">return thisDate.Year() < date.Year()</span>
}
// String returns date as string in the default PostgreSQL date format, YYYY-MM-DD.
func (thisDate Date) String() string <span class="cov8" title="1">{
if !thisDate.IsSet() </span><span class="cov8" title="1">{
return "null"
}</span>
<span class="cov8" title="1">return format[string](thisDate)</span>
}
// format prepares a binary or text of the date in PostgreSQL format.
func format[V []byte | string](thisDate Date) V <span class="cov8" title="1">{
month, day, year := getDateAsBinaries(thisDate)
var output = make([]byte, 10)
output[0] = year[0]
output[1] = year[1]
output[2] = year[2]
output[3] = year[3]
output[4] = '-'
switch len(month) </span>{
case 2:<span class="cov8" title="1">
output[5] = month[0]
output[6] = month[1]</span>
default:<span class="cov8" title="1">
output[5] = 48
output[6] = month[0]</span>
}
<span class="cov8" title="1">output[7] = '-'
switch len(day) </span>{
case 2:<span class="cov8" title="1">
output[8] = day[0]
output[9] = day[1]</span>
default:<span class="cov8" title="1">
output[8] = 48
output[9] = day[0]</span>
}
<span class="cov8" title="1">return V(output)</span>
}
func getDateAsBinaries(thisDate Date) ([]byte, []byte, []byte) <span class="cov8" title="1">{
var month = faststrconv.Byte2Bytes(thisDate.Month())
var day = faststrconv.Byte2Bytes(thisDate.Day())
var year = faststrconv.Uint162Bytes(thisDate.Year())
return month, day, year
}</span>
// DMYWithDots returns date as string in the DD.MM.YYYY format.
func (thisDate Date) DMYWithDots() string <span class="cov8" title="1">{
month, day, year := getDateAsBinaries(thisDate)
var output = make([]byte, 10)
switch len(day) </span>{
case 2:<span class="cov8" title="1">
output[0] = day[0]
output[1] = day[1]</span>
default:<span class="cov8" title="1">
output[0] = 48
output[1] = day[0]</span>
}
<span class="cov8" title="1">output[2] = '.'
switch len(month) </span>{
case 2:<span class="cov8" title="1">
output[3] = month[0]
output[4] = month[1]</span>
default:<span class="cov8" title="1">
output[3] = 48
output[4] = month[0]</span>
}
<span class="cov8" title="1">output[5] = '.'
output[6] = year[0]
output[7] = year[1]
output[8] = year[2]
output[9] = year[3]
return string(output)</span>
}
func (thisDate Date) Format(layout string) string <span class="cov8" title="1">{
switch layout </span>{
case postgreSQLFormat:<span class="cov8" title="1">
return thisDate.String()</span>
default:<span class="cov8" title="1">
return makeTime(thisDate.Year(), thisDate.Month(), thisDate.Day()).Format(layout)</span>
}
}
func Parse(formattedDate string) (Date, error) <span class="cov8" title="1">{
if len([]rune(formattedDate)) != len([]rune(postgreSQLFormat)) </span><span class="cov8" title="1">{
return 0, errors.New("incorrect date format")
}</span>
<span class="cov8" title="1">year, err := faststrconv.GetUint16(formattedDate[0:4])
if err != nil </span><span class="cov0" title="0">{
return 0, err
}</span>
<span class="cov8" title="1">var month byte
month, err = faststrconv.GetByte(formattedDate[5:7])
if err != nil </span><span class="cov0" title="0">{
return 0, err
}</span>
<span class="cov8" title="1">var day byte
day, err = faststrconv.GetByte(formattedDate[8:10])
if err != nil </span><span class="cov0" title="0">{
return 0, err
}</span>
<span class="cov8" title="1">return NewDate(year, month, day), nil</span>
}
func (thisDate Date) Time() *time.Time <span class="cov8" title="1">{
return makeTime(thisDate.Year(), thisDate.Month(), thisDate.Day())
}</span>
func (thisDate Date) NextDay() Date <span class="cov8" title="1">{
if thisDate.Day() > 27 </span><span class="cov8" title="1">{
timeDate := makeTime(thisDate.Year(), thisDate.Month(), thisDate.Day()).AddDate(0, 0, 1)
return NewDateFromTime(&timeDate)
}</span>
<span class="cov8" title="1">return thisDate&^dayMask | (thisDate&dayMask + 1)</span>
}
func (thisDate Date) PreviousDay() Date <span class="cov8" title="1">{
if thisDate.Day() == 1 </span><span class="cov8" title="1">{
timeDate := makeTime(thisDate.Year(), thisDate.Month(), thisDate.Day()).AddDate(0, 0, -1)
return NewDateFromTime(&timeDate)
}</span>
<span class="cov8" title="1">return thisDate&^dayMask | (thisDate&dayMask - 1)</span>
}
func (thisDate Date) NextWeek() Date <span class="cov8" title="1">{
if thisDate.Day() > 21 </span><span class="cov8" title="1">{
timeDate := makeTime(thisDate.Year(), thisDate.Month(), thisDate.Day()).AddDate(0, 0, 7)
return NewDateFromTime(&timeDate)
}</span>
<span class="cov8" title="1">return thisDate&^dayMask | (thisDate&dayMask + 7)</span>
}
func (thisDate Date) PreviousWeek() Date <span class="cov8" title="1">{
if thisDate.Day() < 8 </span><span class="cov8" title="1">{
timeDate := makeTime(thisDate.Year(), thisDate.Month(), thisDate.Day()).AddDate(0, 0, -7)
return NewDateFromTime(&timeDate)
}</span>
<span class="cov8" title="1">return thisDate&^dayMask | (thisDate&dayMask - 7)</span>
}
func NewDate(year uint16, month, day byte) Date <span class="cov8" title="1">{
if year < 2000 </span><span class="cov8" title="1">{
return minimumDate
}</span>
<span class="cov8" title="1">if year > 2127 </span><span class="cov8" title="1">{
return maximumDate
}</span>
<span class="cov8" title="1">if day > 28 || month > 12 || day == 0 || month == 0 </span><span class="cov8" title="1">{
yearInt, monthMonth, dayInt := makeTime(year, month, day).Date()
year, month, day = uint16(yearInt), byte(monthMonth), byte(dayInt)
}</span>
<span class="cov8" title="1">return composeDate(year, month, day)</span>
}
func makeTime(year uint16, month, day byte) *time.Time <span class="cov8" title="1">{
newTime := time.Date(int(year), time.Month(month), int(day), 0, 0, 0, 0, time.UTC)
return &newTime
}</span>
// NewDateFromTime create new date using time.Time model.
func NewDateFromTime(t *time.Time) Date <span class="cov8" title="1">{
if t == nil </span><span class="cov8" title="1">{
return noDate
}</span>
<span class="cov8" title="1">year := t.Year()
if year < 2000 </span><span class="cov8" title="1">{
return minimumDate
}</span>
<span class="cov8" title="1">if year > 2127 </span><span class="cov8" title="1">{
return maximumDate
}</span>
<span class="cov8" title="1">return composeDate(uint16(year), byte(t.Month()), byte(t.Day()))</span>
}
func composeDate(year uint16, month, day byte) Date <span class="cov8" title="1">{
return (Date(year-2000) << 9) + (Date(month) << 5) + Date(day)
}</span>
</pre>
</div>
</body>
<script>
(function() {
var files = document.getElementById('files');
var visible;
files.addEventListener('change', onChange, false);
function select(part) {
if (visible)
visible.style.display = 'none';
visible = document.getElementById(part);
if (!visible)
return;
files.value = part;
visible.style.display = 'block';
location.hash = part;
}
function onChange() {
select(files.value);
window.scrollTo(0, 0);
}
if (location.hash != "") {
select(location.hash.substr(1));
}
if (!visible) {
select("file0");
}
})();
</script>
</html>