Last active
January 29, 2018 18:48
-
-
Save jsixface/7af11cefac0ea71540cf9a841e3c514b to your computer and use it in GitHub Desktop.
if you have duration in format of 3h55m2s in a file, this snippet can calculate the cumulative time duration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"log" | |
"os" | |
"time" | |
) | |
const fileName = "test.txt" | |
func main() { | |
fil, err := os.Open(fileName) | |
if err != nil { | |
log.Fatal(err) | |
} | |
scanner := bufio.NewScanner(fil) | |
var totalTime time.Duration | |
for scanner.Scan() { | |
duration, err := time.ParseDuration(scanner.Text()) | |
if err != nil { | |
log.Fatal(err) | |
} | |
totalTime = totalTime + duration | |
} | |
println(totalTime.String()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19m10s | |
8m43s | |
16m34s | |
13m10s | |
16m48s | |
7m34s | |
9m22s | |
20m18s | |
5m39s | |
16m01s | |
8m42s | |
4m13s | |
18m45s | |
13m56s | |
9m34s | |
9m32s | |
19m52s | |
7m27s | |
9m41s | |
8m12s | |
5m31s | |
12m59s | |
13m41s | |
5m46s | |
5m57s | |
5m24s | |
1m17s | |
8m48s | |
21m45s | |
15m50s | |
7m07s | |
17m01s | |
4m37s | |
10m28s | |
5m55s | |
6m02s | |
4m52s | |
9m31s | |
4m24s | |
3m41s | |
13m56s | |
18m02s | |
5m26s | |
13m43s | |
2m30s | |
4m27s | |
3m57s | |
6m49s | |
3m29s | |
6m09s | |
2m57s | |
6m17s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment