OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / text / currency / common.go
1 // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
2
3 package currency
4
5 import (
6         "time"
7
8         "golang.org/x/text/language"
9 )
10
11 // This file contains code common to gen.go and the package code.
12
13 const (
14         cashShift = 3
15         roundMask = 0x7
16
17         nonTenderBit = 0x8000
18 )
19
20 // currencyInfo contains information about a currency.
21 // bits 0..2: index into roundings for standard rounding
22 // bits 3..5: index into roundings for cash rounding
23 type currencyInfo byte
24
25 // roundingType defines the scale (number of fractional decimals) and increments
26 // in terms of units of size 10^-scale. For example, for scale == 2 and
27 // increment == 1, the currency is rounded to units of 0.01.
28 type roundingType struct {
29         scale, increment uint8
30 }
31
32 // roundings contains rounding data for currencies. This struct is
33 // created by hand as it is very unlikely to change much.
34 var roundings = [...]roundingType{
35         {2, 1}, // default
36         {0, 1},
37         {1, 1},
38         {3, 1},
39         {4, 1},
40         {2, 5}, // cash rounding alternative
41 }
42
43 // regionToCode returns a 16-bit region code. Only two-letter codes are
44 // supported. (Three-letter codes are not needed.)
45 func regionToCode(r language.Region) uint16 {
46         if s := r.String(); len(s) == 2 {
47                 return uint16(s[0])<<8 | uint16(s[1])
48         }
49         return 0
50 }
51
52 func toDate(t time.Time) uint32 {
53         y := t.Year()
54         if y == 1 {
55                 return 0
56         }
57         date := uint32(y) << 4
58         date |= uint32(t.Month())
59         date <<= 5
60         date |= uint32(t.Day())
61         return date
62 }
63
64 func fromDate(date uint32) time.Time {
65         return time.Date(int(date>>9), time.Month((date>>5)&0xf), int(date&0x1f), 0, 0, 0, 0, time.UTC)
66 }