summaryrefslogtreecommitdiffstats
path: root/time/time_test.go
blob: d55783eab8fe73e2ffe02703a95882f9ef973889 (plain) (blame)
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
// Copyright © 2022 siddharth ravikumar <s@ricketyspace.net>
// SPDX-License-Identifier: ISC

package time

import "testing"

func TestDurationToSeconds(t *testing.T) {
	secs, err := durationToSeconds("PT3H4M60S")
	if err != nil {
		t.Errorf("failed: %v", err)
		return
	}
	if secs != 11100 {
		t.Errorf("duration in seconds incorrect: %v", secs)
		return
	}

	secs, err = durationToSeconds("PT4M60S")
	if err != nil {
		t.Errorf("failed: %v", err)
		return
	}
	if secs != 300 {
		t.Errorf("duration in seconds incorrect: %v", secs)
		return
	}

	secs, err = durationToSeconds("PT12H")
	if err != nil {
		t.Errorf("failed: %v", err)
		return
	}
	if secs != 43200 {
		t.Errorf("duration in seconds incorrect: %v", secs)
		return
	}

	secs, err = durationToSeconds("PT1H")
	if err != nil {
		t.Errorf("failed: %v", err)
		return
	}
	if secs != 3600 {
		t.Errorf("duration in seconds incorrect: %v", secs)
		return
	}

	secs, err = durationToSeconds("PT2H")
	if err != nil {
		t.Errorf("failed: %v", err)
		return
	}
	if secs != 7200 {
		t.Errorf("duration in seconds incorrect: %v", secs)
		return
	}

	secs, err = durationToSeconds("PT45M")
	if err != nil {
		t.Errorf("failed: %v", err)
		return
	}
	if secs != 2700 {
		t.Errorf("duration in seconds incorrect: %v", secs)
		return
	}
}