Updte License

This commit is contained in:
aditya.siregar 2024-08-23 00:27:42 +07:00
parent cbc2a842dd
commit b7799b7ada

View File

@ -102,16 +102,55 @@ type PartnerLicense struct {
} }
func (l *LicenseDB) ToPartnerLicense() PartnerLicense { 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 var licenseStatus string
if now.Before(l.StartDate) {
if startDateInGMT7.After(startOfDay) {
licenseStatus = "INACTIVE" 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" licenseStatus = "EXPIRED"
} else if daysToExpire <= 30 {
licenseStatus = "EXPIRING_SOON"
} else { } else {
licenseStatus = "ACTIVE" licenseStatus = "ACTIVE"
} }