sah.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package sah
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type sah 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 'sah' locale
  41. func New() locales.Translator {
  42. return &sah{
  43. locale: "sah",
  44. pluralsCardinal: []locales.PluralRule{6},
  45. pluralsOrdinal: nil,
  46. pluralsRange: nil,
  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", "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", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "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", "EUR", "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", "MX$", "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", "₽", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "STN", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "$", "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"},
  55. currencyPositiveSuffix: " ",
  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{"AKDT": "AKDT", "HKST": "HKST", "WART": "WART", "UYST": "UYST", "AWDT": "Арҕаа Австралия сайыҥҥы кэмэ", "ACWST": "ACWST", "HNEG": "HNEG", "HNPMX": "HNPMX", "WAST": "WAST", "HNPM": "HNPM", "HADT": "HADT", "PDT": "PDT", "SAST": "SAST", "GFT": "GFT", "HEEG": "HEEG", "HEOG": "HEOG", "LHDT": "LHDT", "HEPM": "HEPM", "HNCU": "HNCU", "ARST": "ARST", "HECU": "HECU", "MYT": "MYT", "HNT": "HNT", "WIT": "WIT", "NZDT": "Саҥа Сэйлэнд сайыҥҥы кэмэ", "ACDT": "Киин Австралия сайыҥҥы кэмэ", "IST": "Ииндийэ сүрүн кэмэ", "OEZ": "OEZ", "CDT": "CDT", "AEDT": "Илин Австралия сайыҥҥы кэмэ", "BT": "BT", "JDT": "Дьоппуон сайыҥҥы кэмэ", "LHST": "LHST", "TMST": "TMST", "HEPMX": "HEPMX", "MDT": "MDT", "EST": "EST", "HKT": "HKT", "VET": "VET", "WITA": "WITA", "CAT": "CAT", "COT": "COT", "WEZ": "WEZ", "JST": "Дьоппуон сүрүн кэмэ", "AKST": "AKST", "SRT": "SRT", "CHADT": "CHADT", "AWST": "Арҕаа Австралия сүрүн кэмэ", "OESZ": "OESZ", "AST": "AST", "AEST": "Илин Австралия сүрүн кэмэ", "BOT": "BOT", "ECT": "ECT", "HNOG": "HNOG", "MESZ": "MESZ", "TMT": "TMT", "HAST": "HAST", "ART": "ART", "ChST": "ChST", "CST": "CST", "UYT": "UYT", "MST": "MST", "SGT": "SGT", "ACST": "Киин Австралия сүрүн кэмэ", "ACWDT": "ACWDT", "WARST": "WARST", "HAT": "HAT", "EAT": "EAT", "PST": "PST", "ADT": "ADT", "WESZ": "WESZ", "∅∅∅": "∅∅∅", "HNNOMX": "HNNOMX", "CLST": "CLST", "WAT": "WAT", "WIB": "WIB", "EDT": "EDT", "CLT": "CLT", "GMT": "GMT", "GYT": "GYT", "CHAST": "CHAST", "NZST": "Саҥа Сэйлэнд сүрүн кэмэ", "MEZ": "MEZ", "HENOMX": "HENOMX", "COST": "COST"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (sah *sah) Locale() string {
  75. return sah.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'sah'
  78. func (sah *sah) PluralsCardinal() []locales.PluralRule {
  79. return sah.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'sah'
  82. func (sah *sah) PluralsOrdinal() []locales.PluralRule {
  83. return sah.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'sah'
  86. func (sah *sah) PluralsRange() []locales.PluralRule {
  87. return sah.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'sah'
  90. func (sah *sah) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. return locales.PluralRuleOther
  92. }
  93. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'sah'
  94. func (sah *sah) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  95. return locales.PluralRuleUnknown
  96. }
  97. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'sah'
  98. func (sah *sah) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  99. return locales.PluralRuleUnknown
  100. }
  101. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  102. func (sah *sah) MonthAbbreviated(month time.Month) string {
  103. return sah.monthsAbbreviated[month]
  104. }
  105. // MonthsAbbreviated returns the locales abbreviated months
  106. func (sah *sah) MonthsAbbreviated() []string {
  107. return sah.monthsAbbreviated[1:]
  108. }
  109. // MonthNarrow returns the locales narrow month given the 'month' provided
  110. func (sah *sah) MonthNarrow(month time.Month) string {
  111. return sah.monthsNarrow[month]
  112. }
  113. // MonthsNarrow returns the locales narrow months
  114. func (sah *sah) MonthsNarrow() []string {
  115. return sah.monthsNarrow[1:]
  116. }
  117. // MonthWide returns the locales wide month given the 'month' provided
  118. func (sah *sah) MonthWide(month time.Month) string {
  119. return sah.monthsWide[month]
  120. }
  121. // MonthsWide returns the locales wide months
  122. func (sah *sah) MonthsWide() []string {
  123. return sah.monthsWide[1:]
  124. }
  125. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  126. func (sah *sah) WeekdayAbbreviated(weekday time.Weekday) string {
  127. return sah.daysAbbreviated[weekday]
  128. }
  129. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  130. func (sah *sah) WeekdaysAbbreviated() []string {
  131. return sah.daysAbbreviated
  132. }
  133. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  134. func (sah *sah) WeekdayNarrow(weekday time.Weekday) string {
  135. return sah.daysNarrow[weekday]
  136. }
  137. // WeekdaysNarrow returns the locales narrow weekdays
  138. func (sah *sah) WeekdaysNarrow() []string {
  139. return sah.daysNarrow
  140. }
  141. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  142. func (sah *sah) WeekdayShort(weekday time.Weekday) string {
  143. return sah.daysShort[weekday]
  144. }
  145. // WeekdaysShort returns the locales short weekdays
  146. func (sah *sah) WeekdaysShort() []string {
  147. return sah.daysShort
  148. }
  149. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  150. func (sah *sah) WeekdayWide(weekday time.Weekday) string {
  151. return sah.daysWide[weekday]
  152. }
  153. // WeekdaysWide returns the locales wide weekdays
  154. func (sah *sah) WeekdaysWide() []string {
  155. return sah.daysWide
  156. }
  157. // Decimal returns the decimal point of number
  158. func (sah *sah) Decimal() string {
  159. return sah.decimal
  160. }
  161. // Group returns the group of number
  162. func (sah *sah) Group() string {
  163. return sah.group
  164. }
  165. // Group returns the minus sign of number
  166. func (sah *sah) Minus() string {
  167. return sah.minus
  168. }
  169. // FmtNumber returns 'num' with digits/precision of 'v' for 'sah' and handles both Whole and Real numbers based on 'v'
  170. func (sah *sah) FmtNumber(num float64, v uint64) string {
  171. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  172. l := len(s) + 2 + 2*len(s[:len(s)-int(v)-1])/3
  173. count := 0
  174. inWhole := v == 0
  175. b := make([]byte, 0, l)
  176. for i := len(s) - 1; i >= 0; i-- {
  177. if s[i] == '.' {
  178. b = append(b, sah.decimal[0])
  179. inWhole = true
  180. continue
  181. }
  182. if inWhole {
  183. if count == 3 {
  184. for j := len(sah.group) - 1; j >= 0; j-- {
  185. b = append(b, sah.group[j])
  186. }
  187. count = 1
  188. } else {
  189. count++
  190. }
  191. }
  192. b = append(b, s[i])
  193. }
  194. if num < 0 {
  195. b = append(b, sah.minus[0])
  196. }
  197. // reverse
  198. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  199. b[i], b[j] = b[j], b[i]
  200. }
  201. return string(b)
  202. }
  203. // FmtPercent returns 'num' with digits/precision of 'v' for 'sah' and handles both Whole and Real numbers based on 'v'
  204. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  205. func (sah *sah) FmtPercent(num float64, v uint64) string {
  206. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  207. l := len(s) + 3
  208. b := make([]byte, 0, l)
  209. for i := len(s) - 1; i >= 0; i-- {
  210. if s[i] == '.' {
  211. b = append(b, sah.decimal[0])
  212. continue
  213. }
  214. b = append(b, s[i])
  215. }
  216. if num < 0 {
  217. b = append(b, sah.minus[0])
  218. }
  219. // reverse
  220. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  221. b[i], b[j] = b[j], b[i]
  222. }
  223. b = append(b, sah.percent...)
  224. return string(b)
  225. }
  226. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'sah'
  227. func (sah *sah) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  228. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  229. symbol := sah.currencies[currency]
  230. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  231. count := 0
  232. inWhole := v == 0
  233. b := make([]byte, 0, l)
  234. for i := len(s) - 1; i >= 0; i-- {
  235. if s[i] == '.' {
  236. b = append(b, sah.decimal[0])
  237. inWhole = true
  238. continue
  239. }
  240. if inWhole {
  241. if count == 3 {
  242. for j := len(sah.group) - 1; j >= 0; j-- {
  243. b = append(b, sah.group[j])
  244. }
  245. count = 1
  246. } else {
  247. count++
  248. }
  249. }
  250. b = append(b, s[i])
  251. }
  252. if num < 0 {
  253. b = append(b, sah.minus[0])
  254. }
  255. // reverse
  256. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  257. b[i], b[j] = b[j], b[i]
  258. }
  259. if int(v) < 2 {
  260. if v == 0 {
  261. b = append(b, sah.decimal...)
  262. }
  263. for i := 0; i < 2-int(v); i++ {
  264. b = append(b, '0')
  265. }
  266. }
  267. b = append(b, sah.currencyPositiveSuffix...)
  268. b = append(b, symbol...)
  269. return string(b)
  270. }
  271. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'sah'
  272. // in accounting notation.
  273. func (sah *sah) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  274. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  275. symbol := sah.currencies[currency]
  276. l := len(s) + len(symbol) + 4 + 2*len(s[:len(s)-int(v)-1])/3
  277. count := 0
  278. inWhole := v == 0
  279. b := make([]byte, 0, l)
  280. for i := len(s) - 1; i >= 0; i-- {
  281. if s[i] == '.' {
  282. b = append(b, sah.decimal[0])
  283. inWhole = true
  284. continue
  285. }
  286. if inWhole {
  287. if count == 3 {
  288. for j := len(sah.group) - 1; j >= 0; j-- {
  289. b = append(b, sah.group[j])
  290. }
  291. count = 1
  292. } else {
  293. count++
  294. }
  295. }
  296. b = append(b, s[i])
  297. }
  298. if num < 0 {
  299. b = append(b, sah.minus[0])
  300. }
  301. // reverse
  302. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  303. b[i], b[j] = b[j], b[i]
  304. }
  305. if int(v) < 2 {
  306. if v == 0 {
  307. b = append(b, sah.decimal...)
  308. }
  309. for i := 0; i < 2-int(v); i++ {
  310. b = append(b, '0')
  311. }
  312. }
  313. if num < 0 {
  314. b = append(b, sah.currencyNegativeSuffix...)
  315. b = append(b, symbol...)
  316. } else {
  317. b = append(b, sah.currencyPositiveSuffix...)
  318. b = append(b, symbol...)
  319. }
  320. return string(b)
  321. }
  322. // FmtDateShort returns the short date representation of 't' for 'sah'
  323. func (sah *sah) FmtDateShort(t time.Time) string {
  324. b := make([]byte, 0, 32)
  325. if t.Year() > 9 {
  326. b = append(b, strconv.Itoa(t.Year())[2:]...)
  327. } else {
  328. b = append(b, strconv.Itoa(t.Year())[1:]...)
  329. }
  330. b = append(b, []byte{0x2f}...)
  331. b = strconv.AppendInt(b, int64(t.Month()), 10)
  332. b = append(b, []byte{0x2f}...)
  333. b = strconv.AppendInt(b, int64(t.Day()), 10)
  334. return string(b)
  335. }
  336. // FmtDateMedium returns the medium date representation of 't' for 'sah'
  337. func (sah *sah) FmtDateMedium(t time.Time) string {
  338. b := make([]byte, 0, 32)
  339. if t.Year() > 0 {
  340. b = strconv.AppendInt(b, int64(t.Year()), 10)
  341. } else {
  342. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  343. }
  344. b = append(b, []byte{0x2c, 0x20}...)
  345. b = append(b, sah.monthsAbbreviated[t.Month()]...)
  346. b = append(b, []byte{0x20}...)
  347. b = strconv.AppendInt(b, int64(t.Day()), 10)
  348. return string(b)
  349. }
  350. // FmtDateLong returns the long date representation of 't' for 'sah'
  351. func (sah *sah) FmtDateLong(t time.Time) string {
  352. b := make([]byte, 0, 32)
  353. if t.Year() > 0 {
  354. b = strconv.AppendInt(b, int64(t.Year()), 10)
  355. } else {
  356. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  357. }
  358. b = append(b, []byte{0x2c, 0x20}...)
  359. b = append(b, sah.monthsWide[t.Month()]...)
  360. b = append(b, []byte{0x20}...)
  361. b = strconv.AppendInt(b, int64(t.Day()), 10)
  362. return string(b)
  363. }
  364. // FmtDateFull returns the full date representation of 't' for 'sah'
  365. func (sah *sah) FmtDateFull(t time.Time) string {
  366. b := make([]byte, 0, 32)
  367. if t.Year() > 0 {
  368. b = strconv.AppendInt(b, int64(t.Year()), 10)
  369. } else {
  370. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  371. }
  372. b = append(b, []byte{0x20, 0xd1, 0x81, 0xd1, 0x8b, 0xd0, 0xbb}...)
  373. b = append(b, []byte{0x20}...)
  374. b = append(b, sah.monthsWide[t.Month()]...)
  375. b = append(b, []byte{0x20}...)
  376. b = strconv.AppendInt(b, int64(t.Day()), 10)
  377. b = append(b, []byte{0x20, 0xd0, 0xba, 0xd2, 0xaf, 0xd0, 0xbd, 0xd1, 0x8d}...)
  378. b = append(b, []byte{0x2c, 0x20}...)
  379. b = append(b, sah.daysWide[t.Weekday()]...)
  380. return string(b)
  381. }
  382. // FmtTimeShort returns the short time representation of 't' for 'sah'
  383. func (sah *sah) FmtTimeShort(t time.Time) string {
  384. b := make([]byte, 0, 32)
  385. if t.Hour() < 10 {
  386. b = append(b, '0')
  387. }
  388. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  389. b = append(b, sah.timeSeparator...)
  390. if t.Minute() < 10 {
  391. b = append(b, '0')
  392. }
  393. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  394. return string(b)
  395. }
  396. // FmtTimeMedium returns the medium time representation of 't' for 'sah'
  397. func (sah *sah) FmtTimeMedium(t time.Time) string {
  398. b := make([]byte, 0, 32)
  399. if t.Hour() < 10 {
  400. b = append(b, '0')
  401. }
  402. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  403. b = append(b, sah.timeSeparator...)
  404. if t.Minute() < 10 {
  405. b = append(b, '0')
  406. }
  407. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  408. b = append(b, sah.timeSeparator...)
  409. if t.Second() < 10 {
  410. b = append(b, '0')
  411. }
  412. b = strconv.AppendInt(b, int64(t.Second()), 10)
  413. return string(b)
  414. }
  415. // FmtTimeLong returns the long time representation of 't' for 'sah'
  416. func (sah *sah) FmtTimeLong(t time.Time) string {
  417. b := make([]byte, 0, 32)
  418. if t.Hour() < 10 {
  419. b = append(b, '0')
  420. }
  421. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  422. b = append(b, sah.timeSeparator...)
  423. if t.Minute() < 10 {
  424. b = append(b, '0')
  425. }
  426. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  427. b = append(b, sah.timeSeparator...)
  428. if t.Second() < 10 {
  429. b = append(b, '0')
  430. }
  431. b = strconv.AppendInt(b, int64(t.Second()), 10)
  432. b = append(b, []byte{0x20}...)
  433. tz, _ := t.Zone()
  434. b = append(b, tz...)
  435. return string(b)
  436. }
  437. // FmtTimeFull returns the full time representation of 't' for 'sah'
  438. func (sah *sah) FmtTimeFull(t time.Time) string {
  439. b := make([]byte, 0, 32)
  440. if t.Hour() < 10 {
  441. b = append(b, '0')
  442. }
  443. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  444. b = append(b, sah.timeSeparator...)
  445. if t.Minute() < 10 {
  446. b = append(b, '0')
  447. }
  448. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  449. b = append(b, sah.timeSeparator...)
  450. if t.Second() < 10 {
  451. b = append(b, '0')
  452. }
  453. b = strconv.AppendInt(b, int64(t.Second()), 10)
  454. b = append(b, []byte{0x20}...)
  455. tz, _ := t.Zone()
  456. if btz, ok := sah.timezones[tz]; ok {
  457. b = append(b, btz...)
  458. } else {
  459. b = append(b, tz...)
  460. }
  461. return string(b)
  462. }