diff --git a/internal/entity/license.go b/internal/entity/license.go index 105254a..2985c70 100644 --- a/internal/entity/license.go +++ b/internal/entity/license.go @@ -102,16 +102,55 @@ type PartnerLicense struct { } func (l *LicenseDB) ToPartnerLicense() PartnerLicense { - now := time.Now() + // Define the GMT+7 timezone + location, err := time.LoadLocation("Asia/Jakarta") + if err != nil { + // Handle the error appropriately, but for simplicity, we'll default to UTC + location = time.FixedZone("GMT+7", 7*60*60) + } - daysToExpire := int64(l.EndDate.Sub(now).Hours() / 24) + // Reinterpret StartDate as GMT+7 without changing the actual time values + startDateInGMT7 := time.Date( + l.StartDate.Year(), + l.StartDate.Month(), + l.StartDate.Day(), + l.StartDate.Hour(), + l.StartDate.Minute(), + l.StartDate.Second(), + l.StartDate.Nanosecond(), + location, + ) + + // Convert EndDate similarly, if needed + endDateInGMT7 := time.Date( + l.EndDate.Year(), + l.EndDate.Month(), + l.EndDate.Day(), + l.EndDate.Hour(), + l.EndDate.Minute(), + l.EndDate.Second(), + l.EndDate.Nanosecond(), + location, + ) + + now := time.Now().In(location) + startOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) + + daysToExpire := int64(endDateInGMT7.Sub(startOfDay).Hours() / 24) var licenseStatus string - if now.Before(l.StartDate) { + + if startDateInGMT7.After(startOfDay) { licenseStatus = "INACTIVE" - } else if daysToExpire < 0 { + } else if startDateInGMT7.Equal(startOfDay) || (startDateInGMT7.Before(startOfDay) && endDateInGMT7.After(startOfDay)) { + if daysToExpire < 0 { + licenseStatus = "EXPIRED" + } else if daysToExpire <= 30 { + licenseStatus = "EXPIRING_SOON" + } else { + licenseStatus = "ACTIVE" + } + } else if endDateInGMT7.Before(startOfDay) { licenseStatus = "EXPIRED" - } else if daysToExpire <= 30 { - licenseStatus = "EXPIRING_SOON" } else { licenseStatus = "ACTIVE" }