1// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
2
3package currency
4
5import (
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
13const (
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
23type 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.
28type 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.
34var 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	{2, 50},
42}
43
44// regionToCode returns a 16-bit region code. Only two-letter codes are
45// supported. (Three-letter codes are not needed.)
46func 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
53func 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
65func 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