lt.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. package lt
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type lt 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. percentSuffix string
  19. perMille string
  20. timeSeparator string
  21. inifinity string
  22. currencies []string // idx = enum of currency code
  23. currencyPositiveSuffix string
  24. currencyNegativeSuffix string
  25. monthsAbbreviated []string
  26. monthsNarrow []string
  27. monthsWide []string
  28. daysAbbreviated []string
  29. daysNarrow []string
  30. daysShort []string
  31. daysWide []string
  32. periodsAbbreviated []string
  33. periodsNarrow []string
  34. periodsShort []string
  35. periodsWide []string
  36. erasAbbreviated []string
  37. erasNarrow []string
  38. erasWide []string
  39. timezones map[string]string
  40. }
  41. // New returns a new instance of translator for the 'lt' locale
  42. func New() locales.Translator {
  43. return &lt{
  44. locale: "lt",
  45. pluralsCardinal: []locales.PluralRule{2, 4, 5, 6},
  46. pluralsOrdinal: []locales.PluralRule{6},
  47. pluralsRange: []locales.PluralRule{2, 4, 5, 6},
  48. decimal: ",",
  49. group: " ",
  50. minus: "−",
  51. percent: "%",
  52. perMille: "‰",
  53. timeSeparator: ":",
  54. inifinity: "∞",
  55. currencies: []string{"ADP ", "AED", "AFA ", "AFN", "ALK ", "ALL", "AMD", "ANG", "AOA", "AOK ", "AON ", "AOR ", "ARA ", "ARL ", "ARM ", "ARP ", "ARS", "ATS ", "AUD", "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 ", "BRL", "BRN ", "BRR ", "BRZ ", "BSD", "BTN", "BUK ", "BWP", "BYB ", "BYR", "BZD", "CAD", "CDF", "CHE ", "CHF", "CHW ", "CLE ", "CLF ", "CLP", "CNX ", "CNY", "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 ", "GBP", "GEK ", "GEL", "GHC ", "GHS", "GIP", "GMD", "GNF", "GNS ", "GQE ", "GRD ", "GTQ", "GWE ", "GWP ", "GYD", "HKD", "HNL", "HRD ", "HRK", "HTG", "HUF", "IDR", "IEP ", "ILP ", "ILR ", "ILS", "INR", "IQD", "IRR", "ISJ ", "ISK", "ITL ", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH ", "KRO ", "KRW", "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", "MXN", "MXP ", "MXV ", "MYR", "MZE ", "MZM ", "MZN", "NAD", "NGN", "NIC ", "NIO", "NLG ", "NOK", "NPR", "NZD", "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", "SUR ", "SVC ", "SYP", "SZL", "THB", "TJR ", "TJS", "TMM ", "TMT", "TND", "TOP", "TPE ", "TRL ", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK ", "UGS ", "UGX", "USD", "USN ", "USS ", "UYI ", "UYP ", "UYU", "UZS", "VEB ", "VEF", "VND", "VNN ", "VUV", "WST", "XAF", "XAG ", "XAU ", "XBA ", "XBB ", "XBC ", "XBD ", "XCD", "XDR ", "XEU ", "XFO ", "XFU ", "XOF", "XPD ", "XPF", "XPT ", "XRE ", "XSU ", "XTS ", "XUA ", "XXX ", "YDD ", "YER", "YUD ", "YUM ", "YUN ", "YUR ", "ZAL ", "ZAR", "ZMK ", "ZMW", "ZRN ", "ZRZ ", "ZWD ", "ZWL ", "ZWR "},
  56. percentSuffix: " ",
  57. currencyPositiveSuffix: " ",
  58. currencyNegativeSuffix: " ",
  59. monthsAbbreviated: []string{"", "saus.", "vas.", "kov.", "bal.", "geg.", "birž.", "liep.", "rugp.", "rugs.", "spal.", "lapkr.", "gruod."},
  60. monthsNarrow: []string{"", "S", "V", "K", "B", "G", "B", "L", "R", "R", "S", "L", "G"},
  61. monthsWide: []string{"", "sausio", "vasario", "kovo", "balandžio", "gegužės", "birželio", "liepos", "rugpjūčio", "rugsėjo", "spalio", "lapkričio", "gruodžio"},
  62. daysAbbreviated: []string{"sk", "pr", "an", "tr", "kt", "pn", "št"},
  63. daysNarrow: []string{"S", "P", "A", "T", "K", "P", "Š"},
  64. daysShort: []string{"Sk", "Pr", "An", "Tr", "Kt", "Pn", "Št"},
  65. daysWide: []string{"sekmadienis", "pirmadienis", "antradienis", "trečiadienis", "ketvirtadienis", "penktadienis", "šeštadienis"},
  66. periodsAbbreviated: []string{"priešpiet", "popiet"},
  67. periodsNarrow: []string{"pr. p.", "pop."},
  68. periodsWide: []string{"priešpiet", "popiet"},
  69. erasAbbreviated: []string{"pr. Kr.", "po Kr."},
  70. erasNarrow: []string{"pr. Kr.", "po Kr."},
  71. erasWide: []string{"prieš Kristų", "po Kristaus"},
  72. timezones: map[string]string{"AEDT": "Rytų Australijos vasaros laikas", "MST": "Makau žiemos laikas", "HADT": "Havajų–Aleutų vasaros laikas", "WART": "Vakarų Argentinos žiemos laikas", "ACDT": "Centrinės Australijos vasaros laikas", "ChST": "Čamoro laikas", "WAST": "Vakarų Afrikos vasaros laikas", "AST": "Atlanto žiemos laikas", "GFT": "Prancūzijos Gvianos laikas", "TMST": "Turkmėnistano vasaros laikas", "AKST": "Aliaskos žiemos laikas", "CDT": "Šiaurės Amerikos centro vasaros laikas", "VET": "Venesuelos laikas", "WEZ": "Vakarų Europos žiemos laikas", "HKT": "Honkongo žiemos laikas", "HKST": "Honkongo vasaros laikas", "HNT": "Niufaundlendo žiemos laikas", "WIB": "Vakarų Indonezijos laikas", "AWST": "Vakarų Australijos žiemos laikas", "AKDT": "Aliaskos vasaros laikas", "WESZ": "Vakarų Europos vasaros laikas", "SGT": "Singapūro laikas", "OEZ": "Rytų Europos žiemos laikas", "WIT": "Rytų Indonezijos laikas", "LHST": "Lordo Hau žiemos laikas", "GYT": "Gajanos laikas", "NZDT": "Naujosios Zelandijos vasaros laikas", "UYST": "Urugvajaus vasaros laikas", "MEZ": "Vidurio Europos žiemos laikas", "CST": "Šiaurės Amerikos centro žiemos laikas", "CHAST": "Čatamo žiemos laikas", "HAT": "Niufaundlendo vasaros laikas", "IST": "Indijos laikas", "ACST": "Centrinės Australijos žiemos laikas", "EAT": "Rytų Afrikos laikas", "COST": "Kolumbijos vasaros laikas", "HAST": "Havajų–Aleutų žiemos laikas", "CAT": "Centrinės Afrikos laikas", "SAST": "Pietų Afrikos laikas", "NZST": "Naujosios Zelandijos žiemos laikas", "EDT": "Šiaurės Amerikos rytų vasaros laikas", "MDT": "Makau vasaros laikas", "TMT": "Turkmėnistano žiemos laikas", "LHDT": "Lordo Hau vasaros laikas", "JDT": "Japonijos vasaros laikas", "SRT": "Surinamo laikas", "MESZ": "Vidurio Europos vasaros laikas", "BT": "Butano laikas", "WARST": "Vakarų Argentinos vasaros laikas", "GMT": "Grinvičo laikas", "ART": "Argentinos žiemos laikas", "CLT": "Čilės žiemos laikas", "CLST": "Čilės vasaros laikas", "∅∅∅": "Amazonės vasaros laikas", "ACWDT": "Centrinės vakarų Australijos vasaros laikas", "OESZ": "Rytų Europos vasaros laikas", "PST": "Šiaurės Amerikos Ramiojo vandenyno žiemos laikas", "COT": "Kolumbijos žiemos laikas", "WITA": "Centrinės Indonezijos laikas", "ARST": "Argentinos vasaros laikas", "AWDT": "Vakarų Australijos vasaros laikas", "MYT": "Malaizijos laikas", "EST": "Šiaurės Amerikos rytų žiemos laikas", "PDT": "Šiaurės Amerikos Ramiojo vandenyno vasaros laikas", "UYT": "Urugvajaus žiemos laikas", "AEST": "Rytų Australijos žiemos laikas", "CHADT": "Čatamo vasaros laikas", "ECT": "Ekvadoro laikas", "JST": "Japonijos žiemos laikas", "BOT": "Bolivijos laikas", "ACWST": "Centrinės vakarų Australijos žiemos laikas", "ADT": "Atlanto vasaros laikas", "WAT": "Vakarų Afrikos žiemos laikas"},
  73. }
  74. }
  75. // Locale returns the current translators string locale
  76. func (lt *lt) Locale() string {
  77. return lt.locale
  78. }
  79. // PluralsCardinal returns the list of cardinal plural rules associated with 'lt'
  80. func (lt *lt) PluralsCardinal() []locales.PluralRule {
  81. return lt.pluralsCardinal
  82. }
  83. // PluralsOrdinal returns the list of ordinal plural rules associated with 'lt'
  84. func (lt *lt) PluralsOrdinal() []locales.PluralRule {
  85. return lt.pluralsOrdinal
  86. }
  87. // PluralsRange returns the list of range plural rules associated with 'lt'
  88. func (lt *lt) PluralsRange() []locales.PluralRule {
  89. return lt.pluralsRange
  90. }
  91. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'lt'
  92. func (lt *lt) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. n := math.Abs(num)
  94. f := locales.F(n, v)
  95. nMod100 := math.Mod(n, 100)
  96. nMod10 := math.Mod(n, 10)
  97. if nMod10 == 1 && nMod100 < 11 && nMod100 > 19 {
  98. return locales.PluralRuleOne
  99. } else if nMod10 >= 2 && nMod10 <= 9 && nMod100 < 11 && nMod100 > 19 {
  100. return locales.PluralRuleFew
  101. } else if f != 0 {
  102. return locales.PluralRuleMany
  103. }
  104. return locales.PluralRuleOther
  105. }
  106. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'lt'
  107. func (lt *lt) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  108. return locales.PluralRuleOther
  109. }
  110. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'lt'
  111. func (lt *lt) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  112. start := lt.CardinalPluralRule(num1, v1)
  113. end := lt.CardinalPluralRule(num2, v2)
  114. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  115. return locales.PluralRuleOne
  116. } else if start == locales.PluralRuleOne && end == locales.PluralRuleFew {
  117. return locales.PluralRuleFew
  118. } else if start == locales.PluralRuleOne && end == locales.PluralRuleMany {
  119. return locales.PluralRuleMany
  120. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  121. return locales.PluralRuleOther
  122. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOne {
  123. return locales.PluralRuleOne
  124. } else if start == locales.PluralRuleFew && end == locales.PluralRuleFew {
  125. return locales.PluralRuleFew
  126. } else if start == locales.PluralRuleFew && end == locales.PluralRuleMany {
  127. return locales.PluralRuleMany
  128. } else if start == locales.PluralRuleFew && end == locales.PluralRuleOther {
  129. return locales.PluralRuleOther
  130. } else if start == locales.PluralRuleMany && end == locales.PluralRuleOne {
  131. return locales.PluralRuleOne
  132. } else if start == locales.PluralRuleMany && end == locales.PluralRuleFew {
  133. return locales.PluralRuleFew
  134. } else if start == locales.PluralRuleMany && end == locales.PluralRuleMany {
  135. return locales.PluralRuleMany
  136. } else if start == locales.PluralRuleMany && end == locales.PluralRuleOther {
  137. return locales.PluralRuleOther
  138. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  139. return locales.PluralRuleOne
  140. } else if start == locales.PluralRuleOther && end == locales.PluralRuleFew {
  141. return locales.PluralRuleFew
  142. } else if start == locales.PluralRuleOther && end == locales.PluralRuleMany {
  143. return locales.PluralRuleMany
  144. }
  145. return locales.PluralRuleOther
  146. }
  147. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  148. func (lt *lt) MonthAbbreviated(month time.Month) string {
  149. return lt.monthsAbbreviated[month]
  150. }
  151. // MonthsAbbreviated returns the locales abbreviated months
  152. func (lt *lt) MonthsAbbreviated() []string {
  153. return lt.monthsAbbreviated[1:]
  154. }
  155. // MonthNarrow returns the locales narrow month given the 'month' provided
  156. func (lt *lt) MonthNarrow(month time.Month) string {
  157. return lt.monthsNarrow[month]
  158. }
  159. // MonthsNarrow returns the locales narrow months
  160. func (lt *lt) MonthsNarrow() []string {
  161. return lt.monthsNarrow[1:]
  162. }
  163. // MonthWide returns the locales wide month given the 'month' provided
  164. func (lt *lt) MonthWide(month time.Month) string {
  165. return lt.monthsWide[month]
  166. }
  167. // MonthsWide returns the locales wide months
  168. func (lt *lt) MonthsWide() []string {
  169. return lt.monthsWide[1:]
  170. }
  171. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  172. func (lt *lt) WeekdayAbbreviated(weekday time.Weekday) string {
  173. return lt.daysAbbreviated[weekday]
  174. }
  175. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  176. func (lt *lt) WeekdaysAbbreviated() []string {
  177. return lt.daysAbbreviated
  178. }
  179. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  180. func (lt *lt) WeekdayNarrow(weekday time.Weekday) string {
  181. return lt.daysNarrow[weekday]
  182. }
  183. // WeekdaysNarrow returns the locales narrow weekdays
  184. func (lt *lt) WeekdaysNarrow() []string {
  185. return lt.daysNarrow
  186. }
  187. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  188. func (lt *lt) WeekdayShort(weekday time.Weekday) string {
  189. return lt.daysShort[weekday]
  190. }
  191. // WeekdaysShort returns the locales short weekdays
  192. func (lt *lt) WeekdaysShort() []string {
  193. return lt.daysShort
  194. }
  195. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  196. func (lt *lt) WeekdayWide(weekday time.Weekday) string {
  197. return lt.daysWide[weekday]
  198. }
  199. // WeekdaysWide returns the locales wide weekdays
  200. func (lt *lt) WeekdaysWide() []string {
  201. return lt.daysWide
  202. }
  203. // FmtNumber returns 'num' with digits/precision of 'v' for 'lt' and handles both Whole and Real numbers based on 'v'
  204. func (lt *lt) FmtNumber(num float64, v uint64) string {
  205. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  206. l := len(s) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  207. count := 0
  208. inWhole := v == 0
  209. b := make([]byte, 0, l)
  210. for i := len(s) - 1; i >= 0; i-- {
  211. if s[i] == '.' {
  212. b = append(b, lt.decimal[0])
  213. inWhole = true
  214. continue
  215. }
  216. if inWhole {
  217. if count == 3 {
  218. for j := len(lt.group) - 1; j >= 0; j-- {
  219. b = append(b, lt.group[j])
  220. }
  221. count = 1
  222. } else {
  223. count++
  224. }
  225. }
  226. b = append(b, s[i])
  227. }
  228. if num < 0 {
  229. for j := len(lt.minus) - 1; j >= 0; j-- {
  230. b = append(b, lt.minus[j])
  231. }
  232. }
  233. // reverse
  234. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  235. b[i], b[j] = b[j], b[i]
  236. }
  237. return string(b)
  238. }
  239. // FmtPercent returns 'num' with digits/precision of 'v' for 'lt' and handles both Whole and Real numbers based on 'v'
  240. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  241. func (lt *lt) FmtPercent(num float64, v uint64) string {
  242. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  243. l := len(s) + 7
  244. b := make([]byte, 0, l)
  245. for i := len(s) - 1; i >= 0; i-- {
  246. if s[i] == '.' {
  247. b = append(b, lt.decimal[0])
  248. continue
  249. }
  250. b = append(b, s[i])
  251. }
  252. if num < 0 {
  253. for j := len(lt.minus) - 1; j >= 0; j-- {
  254. b = append(b, lt.minus[j])
  255. }
  256. }
  257. // reverse
  258. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  259. b[i], b[j] = b[j], b[i]
  260. }
  261. b = append(b, lt.percentSuffix...)
  262. b = append(b, lt.percent...)
  263. return string(b)
  264. }
  265. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'lt'
  266. func (lt *lt) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  267. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  268. symbol := lt.currencies[currency]
  269. l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
  270. count := 0
  271. inWhole := v == 0
  272. b := make([]byte, 0, l)
  273. for i := len(s) - 1; i >= 0; i-- {
  274. if s[i] == '.' {
  275. b = append(b, lt.decimal[0])
  276. inWhole = true
  277. continue
  278. }
  279. if inWhole {
  280. if count == 3 {
  281. for j := len(lt.group) - 1; j >= 0; j-- {
  282. b = append(b, lt.group[j])
  283. }
  284. count = 1
  285. } else {
  286. count++
  287. }
  288. }
  289. b = append(b, s[i])
  290. }
  291. if num < 0 {
  292. for j := len(lt.minus) - 1; j >= 0; j-- {
  293. b = append(b, lt.minus[j])
  294. }
  295. }
  296. // reverse
  297. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  298. b[i], b[j] = b[j], b[i]
  299. }
  300. if int(v) < 2 {
  301. if v == 0 {
  302. b = append(b, lt.decimal...)
  303. }
  304. for i := 0; i < 2-int(v); i++ {
  305. b = append(b, '0')
  306. }
  307. }
  308. b = append(b, lt.currencyPositiveSuffix...)
  309. b = append(b, symbol...)
  310. return string(b)
  311. }
  312. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'lt'
  313. // in accounting notation.
  314. func (lt *lt) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  315. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  316. symbol := lt.currencies[currency]
  317. l := len(s) + len(symbol) + 6 + 2*len(s[:len(s)-int(v)-1])/3
  318. count := 0
  319. inWhole := v == 0
  320. b := make([]byte, 0, l)
  321. for i := len(s) - 1; i >= 0; i-- {
  322. if s[i] == '.' {
  323. b = append(b, lt.decimal[0])
  324. inWhole = true
  325. continue
  326. }
  327. if inWhole {
  328. if count == 3 {
  329. for j := len(lt.group) - 1; j >= 0; j-- {
  330. b = append(b, lt.group[j])
  331. }
  332. count = 1
  333. } else {
  334. count++
  335. }
  336. }
  337. b = append(b, s[i])
  338. }
  339. if num < 0 {
  340. for j := len(lt.minus) - 1; j >= 0; j-- {
  341. b = append(b, lt.minus[j])
  342. }
  343. }
  344. // reverse
  345. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  346. b[i], b[j] = b[j], b[i]
  347. }
  348. if int(v) < 2 {
  349. if v == 0 {
  350. b = append(b, lt.decimal...)
  351. }
  352. for i := 0; i < 2-int(v); i++ {
  353. b = append(b, '0')
  354. }
  355. }
  356. if num < 0 {
  357. b = append(b, lt.currencyNegativeSuffix...)
  358. b = append(b, symbol...)
  359. } else {
  360. b = append(b, lt.currencyPositiveSuffix...)
  361. b = append(b, symbol...)
  362. }
  363. return string(b)
  364. }
  365. // FmtDateShort returns the short date representation of 't' for 'lt'
  366. func (lt *lt) FmtDateShort(t time.Time) string {
  367. b := make([]byte, 0, 32)
  368. b = strconv.AppendInt(b, int64(t.Year()), 10)
  369. b = append(b, []byte{0x2d}...)
  370. if t.Month() < 10 {
  371. b = append(b, '0')
  372. }
  373. b = strconv.AppendInt(b, int64(t.Month()), 10)
  374. b = append(b, []byte{0x2d}...)
  375. if t.Day() < 10 {
  376. b = append(b, '0')
  377. }
  378. b = strconv.AppendInt(b, int64(t.Day()), 10)
  379. return string(b)
  380. }
  381. // FmtDateMedium returns the medium date representation of 't' for 'lt'
  382. func (lt *lt) FmtDateMedium(t time.Time) string {
  383. b := make([]byte, 0, 32)
  384. b = strconv.AppendInt(b, int64(t.Year()), 10)
  385. b = append(b, []byte{0x2d}...)
  386. if t.Month() < 10 {
  387. b = append(b, '0')
  388. }
  389. b = strconv.AppendInt(b, int64(t.Month()), 10)
  390. b = append(b, []byte{0x2d}...)
  391. if t.Day() < 10 {
  392. b = append(b, '0')
  393. }
  394. b = strconv.AppendInt(b, int64(t.Day()), 10)
  395. return string(b)
  396. }
  397. // FmtDateLong returns the long date representation of 't' for 'lt'
  398. func (lt *lt) FmtDateLong(t time.Time) string {
  399. b := make([]byte, 0, 32)
  400. b = strconv.AppendInt(b, int64(t.Year()), 10)
  401. b = append(b, []byte{}...)
  402. b = append(b, []byte{0x27, 0x6d, 0x27, 0x2e, 0x20}...)
  403. b = append(b, lt.monthsWide[t.Month()]...)
  404. b = append(b, []byte{0x20}...)
  405. b = strconv.AppendInt(b, int64(t.Day()), 10)
  406. b = append(b, []byte{}...)
  407. b = append(b, []byte{0x27, 0x64, 0x27, 0x2e}...)
  408. return string(b)
  409. }
  410. // FmtDateFull returns the full date representation of 't' for 'lt'
  411. func (lt *lt) FmtDateFull(t time.Time) string {
  412. b := make([]byte, 0, 32)
  413. b = strconv.AppendInt(b, int64(t.Year()), 10)
  414. b = append(b, []byte{}...)
  415. b = append(b, []byte{0x27, 0x6d, 0x27, 0x2e, 0x20}...)
  416. b = append(b, lt.monthsWide[t.Month()]...)
  417. b = append(b, []byte{0x20}...)
  418. b = strconv.AppendInt(b, int64(t.Day()), 10)
  419. b = append(b, []byte{}...)
  420. b = append(b, []byte{0x27, 0x64, 0x27, 0x2e, 0x2c, 0x20}...)
  421. b = append(b, lt.daysWide[t.Weekday()]...)
  422. return string(b)
  423. }
  424. // FmtTimeShort returns the short time representation of 't' for 'lt'
  425. func (lt *lt) FmtTimeShort(t time.Time) string {
  426. b := make([]byte, 0, 32)
  427. if t.Hour() < 10 {
  428. b = append(b, '0')
  429. }
  430. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  431. b = append(b, lt.timeSeparator...)
  432. if t.Minute() < 10 {
  433. b = append(b, '0')
  434. }
  435. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  436. return string(b)
  437. }
  438. // FmtTimeMedium returns the medium time representation of 't' for 'lt'
  439. func (lt *lt) FmtTimeMedium(t time.Time) string {
  440. b := make([]byte, 0, 32)
  441. if t.Hour() < 10 {
  442. b = append(b, '0')
  443. }
  444. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  445. b = append(b, lt.timeSeparator...)
  446. if t.Minute() < 10 {
  447. b = append(b, '0')
  448. }
  449. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  450. b = append(b, lt.timeSeparator...)
  451. if t.Second() < 10 {
  452. b = append(b, '0')
  453. }
  454. b = strconv.AppendInt(b, int64(t.Second()), 10)
  455. return string(b)
  456. }
  457. // FmtTimeLong returns the long time representation of 't' for 'lt'
  458. func (lt *lt) FmtTimeLong(t time.Time) string {
  459. b := make([]byte, 0, 32)
  460. if t.Hour() < 10 {
  461. b = append(b, '0')
  462. }
  463. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  464. b = append(b, lt.timeSeparator...)
  465. if t.Minute() < 10 {
  466. b = append(b, '0')
  467. }
  468. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  469. b = append(b, lt.timeSeparator...)
  470. if t.Second() < 10 {
  471. b = append(b, '0')
  472. }
  473. b = strconv.AppendInt(b, int64(t.Second()), 10)
  474. b = append(b, []byte{0x20}...)
  475. tz, _ := t.Zone()
  476. b = append(b, tz...)
  477. return string(b)
  478. }
  479. // FmtTimeFull returns the full time representation of 't' for 'lt'
  480. func (lt *lt) FmtTimeFull(t time.Time) string {
  481. b := make([]byte, 0, 32)
  482. if t.Hour() < 10 {
  483. b = append(b, '0')
  484. }
  485. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  486. b = append(b, lt.timeSeparator...)
  487. if t.Minute() < 10 {
  488. b = append(b, '0')
  489. }
  490. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  491. b = append(b, lt.timeSeparator...)
  492. if t.Second() < 10 {
  493. b = append(b, '0')
  494. }
  495. b = strconv.AppendInt(b, int64(t.Second()), 10)
  496. b = append(b, []byte{0x20}...)
  497. tz, _ := t.Zone()
  498. if btz, ok := lt.timezones[tz]; ok {
  499. b = append(b, btz...)
  500. } else {
  501. b = append(b, tz...)
  502. }
  503. return string(b)
  504. }