1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 "golang.org/x/text/language"
15 // This file contains code common to gen.go and the package code.
24 // currencyInfo contains information about a currency.
25 // bits 0..2: index into roundings for standard rounding
26 // bits 3..5: index into roundings for cash rounding
27 type currencyInfo byte
29 // roundingType defines the scale (number of fractional decimals) and increments
30 // in terms of units of size 10^-scale. For example, for scale == 2 and
31 // increment == 1, the currency is rounded to units of 0.01.
32 type roundingType struct {
33 scale, increment uint8
36 // roundings contains rounding data for currencies. This struct is
37 // created by hand as it is very unlikely to change much.
38 var roundings = [...]roundingType{
44 {2, 5}, // cash rounding alternative
47 // regionToCode returns a 16-bit region code. Only two-letter codes are
48 // supported. (Three-letter codes are not needed.)
49 func regionToCode(r language.Region) uint16 {
50 if s := r.String(); len(s) == 2 {
51 return uint16(s[0])<<8 | uint16(s[1])
56 func toDate(t time.Time) uint32 {
61 date := uint32(y) << 4
62 date |= uint32(t.Month())
64 date |= uint32(t.Day())
68 func fromDate(date uint32) time.Time {
69 return time.Date(int(date>>9), time.Month((date>>5)&0xf), int(date&0x1f), 0, 0, 0, 0, time.UTC)