<commit_before>package appstore

import (
	"time"
)

type Receipt struct {
	responseVersion int
	rawReceipt      string
	Status          int
	Environment     string

	ReceiptType                string
	AdamID                     int64
	AppItemID                  int64
	BundleID                   string
	ApplicationVersion         string
	DownloadID                 int64
	OriginalApplicationVersion string
	RequestDate                time.Time
	OriginalPurchaseDate       time.Time
	InApps                     ReceiptInApps

	LatestReceiptInfo ReceiptInApps
	LatestReceipt     string
}

func (r *Receipt) String() string {
	return r.rawReceipt
}

func (r *Receipt) ResponseVersion() int {
	if r.responseVersion == 0 {
		return verIOS7
	}
	return r.responseVersion
}

func (r *Receipt) GetStatus() int {
	return r.Status
}

func (r *Receipt) GetEnvironment() string {
	return r.Environment
}

func (r *Receipt) LatestReceiptString() string {
	return r.LatestReceipt
}

func (r *Receipt) IsValidReceipt() bool {
	return r.Status == 0
}

func (r *Receipt) IsAutoRenewable() bool {
	return r.InApps.IsAutoRenewable()
}

func (r *Receipt) HasError() error {
	return HandleError(r.Status)
}

func (r *Receipt) HasExpired() bool {
	return r.Status == 21006
}

func (r *Receipt) GetTransactionIDsByProduct(product string) []int64 {
	return r.InApps.TransactionIDsByProduct(product)
}

func (r *Receipt) GetByTransactionID(id int64) *ReceiptInApp {
	return r.InApps.ByTransactionID(id)
}

type ReceiptInApp struct {
	Quantity                  int64
	ProductID                 string
	TransactionID             int64
	OriginalTransactionID     int64
	IsTrialPeriod             bool
	AppItemID                 int64
	VersionExternalIdentifier int64
	WebOrderLineItemID        int64
	PurchaseDate              time.Time
	OriginalPurchaseDate      time.Time
	ExpiresDate               time.Time
	CancellationDate          time.Time
}

type ReceiptInApps []*ReceiptInApp

func (r ReceiptInApps) IsAutoRenewable() bool {
	for _, v := range r {
		if v.ExpiresDate.IsZero() {
			return false
		}
	}
	return true
}

func (r ReceiptInApps) ByTransactionID(id int64) *ReceiptInApp {
	for _, v := range r {
		if v.TransactionID == id {
			return v
		}
	}
	return nil
}

func (r ReceiptInApps) ByProduct(productID string) ReceiptInApps {
	var matched ReceiptInApps
	for _, v := range r {
		if v.ProductID != productID {
			continue
		}
		matched = append(matched, v)
	}
	return matched
}

func (r ReceiptInApps) TransactionIDsByProduct(productID string) []int64 {
	var matched []int64
	for _, v := range r {
		if v.ProductID != productID {
			continue
		}
		matched = append(matched, v.TransactionID)
	}
	return matched
}

// for auto-renewable
func (r ReceiptInApps) LastExpiresByProductID(productID string) *ReceiptInApp {
	var latest *ReceiptInApp
	for _, v := range r {
		switch {
		case v.ProductID != productID:
			continue
		case latest != nil && latest.ExpiresDate.Before(v.ExpiresDate):
			continue
		}
		latest = v
	}
	return latest
}
<commit_msg>Fixed a stupid bug for comparing date<commit_after>package appstore

import (
	"time"
)

type Receipt struct {
	responseVersion int
	rawReceipt      string
	Status          int
	Environment     string

	ReceiptType                string
	AdamID                     int64
	AppItemID                  int64
	BundleID                   string
	ApplicationVersion         string
	DownloadID                 int64
	OriginalApplicationVersion string
	RequestDate                time.Time
	OriginalPurchaseDate       time.Time
	InApps                     ReceiptInApps

	LatestReceiptInfo ReceiptInApps
	LatestReceipt     string
}

func (r *Receipt) String() string {
	return r.rawReceipt
}

func (r *Receipt) ResponseVersion() int {
	if r.responseVersion == 0 {
		return verIOS7
	}
	return r.responseVersion
}

func (r *Receipt) GetStatus() int {
	return r.Status
}

func (r *Receipt) GetEnvironment() string {
	return r.Environment
}

func (r *Receipt) LatestReceiptString() string {
	return r.LatestReceipt
}

func (r *Receipt) IsValidReceipt() bool {
	return r.Status == 0
}

func (r *Receipt) IsAutoRenewable() bool {
	return r.InApps.IsAutoRenewable()
}

func (r *Receipt) HasError() error {
	return HandleError(r.Status)
}

func (r *Receipt) HasExpired() bool {
	return r.Status == 21006
}

func (r *Receipt) GetTransactionIDsByProduct(product string) []int64 {
	return r.InApps.TransactionIDsByProduct(product)
}

func (r *Receipt) GetByTransactionID(id int64) *ReceiptInApp {
	return r.InApps.ByTransactionID(id)
}

type ReceiptInApp struct {
	Quantity                  int64
	ProductID                 string
	TransactionID             int64
	OriginalTransactionID     int64
	IsTrialPeriod             bool
	AppItemID                 int64
	VersionExternalIdentifier int64
	WebOrderLineItemID        int64
	PurchaseDate              time.Time
	OriginalPurchaseDate      time.Time
	ExpiresDate               time.Time
	CancellationDate          time.Time
}

type ReceiptInApps []*ReceiptInApp

func (r ReceiptInApps) IsAutoRenewable() bool {
	for _, v := range r {
		if v.ExpiresDate.IsZero() {
			return false
		}
	}
	return true
}

func (r ReceiptInApps) ByTransactionID(id int64) *ReceiptInApp {
	for _, v := range r {
		if v.TransactionID == id {
			return v
		}
	}
	return nil
}

func (r ReceiptInApps) ByProduct(productID string) ReceiptInApps {
	var matched ReceiptInApps
	for _, v := range r {
		if v.ProductID != productID {
			continue
		}
		matched = append(matched, v)
	}
	return matched
}

func (r ReceiptInApps) TransactionIDsByProduct(productID string) []int64 {
	var matched []int64
	for _, v := range r {
		if v.ProductID != productID {
			continue
		}
		matched = append(matched, v.TransactionID)
	}
	return matched
}

// for auto-renewable
func (r ReceiptInApps) LastExpiresByProductID(productID string) *ReceiptInApp {
	var latest *ReceiptInApp
	for _, v := range r {
		switch {
		case v.ProductID != productID:
			continue
		case latest != nil && latest.ExpiresDate.After(v.ExpiresDate):
			continue
		}
		latest = v
	}
	return latest
}

{'fraction_non_alphanumeric': 0.07971133344267672, 'fraction_numerical': 0.011809086435952108, 'mean_word_length': 2.83763373190686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3580944', 'n_tokens_mistral': 2185, 'n_tokens_neox': 1984, 'n_words': 526}