File: README.md

package info (click to toggle)
golang-github-google-go-intervals 0.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 144 kB
  • sloc: makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,550 bytes parent folder | download
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
# go-intervals

go-intervals is a library for performing set operations on 1-dimensional
intervals, such as time ranges.

Example usage:

```go
var tz = func() *time.Location {
    x, err := time.LoadLocation("PST8PDT")
    if err != nil {
        panic(fmt.Errorf("timezone not available: %v", err))
    }
    return x
}()

type span struct {
    start, end time.Time
}
week1 := &span{
    time.Date(2015, time.June, 1, 0, 0, 0, 0, tz),
    time.Date(2015, time.June, 8, 0, 0, 0, 0, tz),
}
week2 := &span{
    time.Date(2015, time.June, 8, 0, 0, 0, 0, tz),
    time.Date(2015, time.June, 15, 0, 0, 0, 0, tz),
}
week3 := &span{
    time.Date(2015, time.June, 15, 0, 0, 0, 0, tz),
    time.Date(2015, time.June, 22, 0, 0, 0, 0, tz),
}

set := timespanset.Empty()
fmt.Printf("Empty set: %s\n", set)

set.Insert(week1.start, week3.end)
fmt.Printf("Week 1-3: %s\n", set)

set2 := timespanset.Empty()
set2.Insert(week2.start, week2.end)
set.Sub(set2)
fmt.Printf("Week 1-3 minus week 2: %s\n", set)
```

produces

    Empty set: {}
    Week 1-3: {[2015-06-01 00:00:00 -0700 PDT, 2015-06-22 00:00:00 -0700 PDT)}
    Week 1-3 minus week 2: {[2015-06-01 00:00:00 -0700 PDT, 2015-06-08 00:00:00 -0700 PDT), [2015-06-15 00:00:00 -0700 PDT, 2015-06-22 00:00:00 -0700 PDT)}

## Notes

- The intervalset.Set implementation's efficiency could be improved. Insertion
  is best- and worse-case O(n). It could be O(log(n)).

- The library's types and interfaces are still evolving, so expect breaking
  changes.

## Disclaimer

This is not an official Google product.