mirror of
https://github.com/taigrr/most-specific-period.git
synced 2026-04-02 03:38:41 -07:00
Initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
main
|
||||
12
LICENSE
Normal file
12
LICENSE
Normal file
@@ -0,0 +1,12 @@
|
||||
Copyright (C) 2021-2022 by Tai Groot <tai@taigrr.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
13
README.md
Normal file
13
README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
Most Specific Period
|
||||
An MSP, or Most Specific Period is defined as follows:
|
||||
- Given a period that hasn’t started or has already finished, an error is returned.
|
||||
- Given a period that is currently valid, the period which is valid is chosen.
|
||||
- Given two valid periods, one which is a month long and one which is a week long and completely overlap, the week-long period is chosen.
|
||||
- Given two valid periods, one which is a week long and one which is a month long, but only overlap by a day (in either direction) the week-long period is selected.
|
||||
- Given two valid periods, each exactly 30 days long, but offset by a week, the second (newer) period is given precedence.
|
||||
- Given two valid periods with exact same start and end time, the period with the lowest-ranking lexicographic identifier is returned (i.e. period B has precedence over period A, as ‘B’ comes after ‘A’ lexicographically.) This is because the default behavior is to choose the newer period, and named periods are often in lexicographical order (increasing numbers, letters, etc.)
|
||||
|
||||
This library operates off Period structs, which contain the following:
|
||||
- StartTime (time.Time)
|
||||
- EndTime (time.Time)
|
||||
- Identifier (string)
|
||||
3
go.mod
Normal file
3
go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/taigrr/most-specific-period
|
||||
|
||||
go 1.17
|
||||
26
main.go
Normal file
26
main.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var addr = flag.String("addr", "0.0.0.0:8080", "http service address")
|
||||
|
||||
func init() {
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
s := bufio.NewScanner(os.Stdin)
|
||||
for s.Scan() {
|
||||
log.Println("line", s.Text())
|
||||
}
|
||||
}
|
||||
10
msp/msp.go
Normal file
10
msp/msp.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package msp
|
||||
|
||||
var ()
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
func MostSpecificPeriod(periods ...Period) (id string, err error) {
|
||||
return
|
||||
}
|
||||
9
msp/msp_test.go
Normal file
9
msp/msp_test.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package msp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
//(periods ...Period) (id string, err error) {
|
||||
func TestMostSpecificPeriod(t *testing.T) {
|
||||
}
|
||||
9
msp/types.go
Normal file
9
msp/types.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package msp
|
||||
|
||||
import "time"
|
||||
|
||||
type Period struct {
|
||||
StartTime time.Time `json:"startTime"`
|
||||
EndTime time.Time `json:"endTime"`
|
||||
Identifier string `json:"identifier"`
|
||||
}
|
||||
Reference in New Issue
Block a user