lv.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. package lv
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type lv 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. currencyPositiveSuffix 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 'lv' locale
  41. func New() locales.Translator {
  42. return &lv{
  43. locale: "lv",
  44. pluralsCardinal: []locales.PluralRule{1, 2, 6},
  45. pluralsOrdinal: []locales.PluralRule{6},
  46. pluralsRange: []locales.PluralRule{6, 2},
  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 ", "AU$", "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 ", "BYR", "BZD", "CA$", "CDF", "CHE ", "CHF", "CHW ", "CLE ", "CLF ", "CLP", "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 ", "Ls", "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", "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. currencyPositiveSuffix: " ",
  56. currencyNegativeSuffix: " ",
  57. monthsAbbreviated: []string{"", "janv.", "febr.", "marts", "apr.", "maijs", "jūn.", "jūl.", "aug.", "sept.", "okt.", "nov.", "dec."},
  58. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  59. monthsWide: []string{"", "janvāris", "februāris", "marts", "aprīlis", "maijs", "jūnijs", "jūlijs", "augusts", "septembris", "oktobris", "novembris", "decembris"},
  60. daysAbbreviated: []string{"Sv", "Pr", "Ot", "Tr", "Ce", "Pk", "Se"},
  61. daysNarrow: []string{"S", "P", "O", "T", "C", "P", "S"},
  62. daysShort: []string{"Sv", "Pr", "Ot", "Tr", "Ce", "Pk", "Se"},
  63. daysWide: []string{"svētdiena", "pirmdiena", "otrdiena", "trešdiena", "ceturtdiena", "piektdiena", "sestdiena"},
  64. periodsAbbreviated: []string{"priekšp.", "pēcp."},
  65. periodsNarrow: []string{"priekšp.", "pēcp."},
  66. periodsWide: []string{"priekšpusdienā", "pēcpusdienā"},
  67. erasAbbreviated: []string{"p.m.ē.", "m.ē."},
  68. erasNarrow: []string{"p.m.ē.", "m.ē."},
  69. erasWide: []string{"pirms mūsu ēras", "mūsu ērā"},
  70. timezones: map[string]string{"AWST": "Austrālijas rietumu ziemas laiks", "MEZ": "Centrāleiropas ziemas laiks", "ChST": "Čamoro standarta laiks", "SAST": "Dienvidāfrikas ziemas laiks", "OEZ": "Austrumeiropas ziemas laiks", "OESZ": "Austrumeiropas vasaras laiks", "LHDT": "Lorda Hava salas vasaras laiks", "COST": "Kolumbijas vasaras laiks", "AST": "Atlantijas ziemas laiks", "HKT": "Honkongas ziemas laiks", "WAST": "Rietumāfrikas vasaras laiks", "MESZ": "Centrāleiropas vasaras laiks", "NZDT": "Jaunzēlandes vasaras laiks", "ECT": "Ekvadoras laiks", "CDT": "Centrālais vasaras laiks", "CHADT": "Četemas vasaras laiks", "ACST": "Austrālijas centrālais ziemas laiks", "AKST": "Aļaskas ziemas laiks", "PST": "Klusā okeāna ziemas laiks", "CAT": "Centrālāfrikas laiks", "EDT": "Austrumu vasaras laiks", "HAST": "Havaju–Aleutu ziemas laiks", "IST": "Indijas ziemas laiks", "GYT": "Gajānas laiks", "MYT": "Malaizijas laiks", "CLT": "Čīles ziemas laiks", "CLST": "Čīles vasaras laiks", "UYT": "Urugvajas ziemas laiks", "UYST": "Urugvajas vasaras laiks", "CHAST": "Četemas ziemas laiks", "ACWDT": "Austrālijas centrālais rietumu vasaras laiks", "HNT": "Ņūfaundlendas ziemas laiks", "WIT": "Austrumindonēzijas laiks", "LHST": "Lorda Hava salas ziemas laiks", "CST": "Centrālais ziemas laiks", "NZST": "Jaunzēlandes ziemas laiks", "AEST": "Austrālijas austrumu ziemas laiks", "ADT": "Atlantijas vasaras laiks", "ARST": "Argentīnas vasaras laiks", "ACDT": "Austrālijas centrālais vasaras laiks", "JDT": "Japānas vasaras laiks", "AKDT": "Aļaskas vasaras laiks", "AWDT": "Austrālijas rietumu vasaras laiks", "WARST": "Rietumargentīnas vasaras laiks", "BT": "Butānas laiks", "GMT": "Griničas laiks", "TMST": "Turkmenistānas vasaras laiks", "JST": "Japānas ziemas laiks", "EAT": "Austrumāfrikas laiks", "MDT": "MDT", "HAT": "Ņūfaundlendas vasaras laiks", "GFT": "Franču Gviānas laiks", "WITA": "Centrālindonēzijas laiks", "ACWST": "Austrālijas centrālais rietumu ziemas laiks", "HADT": "Havaju–Aleutu vasaras laiks", "SGT": "Singapūras laiks", "COT": "Kolumbijas ziemas laiks", "HKST": "Honkongas vasaras laiks", "WIB": "Rietumindonēzijas laiks", "TMT": "Turkmenistānas ziemas laiks", "BOT": "Bolīvijas laiks", "∅∅∅": "Amazones vasaras laiks", "WART": "Rietumargentīnas ziemas laiks", "WAT": "Rietumāfrikas ziemas laiks", "ART": "Argentīnas ziemas laiks", "PDT": "Klusā okeāna vasaras laiks", "EST": "Austrumu ziemas laiks", "AEDT": "Austrālijas austrumu vasaras laiks", "MST": "MST", "WESZ": "Rietumeiropas vasaras laiks", "SRT": "Surinamas laiks", "VET": "Venecuēlas laiks", "WEZ": "Rietumeiropas ziemas laiks"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (lv *lv) Locale() string {
  75. return lv.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'lv'
  78. func (lv *lv) PluralsCardinal() []locales.PluralRule {
  79. return lv.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'lv'
  82. func (lv *lv) PluralsOrdinal() []locales.PluralRule {
  83. return lv.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'lv'
  86. func (lv *lv) PluralsRange() []locales.PluralRule {
  87. return lv.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'lv'
  90. func (lv *lv) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. f := locales.F(n, v)
  93. nMod10 := math.Mod(n, 10)
  94. nMod100 := math.Mod(n, 100)
  95. fMod100 := f % 100
  96. fMod10 := f % 10
  97. if (nMod10 == 0) || (nMod100 >= 11 && nMod100 <= 19) || (v == 2 && fMod100 >= 11 && fMod100 <= 19) {
  98. return locales.PluralRuleZero
  99. } else if (nMod10 == 1 && nMod100 != 11) || (v == 2 && fMod10 == 1 && fMod100 != 11) || (v != 2 && fMod10 == 1) {
  100. return locales.PluralRuleOne
  101. }
  102. return locales.PluralRuleOther
  103. }
  104. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'lv'
  105. func (lv *lv) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  106. return locales.PluralRuleOther
  107. }
  108. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'lv'
  109. func (lv *lv) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  110. start := lv.CardinalPluralRule(num1, v1)
  111. end := lv.CardinalPluralRule(num2, v2)
  112. if start == locales.PluralRuleZero && end == locales.PluralRuleZero {
  113. return locales.PluralRuleOther
  114. } else if start == locales.PluralRuleZero && end == locales.PluralRuleOne {
  115. return locales.PluralRuleOne
  116. } else if start == locales.PluralRuleZero && end == locales.PluralRuleOther {
  117. return locales.PluralRuleOther
  118. } else if start == locales.PluralRuleOne && end == locales.PluralRuleZero {
  119. return locales.PluralRuleOther
  120. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  121. return locales.PluralRuleOne
  122. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  123. return locales.PluralRuleOther
  124. } else if start == locales.PluralRuleOther && end == locales.PluralRuleZero {
  125. return locales.PluralRuleOther
  126. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  127. return locales.PluralRuleOne
  128. }
  129. return locales.PluralRuleOther
  130. }
  131. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  132. func (lv *lv) MonthAbbreviated(month time.Month) string {
  133. return lv.monthsAbbreviated[month]
  134. }
  135. // MonthsAbbreviated returns the locales abbreviated months
  136. func (lv *lv) MonthsAbbreviated() []string {
  137. return lv.monthsAbbreviated[1:]
  138. }
  139. // MonthNarrow returns the locales narrow month given the 'month' provided
  140. func (lv *lv) MonthNarrow(month time.Month) string {
  141. return lv.monthsNarrow[month]
  142. }
  143. // MonthsNarrow returns the locales narrow months
  144. func (lv *lv) MonthsNarrow() []string {
  145. return lv.monthsNarrow[1:]
  146. }
  147. // MonthWide returns the locales wide month given the 'month' provided
  148. func (lv *lv) MonthWide(month time.Month) string {
  149. return lv.monthsWide[month]
  150. }
  151. // MonthsWide returns the locales wide months
  152. func (lv *lv) MonthsWide() []string {
  153. return lv.monthsWide[1:]
  154. }
  155. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  156. func (lv *lv) WeekdayAbbreviated(weekday time.Weekday) string {
  157. return lv.daysAbbreviated[weekday]
  158. }
  159. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  160. func (lv *lv) WeekdaysAbbreviated() []string {
  161. return lv.daysAbbreviated
  162. }
  163. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  164. func (lv *lv) WeekdayNarrow(weekday time.Weekday) string {
  165. return lv.daysNarrow[weekday]
  166. }
  167. // WeekdaysNarrow returns the locales narrow weekdays
  168. func (lv *lv) WeekdaysNarrow() []string {
  169. return lv.daysNarrow
  170. }
  171. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  172. func (lv *lv) WeekdayShort(weekday time.Weekday) string {
  173. return lv.daysShort[weekday]
  174. }
  175. // WeekdaysShort returns the locales short weekdays
  176. func (lv *lv) WeekdaysShort() []string {
  177. return lv.daysShort
  178. }
  179. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  180. func (lv *lv) WeekdayWide(weekday time.Weekday) string {
  181. return lv.daysWide[weekday]
  182. }
  183. // WeekdaysWide returns the locales wide weekdays
  184. func (lv *lv) WeekdaysWide() []string {
  185. return lv.daysWide
  186. }
  187. // FmtNumber returns 'num' with digits/precision of 'v' for 'lv' and handles both Whole and Real numbers based on 'v'
  188. func (lv *lv) FmtNumber(num float64, v uint64) string {
  189. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  190. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  191. count := 0
  192. inWhole := v == 0
  193. b := make([]byte, 0, l)
  194. for i := len(s) - 1; i >= 0; i-- {
  195. if s[i] == '.' {
  196. b = append(b, lv.decimal[0])
  197. inWhole = true
  198. continue
  199. }
  200. if inWhole {
  201. if count == 3 {
  202. for j := len(lv.group) - 1; j >= 0; j-- {
  203. b = append(b, lv.group[j])
  204. }
  205. count = 1
  206. } else {
  207. count++
  208. }
  209. }
  210. b = append(b, s[i])
  211. }
  212. if num < 0 {
  213. b = append(b, lv.minus[0])
  214. }
  215. // reverse
  216. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  217. b[i], b[j] = b[j], b[i]
  218. }
  219. return string(b)
  220. }
  221. // FmtPercent returns 'num' with digits/precision of 'v' for 'lv' and handles both Whole and Real numbers based on 'v'
  222. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  223. func (lv *lv) FmtPercent(num float64, v uint64) string {
  224. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  225. l := len(s) + 3
  226. b := make([]byte, 0, l)
  227. for i := len(s) - 1; i >= 0; i-- {
  228. if s[i] == '.' {
  229. b = append(b, lv.decimal[0])
  230. continue
  231. }
  232. b = append(b, s[i])
  233. }
  234. if num < 0 {
  235. b = append(b, lv.minus[0])
  236. }
  237. // reverse
  238. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  239. b[i], b[j] = b[j], b[i]
  240. }
  241. b = append(b, lv.percent...)
  242. return string(b)
  243. }
  244. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'lv'
  245. func (lv *lv) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  246. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  247. symbol := lv.currencies[currency]
  248. l := len(s) + len(symbol) + 4
  249. b := make([]byte, 0, l)
  250. for i := len(s) - 1; i >= 0; i-- {
  251. if s[i] == '.' {
  252. b = append(b, lv.decimal[0])
  253. continue
  254. }
  255. b = append(b, s[i])
  256. }
  257. if num < 0 {
  258. b = append(b, lv.minus[0])
  259. }
  260. // reverse
  261. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  262. b[i], b[j] = b[j], b[i]
  263. }
  264. if int(v) < 2 {
  265. if v == 0 {
  266. b = append(b, lv.decimal...)
  267. }
  268. for i := 0; i < 2-int(v); i++ {
  269. b = append(b, '0')
  270. }
  271. }
  272. b = append(b, lv.currencyPositiveSuffix...)
  273. b = append(b, symbol...)
  274. return string(b)
  275. }
  276. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'lv'
  277. // in accounting notation.
  278. func (lv *lv) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  279. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  280. symbol := lv.currencies[currency]
  281. l := len(s) + len(symbol) + 4
  282. b := make([]byte, 0, l)
  283. for i := len(s) - 1; i >= 0; i-- {
  284. if s[i] == '.' {
  285. b = append(b, lv.decimal[0])
  286. continue
  287. }
  288. b = append(b, s[i])
  289. }
  290. if num < 0 {
  291. b = append(b, lv.minus[0])
  292. }
  293. // reverse
  294. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  295. b[i], b[j] = b[j], b[i]
  296. }
  297. if int(v) < 2 {
  298. if v == 0 {
  299. b = append(b, lv.decimal...)
  300. }
  301. for i := 0; i < 2-int(v); i++ {
  302. b = append(b, '0')
  303. }
  304. }
  305. if num < 0 {
  306. b = append(b, lv.currencyNegativeSuffix...)
  307. b = append(b, symbol...)
  308. } else {
  309. b = append(b, lv.currencyPositiveSuffix...)
  310. b = append(b, symbol...)
  311. }
  312. return string(b)
  313. }
  314. // FmtDateShort returns the short date representation of 't' for 'lv'
  315. func (lv *lv) FmtDateShort(t time.Time) string {
  316. b := make([]byte, 0, 32)
  317. if t.Day() < 10 {
  318. b = append(b, '0')
  319. }
  320. b = strconv.AppendInt(b, int64(t.Day()), 10)
  321. b = append(b, []byte{0x2e}...)
  322. if t.Month() < 10 {
  323. b = append(b, '0')
  324. }
  325. b = strconv.AppendInt(b, int64(t.Month()), 10)
  326. b = append(b, []byte{0x2e}...)
  327. if t.Year() > 9 {
  328. b = append(b, strconv.Itoa(t.Year())[2:]...)
  329. } else {
  330. b = append(b, strconv.Itoa(t.Year())[1:]...)
  331. }
  332. return string(b)
  333. }
  334. // FmtDateMedium returns the medium date representation of 't' for 'lv'
  335. func (lv *lv) FmtDateMedium(t time.Time) string {
  336. b := make([]byte, 0, 32)
  337. b = strconv.AppendInt(b, int64(t.Year()), 10)
  338. b = append(b, []byte{0x2e}...)
  339. b = append(b, []byte{0x27, 0x67, 0x61, 0x64, 0x61, 0x27, 0x20}...)
  340. b = strconv.AppendInt(b, int64(t.Day()), 10)
  341. b = append(b, []byte{0x2e, 0x20}...)
  342. b = append(b, lv.monthsAbbreviated[t.Month()]...)
  343. return string(b)
  344. }
  345. // FmtDateLong returns the long date representation of 't' for 'lv'
  346. func (lv *lv) FmtDateLong(t time.Time) string {
  347. b := make([]byte, 0, 32)
  348. b = strconv.AppendInt(b, int64(t.Year()), 10)
  349. b = append(b, []byte{0x2e}...)
  350. b = append(b, []byte{0x27, 0x67, 0x61, 0x64, 0x61, 0x27, 0x20}...)
  351. b = strconv.AppendInt(b, int64(t.Day()), 10)
  352. b = append(b, []byte{0x2e, 0x20}...)
  353. b = append(b, lv.monthsWide[t.Month()]...)
  354. return string(b)
  355. }
  356. // FmtDateFull returns the full date representation of 't' for 'lv'
  357. func (lv *lv) FmtDateFull(t time.Time) string {
  358. b := make([]byte, 0, 32)
  359. b = append(b, lv.daysWide[t.Weekday()]...)
  360. b = append(b, []byte{0x2c, 0x20}...)
  361. b = strconv.AppendInt(b, int64(t.Year()), 10)
  362. b = append(b, []byte{0x2e}...)
  363. b = append(b, []byte{0x27, 0x67, 0x61, 0x64, 0x61, 0x27, 0x20}...)
  364. b = strconv.AppendInt(b, int64(t.Day()), 10)
  365. b = append(b, []byte{0x2e, 0x20}...)
  366. b = append(b, lv.monthsWide[t.Month()]...)
  367. return string(b)
  368. }
  369. // FmtTimeShort returns the short time representation of 't' for 'lv'
  370. func (lv *lv) FmtTimeShort(t time.Time) string {
  371. b := make([]byte, 0, 32)
  372. if t.Hour() < 10 {
  373. b = append(b, '0')
  374. }
  375. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  376. b = append(b, lv.timeSeparator...)
  377. if t.Minute() < 10 {
  378. b = append(b, '0')
  379. }
  380. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  381. return string(b)
  382. }
  383. // FmtTimeMedium returns the medium time representation of 't' for 'lv'
  384. func (lv *lv) FmtTimeMedium(t time.Time) string {
  385. b := make([]byte, 0, 32)
  386. if t.Hour() < 10 {
  387. b = append(b, '0')
  388. }
  389. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  390. b = append(b, lv.timeSeparator...)
  391. if t.Minute() < 10 {
  392. b = append(b, '0')
  393. }
  394. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  395. b = append(b, lv.timeSeparator...)
  396. if t.Second() < 10 {
  397. b = append(b, '0')
  398. }
  399. b = strconv.AppendInt(b, int64(t.Second()), 10)
  400. return string(b)
  401. }
  402. // FmtTimeLong returns the long time representation of 't' for 'lv'
  403. func (lv *lv) FmtTimeLong(t time.Time) string {
  404. b := make([]byte, 0, 32)
  405. if t.Hour() < 10 {
  406. b = append(b, '0')
  407. }
  408. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  409. b = append(b, lv.timeSeparator...)
  410. if t.Minute() < 10 {
  411. b = append(b, '0')
  412. }
  413. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  414. b = append(b, lv.timeSeparator...)
  415. if t.Second() < 10 {
  416. b = append(b, '0')
  417. }
  418. b = strconv.AppendInt(b, int64(t.Second()), 10)
  419. b = append(b, []byte{0x20}...)
  420. tz, _ := t.Zone()
  421. b = append(b, tz...)
  422. return string(b)
  423. }
  424. // FmtTimeFull returns the full time representation of 't' for 'lv'
  425. func (lv *lv) FmtTimeFull(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, lv.timeSeparator...)
  432. if t.Minute() < 10 {
  433. b = append(b, '0')
  434. }
  435. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  436. b = append(b, lv.timeSeparator...)
  437. if t.Second() < 10 {
  438. b = append(b, '0')
  439. }
  440. b = strconv.AppendInt(b, int64(t.Second()), 10)
  441. b = append(b, []byte{0x20}...)
  442. tz, _ := t.Zone()
  443. if btz, ok := lv.timezones[tz]; ok {
  444. b = append(b, btz...)
  445. } else {
  446. b = append(b, tz...)
  447. }
  448. return string(b)
  449. }