money

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2024 License: MIT Imports: 6 Imported by: 21

README

github.com/crediterra/money

Golang package to work with money

Documentation

Index

Constants

View Source
const (
	CurrencySymbolEUR = "€"
	CurrencySymbolUSD = "$"
	CurrencySymbolGPB = "£"
	CurrencySymbolJPY = "¥"
	CurrencySymbolRUR = "₽"
	CurrencySymbolIRR = "﷼"
	CurrencySymbolUAH = "₴"
	CurrencySymbolUZS = "сўм"
	CurrencySymbolBYN = "Br"
	CurrencySymbolTJS = "смн."
	CurrencySymbolKZT = "₸"
)

Variables

View Source
var CurrencyBYN = CurrencyCode("BYN")
View Source
var CurrencyEUR = CurrencyCode("EUR")
View Source
var CurrencyGBP = CurrencyCode("GPB")
View Source
var CurrencyIRR = CurrencyCode("IRR")
View Source
var CurrencyJPY = CurrencyCode("JPY")
View Source
var CurrencyKZT = CurrencyCode("KZT")
View Source
var CurrencyRUB = CurrencyCode("RUB")
View Source
var CurrencyTJS = CurrencyCode("TJS")
View Source
var CurrencyUAH = CurrencyCode("UAH")
View Source
var CurrencyUSD = CurrencyCode("USD")
View Source
var CurrencyUZS = CurrencyCode("UZS")

Functions

func HasCurrencyPrefix

func HasCurrencyPrefix(s string) bool

func IsKnownCurrency added in v0.1.0

func IsKnownCurrency(c CurrencyCode) bool

Types

type Amount

type Amount struct {
	Currency CurrencyCode        `json:"currency" firestore:"currency"`
	Value    decimal.Decimal64p2 `json:"value" firestore:"value"`
}

Amount holds amount of money with currency

func NewAmount

func NewAmount(currency CurrencyCode, value decimal.Decimal64p2) Amount

NewAmount creates new amount

func (Amount) IsZero added in v0.1.0

func (a Amount) IsZero() bool

IsZero returns true if amount is zero

func (Amount) String

func (a Amount) String() string

String returns string representation of amount

func (Amount) Validate added in v0.1.0

func (a Amount) Validate() error

Validate returns error if amount is invalid

type Balance

type Balance map[CurrencyCode]decimal.Decimal64p2

func (Balance) Add

func (b Balance) Add(amount Amount) Balance

func (Balance) CommaSeparatedUnsignedWithSymbols

func (b Balance) CommaSeparatedUnsignedWithSymbols(translator interface{ Translate(s string) string }) string

func (Balance) Equal

func (b Balance) Equal(b2 Balance) bool

func (Balance) IsZero

func (b Balance) IsZero() bool

func (Balance) OnlyNegative

func (b Balance) OnlyNegative() Balance

func (Balance) OnlyPositive

func (b Balance) OnlyPositive() Balance

func (Balance) Reversed

func (b Balance) Reversed() (reversed Balance)

type Balanced

type Balanced struct {
	Balance        Balance   `firestore:"balance,noindex,omitempty,noindex" json:"balance,omitempty"`
	LastTransferID string    `datastore:"lastTransferID,omitempty,noindex" json:"lastTransferID,omitempty"`
	LastTransferAt time.Time `datastore:"lastTransferAt,omitempty,noindex" json:"lastTransferAt,omitempty"`

	// Do not remove, needed to hide a balance/history menu in Telegram
	CountOfTransfers int `datastore:"countOfTransfers,omitempty" json:"countOfTransfers,omitempty"`
}

Balanced is a struct to store balance and summary of transfers ffjson: skip

func (*Balanced) AddToBalance

func (v *Balanced) AddToBalance(currency CurrencyCode, value decimal.Decimal64p2)

type CurrencyCode added in v0.1.0

type CurrencyCode string

func CleanupCurrency

func CleanupCurrency(s string) CurrencyCode

func (CurrencyCode) IsMoney added in v0.1.0

func (c CurrencyCode) IsMoney() bool

func (CurrencyCode) Sign added in v0.1.0

func (c CurrencyCode) Sign() string

func (CurrencyCode) SignAndCode added in v0.1.0

func (c CurrencyCode) SignAndCode() string

type TestStruct

type TestStruct struct {
	ID   int64
	Name string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL