te.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. package te
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type te struct {
  10. locale string
  11. pluralsCardinal []locales.PluralRule
  12. pluralsOrdinal []locales.PluralRule
  13. pluralsRange []locales.PluralRule
  14. decimal string
  15. group string
  16. minus string
  17. percent string
  18. perMille string
  19. timeSeparator string
  20. inifinity string
  21. currencies []string // idx = enum of currency code
  22. currencyNegativePrefix string
  23. currencyNegativeSuffix string
  24. monthsAbbreviated []string
  25. monthsNarrow []string
  26. monthsWide []string
  27. daysAbbreviated []string
  28. daysNarrow []string
  29. daysShort []string
  30. daysWide []string
  31. periodsAbbreviated []string
  32. periodsNarrow []string
  33. periodsShort []string
  34. periodsWide []string
  35. erasAbbreviated []string
  36. erasNarrow []string
  37. erasWide []string
  38. timezones map[string]string
  39. }
  40. // New returns a new instance of translator for the 'te' locale
  41. func New() locales.Translator {
  42. return &te{
  43. locale: "te",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: []locales.PluralRule{6},
  46. pluralsRange: []locales.PluralRule{2, 6},
  47. decimal: ".",
  48. group: ",",
  49. minus: "-",
  50. percent: "%",
  51. perMille: "‰",
  52. timeSeparator: ":",
  53. inifinity: "∞",
  54. currencies: []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "A$", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CN¥", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "FIM", "FJD", "FKP", "FRF", "£", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JP¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "MNT", "MOP", "MRO", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MX$", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZ$", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "STN", "SUR", "SVC", "SYP", "SZL", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "CFPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
  55. currencyNegativePrefix: "(",
  56. currencyNegativeSuffix: ")",
  57. monthsAbbreviated: []string{"", "జన", "ఫిబ్ర", "మార్చి", "ఏప్రి", "మే", "జూన్", "జులై", "ఆగ", "సెప్టెం", "అక్టో", "నవం", "డిసెం"},
  58. monthsNarrow: []string{"", "జ", "ఫి", "మా", "ఏ", "మే", "జూ", "జు", "ఆ", "సె", "అ", "న", "డి"},
  59. monthsWide: []string{"", "జనవరి", "ఫిబ్రవరి", "మార్చి", "ఏప్రిల్", "మే", "జూన్", "జులై", "ఆగస్టు", "సెప్టెంబర్", "అక్టోబర్", "నవంబర్", "డిసెంబర్"},
  60. daysAbbreviated: []string{"ఆది", "సోమ", "మంగళ", "బుధ", "గురు", "శుక్ర", "శని"},
  61. daysNarrow: []string{"ఆ", "సో", "మ", "బు", "గు", "శు", "శ"},
  62. daysShort: []string{"ఆది", "సోమ", "మం", "బుధ", "గురు", "శుక్ర", "శని"},
  63. daysWide: []string{"ఆదివారం", "సోమవారం", "మంగళవారం", "బుధవారం", "గురువారం", "శుక్రవారం", "శనివారం"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"ఉ", "సా"},
  66. periodsWide: []string{"AM", "PM"},
  67. erasAbbreviated: []string{"క్రీపూ", "క్రీశ"},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"క్రీస్తు పూర్వం", "క్రీస్తు శకం"},
  70. timezones: map[string]string{"CHAST": "చాథమ్ ప్రామాణిక సమయం", "SAST": "దక్షిణ ఆఫ్రికా ప్రామాణిక సమయం", "BOT": "బొలీవియా సమయం", "JST": "జపాన్ ప్రామాణిక సమయం", "EST": "తూర్పు ప్రామాణిక సమయం", "IST": "భారతదేశ సమయం", "COST": "కొలంబియా వేసవి సమయం", "UYT": "ఉరుగ్వే ప్రామాణిక సమయం", "HEPM": "సెయింట్ పియర్ మరియు మిక్వెలాన్ పగటి వెలుతురు సమయం", "CST": "మధ్యమ ప్రామాణిక సమయం", "WIB": "పశ్చిమ ఇండోనేషియా సమయం", "ECT": "ఈక్వడార్ సమయం", "HKST": "హాంకాంగ్ వేసవి సమయం", "∅∅∅": "అమెజాన్ వేసవి సమయం", "GMT": "గ్రీన్\u200cవిచ్ సగటు సమయం", "BT": "భూటాన్ సమయం", "NZDT": "న్యూజిల్యాండ్ పగటి వెలుతురు సమయం", "HNOG": "పశ్చిమ గ్రీన్\u200cల్యాండ్ ప్రామాణిక సమయం", "AWST": "ఆస్ట్రేలియన్ పశ్చిమ ప్రామాణిక సమయం", "MYT": "మలేషియా సమయం", "HAT": "న్యూఫౌండ్\u200cల్యాండ్ పగటి వెలుతురు సమయం", "VET": "వెనిజులా సమయం", "MDT": "మకావ్ వేసవి సమయం", "ACWDT": "ఆస్ట్రేలియా మధ్యమ పశ్చిమ పగటి వెలుతురు సమయం", "AEST": "ఆస్ట్రేలియన్ తూర్పు ప్రామాణిక సమయం", "ACST": "ఆస్ట్రేలియా మధ్యమ ప్రామాణిక సమయం", "WIT": "తూర్పు ఇండోనేషియా సమయం", "AWDT": "ఆస్ట్రేలియన్ పశ్చిమ పగటి వెలుతురు సమయం", "HNEG": "తూర్పు గ్రీన్\u200cల్యాండ్ ప్రామాణిక సమయం", "WARST": "పశ్చిమ అర్జెంటీనా వేసవి సమయం", "ChST": "చామర్రో ప్రామాణిక సమయం", "PDT": "పసిఫిక్ పగటి వెలుతురు సమయం", "HNPMX": "మెక్సికన్ పసిఫిక్ ప్రామాణిక సమయం", "ACDT": "ఆస్ట్రేలియా మధ్యమ పగటి వెలుతురు సమయం", "WART": "పశ్చిమ అర్జెంటీనా ప్రామాణిక సమయం", "HNPM": "సెయింట్ పియెర్ మరియు మిక్వెలాన్ ప్రామాణిక సమయం", "CLT": "చిలీ ప్రామాణిక సమయం", "OESZ": "తూర్పు యూరోపియన్ వేసవి సమయం", "CDT": "మధ్యమ పగటి వెలుతురు సమయం", "PST": "పసిఫిక్ ప్రామాణిక సమయం", "TMT": "తుర్క్\u200cమెనిస్తాన్ ప్రామాణిక సమయం", "HECU": "క్యూబా పగటి వెలుతురు సమయం", "EDT": "తూర్పు పగటి వెలుతురు సమయం", "ART": "అర్జెంటీనా ప్రామాణిక సమయం", "JDT": "జపాన్ పగటి వెలుతురు సమయం", "HEOG": "పశ్చిమ గ్రీన్\u200cల్యాండ్ వేసవి సమయం", "MESZ": "సెంట్రల్ యూరోపియన్ వేసవి సమయం", "ADT": "అట్లాంటిక్ పగటి వెలుతురు సమయం", "GFT": "ఫ్రెంచ్ గయానా సమయం", "AKST": "అలాస్కా ప్రామాణిక సమయం", "CLST": "చిలీ వేసవి సమయం", "ARST": "ఆర్జెంటీనా వేసవి సమయం", "ACWST": "మధ్యమ ఆస్ట్రేలియన్ పశ్చిమ ప్రామాణిక సమయం", "LHST": "లార్డ్ హోవ్ ప్రామాణిక సమయం", "WITA": "సెంట్రల్ ఇండోనేషియా సమయం", "HADT": "హవాయ్-అల్యూషియన్ పగటి వెలుతురు సమయం", "WAT": "పశ్చిమ ఆఫ్రికా ప్రామాణిక సమయం", "COT": "కొలంబియా ప్రామాణిక సమయం", "HAST": "హవాయ్-అల్యూషియన్ ప్రామాణిక సమయం", "AEDT": "ఆస్ట్రేలియన్ తూర్పు పగటి వెలుతురు సమయం", "HKT": "హాంకాంగ్ ప్రామాణిక సమయం", "HNT": "న్యూఫౌండ్\u200cల్యాండ్ ప్రామాణిక సమయం", "HNNOMX": "వాయువ్య మెక్సికో ప్రామాణిక సమయం", "MST": "మకావ్ ప్రామాణిక సమయం", "CAT": "సెంట్రల్ ఆఫ్రికా సమయం", "CHADT": "చాథమ్ పగటి వెలుతురు సమయం", "HNCU": "క్యూబా ప్రామాణిక సమయం", "AST": "అట్లాంటిక్ ప్రామాణిక సమయం", "WAST": "పశ్చిమ ఆఫ్రికా వేసవి సమయం", "AKDT": "అలాస్కా పగటి వెలుతురు సమయం", "SGT": "సింగపూర్ ప్రామాణిక సమయం", "UYST": "ఉరుగ్వే వేసవి సమయం", "GYT": "గయానా సమయం", "WESZ": "పశ్చిమ యూరోపియన్ వేసవి సమయం", "LHDT": "లార్డ్ హోవ్ పగటి సమయం", "SRT": "సూరినామ్ సమయం", "OEZ": "తూర్పు యూరోపియన్ ప్రామాణిక సమయం", "HEPMX": "మెక్సికన్ పసిఫిక్ పగటి వెలుతురు సమయం", "WEZ": "పశ్చిమ యూరోపియన్ ప్రామాణిక సమయం", "NZST": "న్యూజిల్యాండ్ ప్రామాణిక సమయం", "HEEG": "తూర్పు గ్రీన్\u200cల్యాండ్ వేసవి సమయం", "MEZ": "సెంట్రల్ యూరోపియన్ ప్రామాణిక సమయం", "HENOMX": "వాయువ్య మెక్సికో పగటి వెలుతురు సమయం", "TMST": "తుర్క్\u200cమెనిస్తాన్ వేసవి సమయం", "EAT": "తూర్పు ఆఫ్రికా సమయం"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (te *te) Locale() string {
  75. return te.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'te'
  78. func (te *te) PluralsCardinal() []locales.PluralRule {
  79. return te.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'te'
  82. func (te *te) PluralsOrdinal() []locales.PluralRule {
  83. return te.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'te'
  86. func (te *te) PluralsRange() []locales.PluralRule {
  87. return te.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'te'
  90. func (te *te) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. if n == 1 {
  93. return locales.PluralRuleOne
  94. }
  95. return locales.PluralRuleOther
  96. }
  97. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'te'
  98. func (te *te) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  99. return locales.PluralRuleOther
  100. }
  101. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'te'
  102. func (te *te) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  103. start := te.CardinalPluralRule(num1, v1)
  104. end := te.CardinalPluralRule(num2, v2)
  105. if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  106. return locales.PluralRuleOther
  107. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  108. return locales.PluralRuleOne
  109. }
  110. return locales.PluralRuleOther
  111. }
  112. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  113. func (te *te) MonthAbbreviated(month time.Month) string {
  114. return te.monthsAbbreviated[month]
  115. }
  116. // MonthsAbbreviated returns the locales abbreviated months
  117. func (te *te) MonthsAbbreviated() []string {
  118. return te.monthsAbbreviated[1:]
  119. }
  120. // MonthNarrow returns the locales narrow month given the 'month' provided
  121. func (te *te) MonthNarrow(month time.Month) string {
  122. return te.monthsNarrow[month]
  123. }
  124. // MonthsNarrow returns the locales narrow months
  125. func (te *te) MonthsNarrow() []string {
  126. return te.monthsNarrow[1:]
  127. }
  128. // MonthWide returns the locales wide month given the 'month' provided
  129. func (te *te) MonthWide(month time.Month) string {
  130. return te.monthsWide[month]
  131. }
  132. // MonthsWide returns the locales wide months
  133. func (te *te) MonthsWide() []string {
  134. return te.monthsWide[1:]
  135. }
  136. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  137. func (te *te) WeekdayAbbreviated(weekday time.Weekday) string {
  138. return te.daysAbbreviated[weekday]
  139. }
  140. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  141. func (te *te) WeekdaysAbbreviated() []string {
  142. return te.daysAbbreviated
  143. }
  144. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  145. func (te *te) WeekdayNarrow(weekday time.Weekday) string {
  146. return te.daysNarrow[weekday]
  147. }
  148. // WeekdaysNarrow returns the locales narrow weekdays
  149. func (te *te) WeekdaysNarrow() []string {
  150. return te.daysNarrow
  151. }
  152. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  153. func (te *te) WeekdayShort(weekday time.Weekday) string {
  154. return te.daysShort[weekday]
  155. }
  156. // WeekdaysShort returns the locales short weekdays
  157. func (te *te) WeekdaysShort() []string {
  158. return te.daysShort
  159. }
  160. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  161. func (te *te) WeekdayWide(weekday time.Weekday) string {
  162. return te.daysWide[weekday]
  163. }
  164. // WeekdaysWide returns the locales wide weekdays
  165. func (te *te) WeekdaysWide() []string {
  166. return te.daysWide
  167. }
  168. // Decimal returns the decimal point of number
  169. func (te *te) Decimal() string {
  170. return te.decimal
  171. }
  172. // Group returns the group of number
  173. func (te *te) Group() string {
  174. return te.group
  175. }
  176. // Group returns the minus sign of number
  177. func (te *te) Minus() string {
  178. return te.minus
  179. }
  180. // FmtNumber returns 'num' with digits/precision of 'v' for 'te' and handles both Whole and Real numbers based on 'v'
  181. func (te *te) FmtNumber(num float64, v uint64) string {
  182. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  183. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  184. count := 0
  185. inWhole := v == 0
  186. inSecondary := false
  187. groupThreshold := 3
  188. b := make([]byte, 0, l)
  189. for i := len(s) - 1; i >= 0; i-- {
  190. if s[i] == '.' {
  191. b = append(b, te.decimal[0])
  192. inWhole = true
  193. continue
  194. }
  195. if inWhole {
  196. if count == groupThreshold {
  197. b = append(b, te.group[0])
  198. count = 1
  199. if !inSecondary {
  200. inSecondary = true
  201. groupThreshold = 2
  202. }
  203. } else {
  204. count++
  205. }
  206. }
  207. b = append(b, s[i])
  208. }
  209. if num < 0 {
  210. b = append(b, te.minus[0])
  211. }
  212. // reverse
  213. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  214. b[i], b[j] = b[j], b[i]
  215. }
  216. return string(b)
  217. }
  218. // FmtPercent returns 'num' with digits/precision of 'v' for 'te' and handles both Whole and Real numbers based on 'v'
  219. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  220. func (te *te) FmtPercent(num float64, v uint64) string {
  221. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  222. l := len(s) + 3
  223. b := make([]byte, 0, l)
  224. for i := len(s) - 1; i >= 0; i-- {
  225. if s[i] == '.' {
  226. b = append(b, te.decimal[0])
  227. continue
  228. }
  229. b = append(b, s[i])
  230. }
  231. if num < 0 {
  232. b = append(b, te.minus[0])
  233. }
  234. // reverse
  235. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  236. b[i], b[j] = b[j], b[i]
  237. }
  238. b = append(b, te.percent...)
  239. return string(b)
  240. }
  241. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'te'
  242. func (te *te) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  243. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  244. symbol := te.currencies[currency]
  245. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  246. count := 0
  247. inWhole := v == 0
  248. inSecondary := false
  249. groupThreshold := 3
  250. b := make([]byte, 0, l)
  251. for i := len(s) - 1; i >= 0; i-- {
  252. if s[i] == '.' {
  253. b = append(b, te.decimal[0])
  254. inWhole = true
  255. continue
  256. }
  257. if inWhole {
  258. if count == groupThreshold {
  259. b = append(b, te.group[0])
  260. count = 1
  261. if !inSecondary {
  262. inSecondary = true
  263. groupThreshold = 2
  264. }
  265. } else {
  266. count++
  267. }
  268. }
  269. b = append(b, s[i])
  270. }
  271. for j := len(symbol) - 1; j >= 0; j-- {
  272. b = append(b, symbol[j])
  273. }
  274. if num < 0 {
  275. b = append(b, te.minus[0])
  276. }
  277. // reverse
  278. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  279. b[i], b[j] = b[j], b[i]
  280. }
  281. if int(v) < 2 {
  282. if v == 0 {
  283. b = append(b, te.decimal...)
  284. }
  285. for i := 0; i < 2-int(v); i++ {
  286. b = append(b, '0')
  287. }
  288. }
  289. return string(b)
  290. }
  291. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'te'
  292. // in accounting notation.
  293. func (te *te) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  294. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  295. symbol := te.currencies[currency]
  296. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  297. count := 0
  298. inWhole := v == 0
  299. inSecondary := false
  300. groupThreshold := 3
  301. b := make([]byte, 0, l)
  302. for i := len(s) - 1; i >= 0; i-- {
  303. if s[i] == '.' {
  304. b = append(b, te.decimal[0])
  305. inWhole = true
  306. continue
  307. }
  308. if inWhole {
  309. if count == groupThreshold {
  310. b = append(b, te.group[0])
  311. count = 1
  312. if !inSecondary {
  313. inSecondary = true
  314. groupThreshold = 2
  315. }
  316. } else {
  317. count++
  318. }
  319. }
  320. b = append(b, s[i])
  321. }
  322. if num < 0 {
  323. for j := len(symbol) - 1; j >= 0; j-- {
  324. b = append(b, symbol[j])
  325. }
  326. b = append(b, te.currencyNegativePrefix[0])
  327. } else {
  328. for j := len(symbol) - 1; j >= 0; j-- {
  329. b = append(b, symbol[j])
  330. }
  331. }
  332. // reverse
  333. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  334. b[i], b[j] = b[j], b[i]
  335. }
  336. if int(v) < 2 {
  337. if v == 0 {
  338. b = append(b, te.decimal...)
  339. }
  340. for i := 0; i < 2-int(v); i++ {
  341. b = append(b, '0')
  342. }
  343. }
  344. if num < 0 {
  345. b = append(b, te.currencyNegativeSuffix...)
  346. }
  347. return string(b)
  348. }
  349. // FmtDateShort returns the short date representation of 't' for 'te'
  350. func (te *te) FmtDateShort(t time.Time) string {
  351. b := make([]byte, 0, 32)
  352. if t.Day() < 10 {
  353. b = append(b, '0')
  354. }
  355. b = strconv.AppendInt(b, int64(t.Day()), 10)
  356. b = append(b, []byte{0x2d}...)
  357. if t.Month() < 10 {
  358. b = append(b, '0')
  359. }
  360. b = strconv.AppendInt(b, int64(t.Month()), 10)
  361. b = append(b, []byte{0x2d}...)
  362. if t.Year() > 9 {
  363. b = append(b, strconv.Itoa(t.Year())[2:]...)
  364. } else {
  365. b = append(b, strconv.Itoa(t.Year())[1:]...)
  366. }
  367. return string(b)
  368. }
  369. // FmtDateMedium returns the medium date representation of 't' for 'te'
  370. func (te *te) FmtDateMedium(t time.Time) string {
  371. b := make([]byte, 0, 32)
  372. b = strconv.AppendInt(b, int64(t.Day()), 10)
  373. b = append(b, []byte{0x20}...)
  374. b = append(b, te.monthsAbbreviated[t.Month()]...)
  375. b = append(b, []byte{0x2c, 0x20}...)
  376. if t.Year() > 0 {
  377. b = strconv.AppendInt(b, int64(t.Year()), 10)
  378. } else {
  379. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  380. }
  381. return string(b)
  382. }
  383. // FmtDateLong returns the long date representation of 't' for 'te'
  384. func (te *te) FmtDateLong(t time.Time) string {
  385. b := make([]byte, 0, 32)
  386. b = strconv.AppendInt(b, int64(t.Day()), 10)
  387. b = append(b, []byte{0x20}...)
  388. b = append(b, te.monthsWide[t.Month()]...)
  389. b = append(b, []byte{0x2c, 0x20}...)
  390. if t.Year() > 0 {
  391. b = strconv.AppendInt(b, int64(t.Year()), 10)
  392. } else {
  393. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  394. }
  395. return string(b)
  396. }
  397. // FmtDateFull returns the full date representation of 't' for 'te'
  398. func (te *te) FmtDateFull(t time.Time) string {
  399. b := make([]byte, 0, 32)
  400. b = strconv.AppendInt(b, int64(t.Day()), 10)
  401. b = append(b, []byte{0x2c, 0x20}...)
  402. b = append(b, te.monthsWide[t.Month()]...)
  403. b = append(b, []byte{0x20}...)
  404. if t.Year() > 0 {
  405. b = strconv.AppendInt(b, int64(t.Year()), 10)
  406. } else {
  407. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  408. }
  409. b = append(b, []byte{0x2c, 0x20}...)
  410. b = append(b, te.daysWide[t.Weekday()]...)
  411. return string(b)
  412. }
  413. // FmtTimeShort returns the short time representation of 't' for 'te'
  414. func (te *te) FmtTimeShort(t time.Time) string {
  415. b := make([]byte, 0, 32)
  416. h := t.Hour()
  417. if h > 12 {
  418. h -= 12
  419. }
  420. b = strconv.AppendInt(b, int64(h), 10)
  421. b = append(b, te.timeSeparator...)
  422. if t.Minute() < 10 {
  423. b = append(b, '0')
  424. }
  425. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  426. b = append(b, []byte{0x20}...)
  427. if t.Hour() < 12 {
  428. b = append(b, te.periodsAbbreviated[0]...)
  429. } else {
  430. b = append(b, te.periodsAbbreviated[1]...)
  431. }
  432. return string(b)
  433. }
  434. // FmtTimeMedium returns the medium time representation of 't' for 'te'
  435. func (te *te) FmtTimeMedium(t time.Time) string {
  436. b := make([]byte, 0, 32)
  437. h := t.Hour()
  438. if h > 12 {
  439. h -= 12
  440. }
  441. b = strconv.AppendInt(b, int64(h), 10)
  442. b = append(b, te.timeSeparator...)
  443. if t.Minute() < 10 {
  444. b = append(b, '0')
  445. }
  446. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  447. b = append(b, te.timeSeparator...)
  448. if t.Second() < 10 {
  449. b = append(b, '0')
  450. }
  451. b = strconv.AppendInt(b, int64(t.Second()), 10)
  452. b = append(b, []byte{0x20}...)
  453. if t.Hour() < 12 {
  454. b = append(b, te.periodsAbbreviated[0]...)
  455. } else {
  456. b = append(b, te.periodsAbbreviated[1]...)
  457. }
  458. return string(b)
  459. }
  460. // FmtTimeLong returns the long time representation of 't' for 'te'
  461. func (te *te) FmtTimeLong(t time.Time) string {
  462. b := make([]byte, 0, 32)
  463. h := t.Hour()
  464. if h > 12 {
  465. h -= 12
  466. }
  467. b = strconv.AppendInt(b, int64(h), 10)
  468. b = append(b, te.timeSeparator...)
  469. if t.Minute() < 10 {
  470. b = append(b, '0')
  471. }
  472. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  473. b = append(b, te.timeSeparator...)
  474. if t.Second() < 10 {
  475. b = append(b, '0')
  476. }
  477. b = strconv.AppendInt(b, int64(t.Second()), 10)
  478. b = append(b, []byte{0x20}...)
  479. if t.Hour() < 12 {
  480. b = append(b, te.periodsAbbreviated[0]...)
  481. } else {
  482. b = append(b, te.periodsAbbreviated[1]...)
  483. }
  484. b = append(b, []byte{0x20}...)
  485. tz, _ := t.Zone()
  486. b = append(b, tz...)
  487. return string(b)
  488. }
  489. // FmtTimeFull returns the full time representation of 't' for 'te'
  490. func (te *te) FmtTimeFull(t time.Time) string {
  491. b := make([]byte, 0, 32)
  492. h := t.Hour()
  493. if h > 12 {
  494. h -= 12
  495. }
  496. b = strconv.AppendInt(b, int64(h), 10)
  497. b = append(b, te.timeSeparator...)
  498. if t.Minute() < 10 {
  499. b = append(b, '0')
  500. }
  501. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  502. b = append(b, te.timeSeparator...)
  503. if t.Second() < 10 {
  504. b = append(b, '0')
  505. }
  506. b = strconv.AppendInt(b, int64(t.Second()), 10)
  507. b = append(b, []byte{0x20}...)
  508. if t.Hour() < 12 {
  509. b = append(b, te.periodsAbbreviated[0]...)
  510. } else {
  511. b = append(b, te.periodsAbbreviated[1]...)
  512. }
  513. b = append(b, []byte{0x20}...)
  514. tz, _ := t.Zone()
  515. if btz, ok := te.timezones[tz]; ok {
  516. b = append(b, btz...)
  517. } else {
  518. b = append(b, tz...)
  519. }
  520. return string(b)
  521. }