init: 1.0.0

This commit is contained in:
Chang lue Tsen
2025-04-25 12:08:29 +09:00
commit 8addcc584b
1031 changed files with 76472 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
package calculateMonths
import "time"
// CalculateMonths calculates the number of months between startTime and endTime.
// It rounds up to the next month if there are remaining days.
func CalculateMonths(startTime, endTime time.Time) int8 {
// Calculate the year and month difference
years := endTime.Year() - startTime.Year()
months := int8(years*12) + int8(endTime.Month()) - int8(startTime.Month())
// Always round up if endTime is not on the same or earlier day of the month
if endTime.Day() > startTime.Day() || (endTime.Day() < startTime.Day() && endTime.After(startTime)) {
months++
}
return months
}
@@ -0,0 +1,13 @@
package calculateMonths
import (
"testing"
"time"
)
func TestCalculateMonths(t *testing.T) {
startTime, _ := time.Parse(time.DateTime, "2025-01-15 00:00:00")
EndTime, _ := time.Parse(time.DateTime, "2025-05-15 00:00:00")
months := CalculateMonths(startTime, EndTime)
t.Log(months)
}