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