From 72c18dba1affdf8b3c97e24e15596f2027236eb1 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Mon, 28 Feb 2022 14:56:44 -0800 Subject: [PATCH] Initial commit --- .gitignore | 1 + LICENSE | 12 ++++++++++++ README.md | 13 +++++++++++++ go.mod | 3 +++ go.sum | 0 main.go | 26 ++++++++++++++++++++++++++ msp/msp.go | 10 ++++++++++ msp/msp_test.go | 9 +++++++++ msp/types.go | 9 +++++++++ 9 files changed, 83 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 msp/msp.go create mode 100644 msp/msp_test.go create mode 100644 msp/types.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba2906d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +main diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..51869c4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +Copyright (C) 2021-2022 by Tai Groot + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8f65cd7 --- /dev/null +++ b/README.md @@ -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) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d24e67c --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/taigrr/most-specific-period + +go 1.17 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/main.go b/main.go new file mode 100644 index 0000000..be75bfc --- /dev/null +++ b/main.go @@ -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()) + } +} diff --git a/msp/msp.go b/msp/msp.go new file mode 100644 index 0000000..409bd44 --- /dev/null +++ b/msp/msp.go @@ -0,0 +1,10 @@ +package msp + +var () + +func init() { +} + +func MostSpecificPeriod(periods ...Period) (id string, err error) { + return +} diff --git a/msp/msp_test.go b/msp/msp_test.go new file mode 100644 index 0000000..cccf3a6 --- /dev/null +++ b/msp/msp_test.go @@ -0,0 +1,9 @@ +package msp + +import ( + "testing" +) + +//(periods ...Period) (id string, err error) { +func TestMostSpecificPeriod(t *testing.T) { +} diff --git a/msp/types.go b/msp/types.go new file mode 100644 index 0000000..dac8c71 --- /dev/null +++ b/msp/types.go @@ -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"` +}