Skip to content

Commit e159fc9

Browse files
joshbranhamclaude
andcommitted
Fix last month time period calculation to handle year boundaries
The LM (Last Month) case in getTimePeriod was using t.Month()-1 which doesn't handle year boundaries correctly. Changed to use AddDate(0, -1, 0) to properly calculate the previous month, fixing the failing test TestGetTimePeriod/Last_Month_(LM). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 278860c commit e159fc9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

cmd/cost/get.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ func getTimePeriod(timePtr *string) (string, string) {
340340

341341
switch *timePtr {
342342
case "LM": //Last Month
343-
start = fmt.Sprintf("%d-%02d-%02d", t.Year(), t.Month()-1, 01)
343+
prevMonth := t.AddDate(0, -1, 0)
344+
start = fmt.Sprintf("%d-%02d-%02d", prevMonth.Year(), prevMonth.Month(), 01)
344345
end = fmt.Sprintf("%d-%02d-%02d", t.Year(), t.Month(), 01)
345346
case "MTD":
346347
start = fmt.Sprintf("%d-%02d-%02d", t.Year(), t.Month(), 01)

0 commit comments

Comments
 (0)