-
Notifications
You must be signed in to change notification settings - Fork 1
/
value-objects.go
46 lines (35 loc) · 978 Bytes
/
value-objects.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-FileCopyrightText: 2022 Adriano Prado <dev@dude333.com>
//
// SPDX-License-Identifier: MIT
package rapina
import (
"time"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
// Empresa ------------------------------------------------
type Empresa struct {
CNPJ string `json:"cnpj"`
Nome string `json:"nome"`
}
func (e Empresa) String() string {
return e.CNPJ + " - " + e.Nome
}
// Dinheiro -----------------------------------------------
type Dinheiro struct {
Moeda string
Valor float64
Escala int
}
func (d Dinheiro) String() string {
p := message.NewPrinter(language.BrazilianPortuguese)
return p.Sprintf(`%s %.2f`, d.Moeda, d.Valor*float64(d.Escala))
}
// Data ---------------------------------------------------
type Data time.Time
const layoutISO = "2006-01-02"
func (d Data) String() string { return time.Time(d).Format(layoutISO) }
func NovaData(s string) (Data, error) {
t, err := time.Parse(layoutISO, s)
return Data(t), err
}