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