Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit fc17376

Browse files
committed
Add util.go
1 parent 94a97da commit fc17376

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

util.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package datautils
2+
3+
import "time"
4+
5+
// CountTrue count the number of true values in a slice.
6+
func CountTrue(s []bool) int {
7+
n := 0
8+
for _, b := range s {
9+
if b {
10+
n++
11+
}
12+
}
13+
return n
14+
}
15+
16+
// ParseRFCDate parses a date string in RFC3339 format.
17+
// On failure, the current time will be returned.
18+
func ParseRFCDate(timeString string) time.Time {
19+
date, err := time.Parse(time.RFC3339, timeString)
20+
if err != nil {
21+
return time.Now()
22+
}
23+
return date
24+
}

0 commit comments

Comments
 (0)