5 Commits

Author SHA1 Message Date
34a9fe93f6 Merge pull request #4 from taigrr/cd/lint-fixes
fix(msp): resolve staticcheck warning and fix typo
2026-03-05 03:24:13 -05:00
523d062b04 fix(msp): resolve unused error value and fix typo
- Fix SA4006 staticcheck warning: unused err from GetDuration
- Fix typo: 'addtion' -> 'addition' in comment
2026-03-05 08:01:11 +00:00
f3bf5c7d6b Merge pull request #3 from taigrr/cd/modernize-and-cleanup
chore: bump Go 1.18→1.26, fix typos, clean up tests
2026-02-22 23:57:45 -05:00
8b431b5d2f chore: bump Go 1.18→1.26, fix typos, clean up tests
- Update go.mod to Go 1.26
- Fix help text typos ('menut' → 'menu', 'most-significant' → 'most-specific')
- Fix error comment typo ('ll' → 'all')
- Remove unnecessary fmt.Sprintf in test names
- Remove unused fmt imports from test files
- Add compile-time interface check for TimeWindow
2026-02-22 21:01:23 +00:00
433d28a87b add sponsor button 2022-10-22 20:47:21 -07:00
9 changed files with 26 additions and 13 deletions

12
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: taigrr # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

2
go.mod
View File

@@ -1,3 +1,3 @@
module github.com/taigrr/most-specific-period module github.com/taigrr/most-specific-period
go 1.18 go 1.26

View File

@@ -41,7 +41,7 @@ func warnMessage() {
} }
func helpMessage() { func helpMessage() {
fmt.Print("\nmost-significant-period [-h][-d]\n\nGenerates a timeline of periods and will provide a most significant period if available.\n\n-h\tShows this help menut\n-d\tProvide a RFC 3339 time to provide an alternate point for calculating MSP.") fmt.Print("\nmost-specific-period [-h][-d]\n\nGenerates a timeline of periods and will provide a most specific period if available.\n\n-h\tShows this help menu\n-d\tProvide an RFC 3339 time to provide an alternate point for calculating MSP.")
} }
func main() { func main() {

View File

@@ -1,7 +1,6 @@
package msp package msp
import ( import (
"fmt"
"testing" "testing"
"time" "time"
) )
@@ -148,7 +147,7 @@ func TestGetChangeOvers(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.testID), func(t *testing.T) { t.Run(tc.testID, func(t *testing.T) {
changeovers := GetChangeOvers(tc.periods...) changeovers := GetChangeOvers(tc.periods...)
if !slicesEqual(changeovers, tc.result) { if !slicesEqual(changeovers, tc.result) {
t.Errorf("Expected %v but got %v", tc.result, changeovers) t.Errorf("Expected %v but got %v", tc.result, changeovers)
@@ -320,7 +319,7 @@ func TestFlattenPeriods(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.testID), func(t *testing.T) { t.Run(tc.testID, func(t *testing.T) {
changeovers := FlattenPeriods(tc.periods...) changeovers := FlattenPeriods(tc.periods...)
if !slicesEqual(changeovers, tc.result) { if !slicesEqual(changeovers, tc.result) {
t.Errorf("Expected %v but got %v", tc.result, changeovers) t.Errorf("Expected %v but got %v", tc.result, changeovers)
@@ -468,7 +467,7 @@ func TestGetNextChangeOver(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.testID), func(t *testing.T) { t.Run(tc.testID, func(t *testing.T) {
ts, err := GetNextChangeOver(now, tc.periods...) ts, err := GetNextChangeOver(now, tc.periods...)
if tc.err != err { if tc.err != err {
t.Errorf("Error %v does not match expected %v", tc.err, err) t.Errorf("Error %v does not match expected %v", tc.err, err)

View File

@@ -5,9 +5,9 @@ import (
) )
var ( var (
// ErrEndAfterStart occurs when a period given has an end time after its start time // ErrEndAfterStart occurs when a period's start time is after its end time
ErrEndAfterStart = errors.New("error: start time is after end time") ErrEndAfterStart = errors.New("error: start time is after end time")
// ErrNoValidPeriods occurs when an empty set of periods is passed or when ll periods are invalid // ErrNoValidPeriods occurs when an empty set of periods is passed or when all periods are invalid
ErrNoValidPeriods = errors.New("error: no valid periods available") ErrNoValidPeriods = errors.New("error: no valid periods available")
// ErrNoNextChangeover occurs when GetNextChangeover is called but there are no changeovers after t // ErrNoNextChangeover occurs when GetNextChangeover is called but there are no changeovers after t
ErrNoNextChangeover = errors.New("error: no valid changeovers available") ErrNoNextChangeover = errors.New("error: no valid changeovers available")

View File

@@ -12,7 +12,7 @@ func MostSpecificPeriod(ts time.Time, periods ...Period) (id string, err error)
return "", ErrNoValidPeriods return "", ErrNoValidPeriods
} }
// find the shortest duration // find the shortest duration
d, err := GetDuration(periods[0].GetStartTime(), periods[0].GetEndTime()) d, _ := GetDuration(periods[0].GetStartTime(), periods[0].GetEndTime())
for _, x := range periods { for _, x := range periods {
p, err := GetDuration(x.GetStartTime(), x.GetEndTime()) p, err := GetDuration(x.GetStartTime(), x.GetEndTime())
if err == nil && p < d { if err == nil && p < d {
@@ -34,7 +34,7 @@ func MostSpecificPeriod(ts time.Time, periods ...Period) (id string, err error)
newest = x.GetStartTime() newest = x.GetStartTime()
} }
} }
// Determine whichever of these periods have the same start time in addtion to duration // Determine whichever of these periods have the same start time in addition to duration
var matchingDurationsAndStartTimes []Period var matchingDurationsAndStartTimes []Period
for _, x := range matchingDurations { for _, x := range matchingDurations {
if x.GetStartTime() == newest { if x.GetStartTime() == newest {

View File

@@ -1,7 +1,6 @@
package msp package msp
import ( import (
"fmt"
"testing" "testing"
"time" "time"
) )
@@ -146,7 +145,7 @@ func TestMostSpecificPeriod(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.testID), func(t *testing.T) { t.Run(tc.testID, func(t *testing.T) {
id, err := MostSpecificPeriod(tc.ts, tc.periods...) id, err := MostSpecificPeriod(tc.ts, tc.periods...)
if id != tc.result { if id != tc.result {
t.Errorf("ID '%s' does not match expected '%s'", id, tc.result) t.Errorf("ID '%s' does not match expected '%s'", id, tc.result)

View File

@@ -263,7 +263,7 @@ func TestGenerateTime(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(fmt.Sprintf("%s", tc.testID), func(t *testing.T) { t.Run(tc.testID, func(t *testing.T) {
timeline := GenerateTimeline(tc.periods...) timeline := GenerateTimeline(tc.periods...)
if len(timeline) != len(tc.result) { if len(timeline) != len(tc.result) {
t.Fatalf("Time line had %d results, expected %d", len(timeline), len(tc.result)) t.Fatalf("Time line had %d results, expected %d", len(timeline), len(tc.result))

View File

@@ -2,6 +2,9 @@ package msp
import "time" import "time"
// Compile-time interface check.
var _ Period = TimeWindow{}
type Period interface { type Period interface {
GetStartTime() time.Time GetStartTime() time.Time
GetEndTime() time.Time GetEndTime() time.Time