...
1
2
3 package currency
4
5 import (
6 "time"
7
8 "golang.org/x/text/language"
9 )
10
11
12
13 const (
14 cashShift = 3
15 roundMask = 0x7
16
17 nonTenderBit = 0x8000
18 )
19
20
21
22
23 type currencyInfo byte
24
25
26
27
28 type roundingType struct {
29 scale, increment uint8
30 }
31
32
33
34 var roundings = [...]roundingType{
35 {2, 1},
36 {0, 1},
37 {1, 1},
38 {3, 1},
39 {4, 1},
40 {2, 5},
41 {2, 50},
42 }
43
44
45
46 func regionToCode(r language.Region) uint16 {
47 if s := r.String(); len(s) == 2 {
48 return uint16(s[0])<<8 | uint16(s[1])
49 }
50 return 0
51 }
52
53 func toDate(t time.Time) uint32 {
54 y := t.Year()
55 if y == 1 {
56 return 0
57 }
58 date := uint32(y) << 4
59 date |= uint32(t.Month())
60 date <<= 5
61 date |= uint32(t.Day())
62 return date
63 }
64
65 func fromDate(date uint32) time.Time {
66 return time.Date(int(date>>9), time.Month((date>>5)&0xf), int(date&0x1f), 0, 0, 0, 0, time.UTC)
67 }
68
View as plain text