Skip to content

Commit

Permalink
fix calc expired date
Browse files Browse the repository at this point in the history
  • Loading branch information
irostub committed Jan 16, 2024
1 parent d44a0e6 commit 151f29f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions discord/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func SendWebhook(conf *config.Config, items []client.Items) {
colorCode := conf.Color
for _, item := range items {
tm := time.Unix(item.DiscountExpiration, 0)
if tm.Before(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)) {
continue
}
embed := GameEmbed{
Title: item.Name,
Description: " [-" + strconv.Itoa(item.DiscountPercent) + "%]" + strconv.FormatInt(item.FinalPrice/100, 10) + conf.CurrencySymbol + " ~~" + strconv.FormatInt(item.OriginalPrice/100, 10) + conf.CurrencySymbol + "~~ ",
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var conf *config.Config
func (cache Cache) updateAndSend() {
responseItems := cache.Client.Get().Specials.Items
for _, responseItem := range responseItems {
if responseItem.DiscountExpiration <= 0 {
continue
}
_, ok := cache.Items[responseItem.ID]
if !ok {
cache.Items[responseItem.ID] = responseItem
Expand Down
4 changes: 4 additions & 0 deletions steam/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,9 @@ func (client Client) Get() *Response {
func (items Items) IsExpired() bool {
now := time.Now().Unix()
expirationTime := items.DiscountExpiration
standardTime := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
if items.DiscountExpiration <= 0 || standardTime.After(time.Unix(items.DiscountExpiration, 0)) {
return true
}
return now > expirationTime
}

0 comments on commit 151f29f

Please sign in to comment.