ta.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. package ta
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type ta 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 'ta' locale
  41. func New() locales.Translator {
  42. return &ta{
  43. locale: "ta",
  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", "¥", "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{"முற்பகல்", "பிற்பகல்"},
  65. periodsNarrow: []string{"மு.ப", "பி.ப"},
  66. periodsWide: []string{"முற்பகல்", "பிற்பகல்"},
  67. erasAbbreviated: []string{"கி.மு.", "கி.பி."},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"கிறிஸ்துவுக்கு முன்", "அன்னோ டோமினி"},
  70. timezones: map[string]string{"PST": "பசிபிக் நிலையான நேரம்", "WESZ": "மேற்கத்திய ஐரோப்பிய கோடை நேரம்", "BT": "பூடான் நேரம்", "HKT": "ஹாங்காங் நிலையான நேரம்", "∅∅∅": "அசோர்ஸ் கோடை நேரம்", "MST": "மக்காவ் தர நேரம்", "HNCU": "கியூபா நிலையான நேரம்", "NZDT": "நியூசிலாந்து பகலொளி நேரம்", "HNPM": "செயின்ட் பியரி & மிக்குயிலான் நிலையான நேரம்", "AEST": "ஆஸ்திரேலியன் கிழக்கத்திய நிலையான நேரம்", "HNOG": "மேற்கு கிரீன்லாந்து நிலையான நேரம்", "HEOG": "மேற்கு கிரீன்லாந்து கோடை நேரம்", "VET": "வெனிசுலா நேரம்", "ChST": "சாமோரோ நிலையான நேரம்", "GMT": "கிரீன்விச் சராசரி நேரம்", "PDT": "பசிபிக் பகலொளி நேரம்", "WAT": "மேற்கு ஆப்பிரிக்க நிலையான நேரம்", "ACDT": "ஆஸ்திரேலியன் மத்திய பகலொளி நேரம்", "HAT": "நியூஃபவுண்ட்லாந்து பகலொளி நேரம்", "HNNOMX": "வடமேற்கு மெக்ஸிகோ நிலையான நேரம்", "CLT": "சிலி நிலையான நேரம்", "COT": "கொலம்பியா நிலையான நேரம்", "MYT": "மலேஷிய நேரம்", "AKDT": "அலாஸ்கா பகலொளி நேரம்", "WART": "மேற்கத்திய அர்ஜென்டினா நிலையான நேரம்", "HEPMX": "மெக்ஸிகன் பசிபிக் பகலொளி நேரம்", "WIB": "மேற்கத்திய இந்தோனேசிய நேரம்", "JST": "ஜப்பான் நிலையான நேரம்", "SRT": "சுரினாம் நேரம்", "COST": "கொலம்பியா கோடை நேரம்", "CHAST": "சத்தாம் நிலையான நேரம்", "CDT": "மத்திய பகலொளி நேரம்", "EDT": "கிழக்கத்திய பகலொளி நேரம்", "ACST": "ஆஸ்திரேலியன் மத்திய நிலையான நேரம்", "WARST": "மேற்கத்திய அர்ஜென்டினா கோடை நேரம்", "MDT": "மக்காவ் கோடை நேரம்", "HKST": "ஹாங்காங் கோடை நேரம்", "ARST": "அர்ஜென்டினா கோடை நேரம்", "EAT": "கிழக்கு ஆப்பிரிக்க நேரம்", "HADT": "ஹவாய்-அலேஷியன் பகலொளி நேரம்", "CHADT": "சத்தாம் பகலொளி நேரம்", "HECU": "கியூபா பகலொளி நேரம்", "HNPMX": "மெக்ஸிகன் பசிபிக் நிலையான நேரம்", "MESZ": "மத்திய ஐரோப்பிய கோடை நேரம்", "CLST": "சிலி கோடை நேரம்", "TMT": "துர்க்மெனிஸ்தான் நிலையான நேரம்", "HAST": "ஹவாய்-அலேஷியன் நிலையான நேரம்", "AWST": "ஆஸ்திரேலியன் மேற்கத்திய நிலையான நேரம்", "ACWDT": "ஆஸ்திரேலியன் மத்திய மேற்கத்திய பகலொளி நேரம்", "LHST": "லார்ட் ஹோவ் நிலையான நேரம்", "LHDT": "லார்ட் ஹோவ் பகலொளி நேரம்", "CST": "மத்திய நிலையான நேரம்", "AST": "அட்லாண்டிக் நிலையான நேரம்", "JDT": "ஜப்பான் பகலொளி நேரம்", "HEEG": "கிழக்கு கிரீன்லாந்து கோடை நேரம்", "OEZ": "கிழக்கத்திய ஐரோப்பிய நிலையான நேரம்", "HNT": "நியூஃபவுண்ட்லாந்து நிலையான நேரம்", "AEDT": "ஆஸ்திரேலியன் கிழக்கத்திய பகலொளி நேரம்", "WAST": "மேற்கு ஆப்பிரிக்க கோடை நேரம்", "WEZ": "மேற்கத்திய ஐரோப்பிய நிலையான நேரம்", "AKST": "அலாஸ்கா நிலையான நேரம்", "ACWST": "ஆஸ்திரேலியன் மத்திய மேற்கத்திய நிலையான நேரம்", "MEZ": "மத்திய ஐரோப்பிய நிலையான நேரம்", "UYST": "உருகுவே கோடை நேரம்", "IST": "இந்திய நிலையான நேரம்", "HEPM": "செயின்ட் பியரி & மிக்குயிலான் பகலொளி நேரம்", "CAT": "மத்திய ஆப்பிரிக்க நேரம்", "BOT": "பொலிவியா நேரம்", "GFT": "ஃபிரஞ்சு கயானா நேரம்", "SGT": "சிங்கப்பூர் நிலையான நேரம்", "EST": "கிழக்கத்திய நிலையான நேரம்", "HNEG": "கிழக்கு கிரீன்லாந்து நிலையான நேரம்", "WIT": "கிழக்கத்திய இந்தோனேசிய நேரம்", "TMST": "துர்க்மெனிஸ்தான் கோடை நேரம்", "ADT": "அட்லாண்டிக் பகலொளி நேரம்", "ART": "அர்ஜென்டினா நிலையான நேரம்", "GYT": "கயானா நேரம்", "UYT": "உருகுவே நிலையான நேரம்", "NZST": "நியூசிலாந்து நிலையான நேரம்", "ECT": "ஈக்வடார் நேரம்", "WITA": "மத்திய இந்தோனேசிய நேரம்", "HENOMX": "வடமேற்கு மெக்ஸிகோ பகலொளி நேரம்", "OESZ": "கிழக்கத்திய ஐரோப்பிய கோடை நேரம்", "AWDT": "ஆஸ்திரேலியன் மேற்கத்திய பகலொளி நேரம்", "SAST": "தென் ஆப்பிரிக்க நிலையான நேரம்"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (ta *ta) Locale() string {
  75. return ta.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'ta'
  78. func (ta *ta) PluralsCardinal() []locales.PluralRule {
  79. return ta.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'ta'
  82. func (ta *ta) PluralsOrdinal() []locales.PluralRule {
  83. return ta.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'ta'
  86. func (ta *ta) PluralsRange() []locales.PluralRule {
  87. return ta.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ta'
  90. func (ta *ta) 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 'ta'
  98. func (ta *ta) 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 'ta'
  102. func (ta *ta) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  103. start := ta.CardinalPluralRule(num1, v1)
  104. end := ta.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 (ta *ta) MonthAbbreviated(month time.Month) string {
  114. return ta.monthsAbbreviated[month]
  115. }
  116. // MonthsAbbreviated returns the locales abbreviated months
  117. func (ta *ta) MonthsAbbreviated() []string {
  118. return ta.monthsAbbreviated[1:]
  119. }
  120. // MonthNarrow returns the locales narrow month given the 'month' provided
  121. func (ta *ta) MonthNarrow(month time.Month) string {
  122. return ta.monthsNarrow[month]
  123. }
  124. // MonthsNarrow returns the locales narrow months
  125. func (ta *ta) MonthsNarrow() []string {
  126. return ta.monthsNarrow[1:]
  127. }
  128. // MonthWide returns the locales wide month given the 'month' provided
  129. func (ta *ta) MonthWide(month time.Month) string {
  130. return ta.monthsWide[month]
  131. }
  132. // MonthsWide returns the locales wide months
  133. func (ta *ta) MonthsWide() []string {
  134. return ta.monthsWide[1:]
  135. }
  136. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  137. func (ta *ta) WeekdayAbbreviated(weekday time.Weekday) string {
  138. return ta.daysAbbreviated[weekday]
  139. }
  140. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  141. func (ta *ta) WeekdaysAbbreviated() []string {
  142. return ta.daysAbbreviated
  143. }
  144. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  145. func (ta *ta) WeekdayNarrow(weekday time.Weekday) string {
  146. return ta.daysNarrow[weekday]
  147. }
  148. // WeekdaysNarrow returns the locales narrow weekdays
  149. func (ta *ta) WeekdaysNarrow() []string {
  150. return ta.daysNarrow
  151. }
  152. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  153. func (ta *ta) WeekdayShort(weekday time.Weekday) string {
  154. return ta.daysShort[weekday]
  155. }
  156. // WeekdaysShort returns the locales short weekdays
  157. func (ta *ta) WeekdaysShort() []string {
  158. return ta.daysShort
  159. }
  160. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  161. func (ta *ta) WeekdayWide(weekday time.Weekday) string {
  162. return ta.daysWide[weekday]
  163. }
  164. // WeekdaysWide returns the locales wide weekdays
  165. func (ta *ta) WeekdaysWide() []string {
  166. return ta.daysWide
  167. }
  168. // Decimal returns the decimal point of number
  169. func (ta *ta) Decimal() string {
  170. return ta.decimal
  171. }
  172. // Group returns the group of number
  173. func (ta *ta) Group() string {
  174. return ta.group
  175. }
  176. // Group returns the minus sign of number
  177. func (ta *ta) Minus() string {
  178. return ta.minus
  179. }
  180. // FmtNumber returns 'num' with digits/precision of 'v' for 'ta' and handles both Whole and Real numbers based on 'v'
  181. func (ta *ta) 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, ta.decimal[0])
  192. inWhole = true
  193. continue
  194. }
  195. if inWhole {
  196. if count == groupThreshold {
  197. b = append(b, ta.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, ta.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 'ta' 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 (ta *ta) 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, ta.decimal[0])
  227. continue
  228. }
  229. b = append(b, s[i])
  230. }
  231. if num < 0 {
  232. b = append(b, ta.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, ta.percent...)
  239. return string(b)
  240. }
  241. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ta'
  242. func (ta *ta) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  243. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  244. symbol := ta.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. b := make([]byte, 0, l)
  249. for i := len(s) - 1; i >= 0; i-- {
  250. if s[i] == '.' {
  251. b = append(b, ta.decimal[0])
  252. inWhole = true
  253. continue
  254. }
  255. if inWhole {
  256. if count == 3 {
  257. b = append(b, ta.group[0])
  258. count = 1
  259. } else {
  260. count++
  261. }
  262. }
  263. b = append(b, s[i])
  264. }
  265. for j := len(symbol) - 1; j >= 0; j-- {
  266. b = append(b, symbol[j])
  267. }
  268. if num < 0 {
  269. b = append(b, ta.minus[0])
  270. }
  271. // reverse
  272. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  273. b[i], b[j] = b[j], b[i]
  274. }
  275. if int(v) < 2 {
  276. if v == 0 {
  277. b = append(b, ta.decimal...)
  278. }
  279. for i := 0; i < 2-int(v); i++ {
  280. b = append(b, '0')
  281. }
  282. }
  283. return string(b)
  284. }
  285. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ta'
  286. // in accounting notation.
  287. func (ta *ta) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  288. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  289. symbol := ta.currencies[currency]
  290. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  291. count := 0
  292. inWhole := v == 0
  293. b := make([]byte, 0, l)
  294. for i := len(s) - 1; i >= 0; i-- {
  295. if s[i] == '.' {
  296. b = append(b, ta.decimal[0])
  297. inWhole = true
  298. continue
  299. }
  300. if inWhole {
  301. if count == 3 {
  302. b = append(b, ta.group[0])
  303. count = 1
  304. } else {
  305. count++
  306. }
  307. }
  308. b = append(b, s[i])
  309. }
  310. if num < 0 {
  311. for j := len(symbol) - 1; j >= 0; j-- {
  312. b = append(b, symbol[j])
  313. }
  314. b = append(b, ta.currencyNegativePrefix[0])
  315. } else {
  316. for j := len(symbol) - 1; j >= 0; j-- {
  317. b = append(b, symbol[j])
  318. }
  319. }
  320. // reverse
  321. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  322. b[i], b[j] = b[j], b[i]
  323. }
  324. if int(v) < 2 {
  325. if v == 0 {
  326. b = append(b, ta.decimal...)
  327. }
  328. for i := 0; i < 2-int(v); i++ {
  329. b = append(b, '0')
  330. }
  331. }
  332. if num < 0 {
  333. b = append(b, ta.currencyNegativeSuffix...)
  334. }
  335. return string(b)
  336. }
  337. // FmtDateShort returns the short date representation of 't' for 'ta'
  338. func (ta *ta) FmtDateShort(t time.Time) string {
  339. b := make([]byte, 0, 32)
  340. b = strconv.AppendInt(b, int64(t.Day()), 10)
  341. b = append(b, []byte{0x2f}...)
  342. b = strconv.AppendInt(b, int64(t.Month()), 10)
  343. b = append(b, []byte{0x2f}...)
  344. if t.Year() > 9 {
  345. b = append(b, strconv.Itoa(t.Year())[2:]...)
  346. } else {
  347. b = append(b, strconv.Itoa(t.Year())[1:]...)
  348. }
  349. return string(b)
  350. }
  351. // FmtDateMedium returns the medium date representation of 't' for 'ta'
  352. func (ta *ta) FmtDateMedium(t time.Time) string {
  353. b := make([]byte, 0, 32)
  354. b = strconv.AppendInt(b, int64(t.Day()), 10)
  355. b = append(b, []byte{0x20}...)
  356. b = append(b, ta.monthsAbbreviated[t.Month()]...)
  357. b = append(b, []byte{0x2c, 0x20}...)
  358. if t.Year() > 0 {
  359. b = strconv.AppendInt(b, int64(t.Year()), 10)
  360. } else {
  361. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  362. }
  363. return string(b)
  364. }
  365. // FmtDateLong returns the long date representation of 't' for 'ta'
  366. func (ta *ta) FmtDateLong(t time.Time) string {
  367. b := make([]byte, 0, 32)
  368. b = strconv.AppendInt(b, int64(t.Day()), 10)
  369. b = append(b, []byte{0x20}...)
  370. b = append(b, ta.monthsWide[t.Month()]...)
  371. b = append(b, []byte{0x2c, 0x20}...)
  372. if t.Year() > 0 {
  373. b = strconv.AppendInt(b, int64(t.Year()), 10)
  374. } else {
  375. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  376. }
  377. return string(b)
  378. }
  379. // FmtDateFull returns the full date representation of 't' for 'ta'
  380. func (ta *ta) FmtDateFull(t time.Time) string {
  381. b := make([]byte, 0, 32)
  382. b = append(b, ta.daysWide[t.Weekday()]...)
  383. b = append(b, []byte{0x2c, 0x20}...)
  384. b = strconv.AppendInt(b, int64(t.Day()), 10)
  385. b = append(b, []byte{0x20}...)
  386. b = append(b, ta.monthsWide[t.Month()]...)
  387. b = append(b, []byte{0x2c, 0x20}...)
  388. if t.Year() > 0 {
  389. b = strconv.AppendInt(b, int64(t.Year()), 10)
  390. } else {
  391. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  392. }
  393. return string(b)
  394. }
  395. // FmtTimeShort returns the short time representation of 't' for 'ta'
  396. func (ta *ta) FmtTimeShort(t time.Time) string {
  397. b := make([]byte, 0, 32)
  398. if t.Hour() < 12 {
  399. b = append(b, ta.periodsAbbreviated[0]...)
  400. } else {
  401. b = append(b, ta.periodsAbbreviated[1]...)
  402. }
  403. b = append(b, []byte{0x20}...)
  404. h := t.Hour()
  405. if h > 12 {
  406. h -= 12
  407. }
  408. b = strconv.AppendInt(b, int64(h), 10)
  409. b = append(b, ta.timeSeparator...)
  410. if t.Minute() < 10 {
  411. b = append(b, '0')
  412. }
  413. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  414. return string(b)
  415. }
  416. // FmtTimeMedium returns the medium time representation of 't' for 'ta'
  417. func (ta *ta) FmtTimeMedium(t time.Time) string {
  418. b := make([]byte, 0, 32)
  419. if t.Hour() < 12 {
  420. b = append(b, ta.periodsAbbreviated[0]...)
  421. } else {
  422. b = append(b, ta.periodsAbbreviated[1]...)
  423. }
  424. b = append(b, []byte{0x20}...)
  425. h := t.Hour()
  426. if h > 12 {
  427. h -= 12
  428. }
  429. b = strconv.AppendInt(b, int64(h), 10)
  430. b = append(b, ta.timeSeparator...)
  431. if t.Minute() < 10 {
  432. b = append(b, '0')
  433. }
  434. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  435. b = append(b, ta.timeSeparator...)
  436. if t.Second() < 10 {
  437. b = append(b, '0')
  438. }
  439. b = strconv.AppendInt(b, int64(t.Second()), 10)
  440. return string(b)
  441. }
  442. // FmtTimeLong returns the long time representation of 't' for 'ta'
  443. func (ta *ta) FmtTimeLong(t time.Time) string {
  444. b := make([]byte, 0, 32)
  445. if t.Hour() < 12 {
  446. b = append(b, ta.periodsAbbreviated[0]...)
  447. } else {
  448. b = append(b, ta.periodsAbbreviated[1]...)
  449. }
  450. b = append(b, []byte{0x20}...)
  451. h := t.Hour()
  452. if h > 12 {
  453. h -= 12
  454. }
  455. b = strconv.AppendInt(b, int64(h), 10)
  456. b = append(b, ta.timeSeparator...)
  457. if t.Minute() < 10 {
  458. b = append(b, '0')
  459. }
  460. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  461. b = append(b, ta.timeSeparator...)
  462. if t.Second() < 10 {
  463. b = append(b, '0')
  464. }
  465. b = strconv.AppendInt(b, int64(t.Second()), 10)
  466. b = append(b, []byte{0x20}...)
  467. tz, _ := t.Zone()
  468. b = append(b, tz...)
  469. return string(b)
  470. }
  471. // FmtTimeFull returns the full time representation of 't' for 'ta'
  472. func (ta *ta) FmtTimeFull(t time.Time) string {
  473. b := make([]byte, 0, 32)
  474. if t.Hour() < 12 {
  475. b = append(b, ta.periodsAbbreviated[0]...)
  476. } else {
  477. b = append(b, ta.periodsAbbreviated[1]...)
  478. }
  479. b = append(b, []byte{0x20}...)
  480. h := t.Hour()
  481. if h > 12 {
  482. h -= 12
  483. }
  484. b = strconv.AppendInt(b, int64(h), 10)
  485. b = append(b, ta.timeSeparator...)
  486. if t.Minute() < 10 {
  487. b = append(b, '0')
  488. }
  489. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  490. b = append(b, ta.timeSeparator...)
  491. if t.Second() < 10 {
  492. b = append(b, '0')
  493. }
  494. b = strconv.AppendInt(b, int64(t.Second()), 10)
  495. b = append(b, []byte{0x20}...)
  496. tz, _ := t.Zone()
  497. if btz, ok := ta.timezones[tz]; ok {
  498. b = append(b, btz...)
  499. } else {
  500. b = append(b, tz...)
  501. }
  502. return string(b)
  503. }