az.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. package az
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type az 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. currencyPositivePrefix string
  23. currencyNegativePrefix 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 'az' locale
  41. func New() locales.Translator {
  42. return &az{
  43. locale: "az",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: []locales.PluralRule{2, 4, 5, 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 ", "₼", "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", "JP¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH ", "KRO ", "₩", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL ", "LTL", "LTT ", "LUC ", "LUF ", "LUL ", "LVL", "LVR ", "LYD", "MAD", "MAF ", "MCF ", "MDC ", "MDL", "MGA", "MGF ", "MKD", "MKN ", "MLF ", "MMK", "MNT", "MOP", "MRO", "MTL ", "MTP ", "MUR", "MVP ", "MVR", "MWK", "MX$", "MXP ", "MXV ", "MYR", "MZE ", "MZM ", "MZN", "NAD", "NGN", "NIC ", "NIO", "NLG ", "NOK", "NPR", "NZ$", "OMR", "PAB", "PEI ", "PEN", "PES ", "PGK", "PHP", "PKR", "PLN", "PLZ ", "PTE ", "PYG", "QAR", "RHD ", "ROL ", "RON", "RSD", "RUB", "RUR ", "RWF", "SAR", "SBD", "SCR", "SDD ", "SDG", "SDP ", "SEK", "SGD", "SHP", "SIT ", "SKK ", "SLL", "SOS", "SRD", "SRG ", "SSP", "STD", "SUR ", "SVC ", "SYP", "SZL", "฿", "TJR ", "TJS", "TMM ", "TMT", "TND", "TOP", "TPE ", "TRL ", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK ", "UGS ", "UGX", "US$", "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. currencyPositivePrefix: " ",
  56. currencyNegativePrefix: " ",
  57. monthsAbbreviated: []string{"", "yan", "fev", "mar", "apr", "may", "iyn", "iyl", "avq", "sen", "okt", "noy", "dek"},
  58. monthsNarrow: []string{"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"},
  59. monthsWide: []string{"", "yanvar", "fevral", "mart", "aprel", "may", "iyun", "iyul", "avqust", "sentyabr", "oktyabr", "noyabr", "dekabr"},
  60. daysAbbreviated: []string{"B.", "B.E.", "Ç.A.", "Ç.", "C.A.", "C.", "Ş."},
  61. daysNarrow: []string{"7", "1", "2", "3", "4", "5", "6"},
  62. daysShort: []string{"B.", "B.E.", "Ç.A.", "Ç.", "C.A.", "C.", "Ş."},
  63. daysWide: []string{"bazar", "bazar ertəsi", "çərşənbə axşamı", "çərşənbə", "cümə axşamı", "cümə", "şənbə"},
  64. periodsAbbreviated: []string{"AM", "PM"},
  65. periodsNarrow: []string{"a", "p"},
  66. periodsWide: []string{"AM", "PM"},
  67. erasAbbreviated: []string{"e.ə.", "b.e."},
  68. erasNarrow: []string{"", ""},
  69. erasWide: []string{"eramızdan əvvəl", "eramız"},
  70. timezones: map[string]string{"ART": "Argentina Standart Vaxtı", "MYT": "Malayziya Vaxtı", "JDT": "Yaponiya Yay Vaxtı", "UYST": "Uruqvay Yay Vaxtı", "MST": "Şimali Dağlıq Amerika Standart Vaxtı", "WESZ": "Qərbi Avropa Yay Vaxtı", "HKT": "Honq Konq Standart Vaxtı", "UYT": "Uruqvay Standart Vaxtı", "ACWST": "Mərkəzi Qərbi Avstraliya Standart Vaxtı", "OESZ": "Şərqi Avropa Yay Vaxtı", "PDT": "Şimali Amerika Sakit Okean Yay Vaxtı", "AWST": "Qərbi Avstraliya Standart Vaxtı", "NZST": "Yeni Zelandiya Standart Vaxtı", "ACWDT": "Mərkəzi Qərbi Avstraliya Yay Vaxtı", "WIT": "Şərqi İndoneziya Vaxtı", "JST": "Yaponiya Standart Vaxtı", "BT": "Butan Vaxtı", "LHST": "Lord Hau Standart Vaxtı", "MESZ": "Mərkəzi Avropa Yay Vaxtı", "NZDT": "Yeni Zelandiya Yay Vaxtı", "BOT": "Boliviya Vaxtı", "HADT": "Havay-Aleut Yay Vaxtı", "WITA": "Mərkəzi İndoneziya Vaxtı", "HAT": "Nyufaundlend Yay Vaxtı", "MEZ": "Mərkəzi Avropa Standart Vaxtı", "ChST": "Çamorro Vaxtı", "ADT": "Atlantik Yay Vaxtı", "SAST": "Cənubi Afrika Vaxtı", "CDT": "Şimali Mərkəzi Amerika Yay Vaxtı", "AEST": "Şərqi Avstraliya Standart Vaxtı", "IST": "Hindistan Vaxtı", "EAT": "Şərqi Afrika Vaxtı", "AKDT": "Alyaska Yay Vaxtı", "PST": "Şimali Amerika Sakit Okean Standart Vaxtı", "CHADT": "Çatham Yay Vaxtı", "WEZ": "Qərbi Avropa Standart Vaxtı", "COT": "Kolumbiya Standart Vaxtı", "AKST": "Alyaska Standart Vaxtı", "CLST": "Çili Yay Vaxtı", "CST": "Şimali Mərkəzi Amerika Standart Vaxtı", "SGT": "Sinqapur Vaxtı", "HNT": "Nyufaundlend Standart Vaxtı", "SRT": "Surinam Vaxtı", "TMST": "Türkmənistan Yay Vaxtı", "GYT": "Qayana Vaxtı", "CHAST": "Çatham Standart Vaxtı", "COST": "Kolumbiya Yay Vaxtı", "WARST": "Qərbi Argentina Yay Vaxtı", "TMT": "Türkmənistan Standart Vaxtı", "VET": "Venesuela Vaxtı", "HAST": "Havay-Aleut Standart Vaxtı", "ACDT": "Mərkəzi Avstraliya Yay Vaxtı", "ARST": "Argentina Yay Vaxtı", "LHDT": "Lord Hau Yay vaxtı", "AST": "Atlantik Standart Vaxt", "OEZ": "Şərqi Avropa Standart Vaxtı", "GMT": "Qrinviç Orta Vaxtı", "AWDT": "Qərbi Avstraliya Yay Vaxtı", "ECT": "Ekvador Vaxtı", "WART": "Qərbi Argentina Standart Vaxtı", "GFT": "Fransız Qvianası Vaxtı", "ACST": "Mərkəzi Avstraliya Standart Vaxtı", "∅∅∅": "Braziliya Yay Vaxtı", "WAST": "Qərbi Afrika Yay Vaxtı", "HKST": "Honq Konq Yay Vaxtı", "WIB": "Qərbi İndoneziya Vaxtı", "EST": "Şimali Şərqi Amerika Standart Vaxtı", "EDT": "Şimali Şərqi Amerika Yay Vaxtı", "WAT": "Qərbi Afrika Standart Vaxtı", "MDT": "Şimali Dağlıq Amerika Yay Vaxtı", "CLT": "Çili Standart Vaxtı", "AEDT": "Şərqi Avstraliya Yay Vaxtı", "CAT": "Mərkəzi Afrika Vaxtı"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (az *az) Locale() string {
  75. return az.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'az'
  78. func (az *az) PluralsCardinal() []locales.PluralRule {
  79. return az.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'az'
  82. func (az *az) PluralsOrdinal() []locales.PluralRule {
  83. return az.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'az'
  86. func (az *az) PluralsRange() []locales.PluralRule {
  87. return az.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'az'
  90. func (az *az) 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 'az'
  98. func (az *az) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  99. n := math.Abs(num)
  100. i := int64(n)
  101. iMod10 := i % 10
  102. iMod100 := i % 100
  103. iMod1000 := i % 1000
  104. if (iMod10 == 1 || iMod10 == 2 || iMod10 == 5 || iMod10 == 7 || iMod10 == 8) || (iMod100 == 20 || iMod100 == 50 || iMod100 == 70 || iMod100 == 80) {
  105. return locales.PluralRuleOne
  106. } else if (iMod10 == 3 || iMod10 == 4) || (iMod1000 == 100 || iMod1000 == 200 || iMod1000 == 300 || iMod1000 == 400 || iMod1000 == 500 || iMod1000 == 600 || iMod1000 == 700 || iMod1000 == 800 || iMod1000 == 900) {
  107. return locales.PluralRuleFew
  108. } else if (i == 0) || (iMod10 == 6) || (iMod100 == 40 || iMod100 == 60 || iMod100 == 90) {
  109. return locales.PluralRuleMany
  110. }
  111. return locales.PluralRuleOther
  112. }
  113. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'az'
  114. func (az *az) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  115. start := az.CardinalPluralRule(num1, v1)
  116. end := az.CardinalPluralRule(num2, v2)
  117. if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  118. return locales.PluralRuleOther
  119. } else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
  120. return locales.PluralRuleOne
  121. }
  122. return locales.PluralRuleOther
  123. }
  124. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  125. func (az *az) MonthAbbreviated(month time.Month) string {
  126. return az.monthsAbbreviated[month]
  127. }
  128. // MonthsAbbreviated returns the locales abbreviated months
  129. func (az *az) MonthsAbbreviated() []string {
  130. return az.monthsAbbreviated[1:]
  131. }
  132. // MonthNarrow returns the locales narrow month given the 'month' provided
  133. func (az *az) MonthNarrow(month time.Month) string {
  134. return az.monthsNarrow[month]
  135. }
  136. // MonthsNarrow returns the locales narrow months
  137. func (az *az) MonthsNarrow() []string {
  138. return az.monthsNarrow[1:]
  139. }
  140. // MonthWide returns the locales wide month given the 'month' provided
  141. func (az *az) MonthWide(month time.Month) string {
  142. return az.monthsWide[month]
  143. }
  144. // MonthsWide returns the locales wide months
  145. func (az *az) MonthsWide() []string {
  146. return az.monthsWide[1:]
  147. }
  148. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  149. func (az *az) WeekdayAbbreviated(weekday time.Weekday) string {
  150. return az.daysAbbreviated[weekday]
  151. }
  152. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  153. func (az *az) WeekdaysAbbreviated() []string {
  154. return az.daysAbbreviated
  155. }
  156. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  157. func (az *az) WeekdayNarrow(weekday time.Weekday) string {
  158. return az.daysNarrow[weekday]
  159. }
  160. // WeekdaysNarrow returns the locales narrow weekdays
  161. func (az *az) WeekdaysNarrow() []string {
  162. return az.daysNarrow
  163. }
  164. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  165. func (az *az) WeekdayShort(weekday time.Weekday) string {
  166. return az.daysShort[weekday]
  167. }
  168. // WeekdaysShort returns the locales short weekdays
  169. func (az *az) WeekdaysShort() []string {
  170. return az.daysShort
  171. }
  172. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  173. func (az *az) WeekdayWide(weekday time.Weekday) string {
  174. return az.daysWide[weekday]
  175. }
  176. // WeekdaysWide returns the locales wide weekdays
  177. func (az *az) WeekdaysWide() []string {
  178. return az.daysWide
  179. }
  180. // FmtNumber returns 'num' with digits/precision of 'v' for 'az' and handles both Whole and Real numbers based on 'v'
  181. func (az *az) 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. b := make([]byte, 0, l)
  187. for i := len(s) - 1; i >= 0; i-- {
  188. if s[i] == '.' {
  189. b = append(b, az.decimal[0])
  190. inWhole = true
  191. continue
  192. }
  193. if inWhole {
  194. if count == 3 {
  195. b = append(b, az.group[0])
  196. count = 1
  197. } else {
  198. count++
  199. }
  200. }
  201. b = append(b, s[i])
  202. }
  203. if num < 0 {
  204. b = append(b, az.minus[0])
  205. }
  206. // reverse
  207. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  208. b[i], b[j] = b[j], b[i]
  209. }
  210. return string(b)
  211. }
  212. // FmtPercent returns 'num' with digits/precision of 'v' for 'az' and handles both Whole and Real numbers based on 'v'
  213. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  214. func (az *az) FmtPercent(num float64, v uint64) string {
  215. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  216. l := len(s) + 3
  217. b := make([]byte, 0, l)
  218. for i := len(s) - 1; i >= 0; i-- {
  219. if s[i] == '.' {
  220. b = append(b, az.decimal[0])
  221. continue
  222. }
  223. b = append(b, s[i])
  224. }
  225. if num < 0 {
  226. b = append(b, az.minus[0])
  227. }
  228. // reverse
  229. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  230. b[i], b[j] = b[j], b[i]
  231. }
  232. b = append(b, az.percent...)
  233. return string(b)
  234. }
  235. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'az'
  236. func (az *az) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  237. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  238. symbol := az.currencies[currency]
  239. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  240. count := 0
  241. inWhole := v == 0
  242. b := make([]byte, 0, l)
  243. for i := len(s) - 1; i >= 0; i-- {
  244. if s[i] == '.' {
  245. b = append(b, az.decimal[0])
  246. inWhole = true
  247. continue
  248. }
  249. if inWhole {
  250. if count == 3 {
  251. b = append(b, az.group[0])
  252. count = 1
  253. } else {
  254. count++
  255. }
  256. }
  257. b = append(b, s[i])
  258. }
  259. for j := len(symbol) - 1; j >= 0; j-- {
  260. b = append(b, symbol[j])
  261. }
  262. for j := len(az.currencyPositivePrefix) - 1; j >= 0; j-- {
  263. b = append(b, az.currencyPositivePrefix[j])
  264. }
  265. if num < 0 {
  266. b = append(b, az.minus[0])
  267. }
  268. // reverse
  269. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  270. b[i], b[j] = b[j], b[i]
  271. }
  272. if int(v) < 2 {
  273. if v == 0 {
  274. b = append(b, az.decimal...)
  275. }
  276. for i := 0; i < 2-int(v); i++ {
  277. b = append(b, '0')
  278. }
  279. }
  280. return string(b)
  281. }
  282. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'az'
  283. // in accounting notation.
  284. func (az *az) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  285. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  286. symbol := az.currencies[currency]
  287. l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
  288. count := 0
  289. inWhole := v == 0
  290. b := make([]byte, 0, l)
  291. for i := len(s) - 1; i >= 0; i-- {
  292. if s[i] == '.' {
  293. b = append(b, az.decimal[0])
  294. inWhole = true
  295. continue
  296. }
  297. if inWhole {
  298. if count == 3 {
  299. b = append(b, az.group[0])
  300. count = 1
  301. } else {
  302. count++
  303. }
  304. }
  305. b = append(b, s[i])
  306. }
  307. if num < 0 {
  308. for j := len(symbol) - 1; j >= 0; j-- {
  309. b = append(b, symbol[j])
  310. }
  311. for j := len(az.currencyNegativePrefix) - 1; j >= 0; j-- {
  312. b = append(b, az.currencyNegativePrefix[j])
  313. }
  314. b = append(b, az.minus[0])
  315. } else {
  316. for j := len(symbol) - 1; j >= 0; j-- {
  317. b = append(b, symbol[j])
  318. }
  319. for j := len(az.currencyPositivePrefix) - 1; j >= 0; j-- {
  320. b = append(b, az.currencyPositivePrefix[j])
  321. }
  322. }
  323. // reverse
  324. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  325. b[i], b[j] = b[j], b[i]
  326. }
  327. if int(v) < 2 {
  328. if v == 0 {
  329. b = append(b, az.decimal...)
  330. }
  331. for i := 0; i < 2-int(v); i++ {
  332. b = append(b, '0')
  333. }
  334. }
  335. return string(b)
  336. }
  337. // FmtDateShort returns the short date representation of 't' for 'az'
  338. func (az *az) FmtDateShort(t time.Time) string {
  339. b := make([]byte, 0, 32)
  340. if t.Day() < 10 {
  341. b = append(b, '0')
  342. }
  343. b = strconv.AppendInt(b, int64(t.Day()), 10)
  344. b = append(b, []byte{0x2e}...)
  345. if t.Month() < 10 {
  346. b = append(b, '0')
  347. }
  348. b = strconv.AppendInt(b, int64(t.Month()), 10)
  349. b = append(b, []byte{0x2e}...)
  350. if t.Year() > 9 {
  351. b = append(b, strconv.Itoa(t.Year())[2:]...)
  352. } else {
  353. b = append(b, strconv.Itoa(t.Year())[1:]...)
  354. }
  355. return string(b)
  356. }
  357. // FmtDateMedium returns the medium date representation of 't' for 'az'
  358. func (az *az) FmtDateMedium(t time.Time) string {
  359. b := make([]byte, 0, 32)
  360. b = strconv.AppendInt(b, int64(t.Day()), 10)
  361. b = append(b, []byte{0x20}...)
  362. b = append(b, az.monthsAbbreviated[t.Month()]...)
  363. b = append(b, []byte{0x20}...)
  364. b = strconv.AppendInt(b, int64(t.Year()), 10)
  365. return string(b)
  366. }
  367. // FmtDateLong returns the long date representation of 't' for 'az'
  368. func (az *az) FmtDateLong(t time.Time) string {
  369. b := make([]byte, 0, 32)
  370. b = strconv.AppendInt(b, int64(t.Day()), 10)
  371. b = append(b, []byte{0x20}...)
  372. b = append(b, az.monthsWide[t.Month()]...)
  373. b = append(b, []byte{0x20}...)
  374. b = strconv.AppendInt(b, int64(t.Year()), 10)
  375. return string(b)
  376. }
  377. // FmtDateFull returns the full date representation of 't' for 'az'
  378. func (az *az) FmtDateFull(t time.Time) string {
  379. b := make([]byte, 0, 32)
  380. b = strconv.AppendInt(b, int64(t.Day()), 10)
  381. b = append(b, []byte{0x20}...)
  382. b = append(b, az.monthsWide[t.Month()]...)
  383. b = append(b, []byte{0x20}...)
  384. b = strconv.AppendInt(b, int64(t.Year()), 10)
  385. b = append(b, []byte{0x2c, 0x20}...)
  386. b = append(b, az.daysWide[t.Weekday()]...)
  387. return string(b)
  388. }
  389. // FmtTimeShort returns the short time representation of 't' for 'az'
  390. func (az *az) FmtTimeShort(t time.Time) string {
  391. b := make([]byte, 0, 32)
  392. if t.Hour() < 10 {
  393. b = append(b, '0')
  394. }
  395. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  396. b = append(b, az.timeSeparator...)
  397. if t.Minute() < 10 {
  398. b = append(b, '0')
  399. }
  400. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  401. return string(b)
  402. }
  403. // FmtTimeMedium returns the medium time representation of 't' for 'az'
  404. func (az *az) FmtTimeMedium(t time.Time) string {
  405. b := make([]byte, 0, 32)
  406. if t.Hour() < 10 {
  407. b = append(b, '0')
  408. }
  409. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  410. b = append(b, az.timeSeparator...)
  411. if t.Minute() < 10 {
  412. b = append(b, '0')
  413. }
  414. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  415. b = append(b, az.timeSeparator...)
  416. if t.Second() < 10 {
  417. b = append(b, '0')
  418. }
  419. b = strconv.AppendInt(b, int64(t.Second()), 10)
  420. return string(b)
  421. }
  422. // FmtTimeLong returns the long time representation of 't' for 'az'
  423. func (az *az) FmtTimeLong(t time.Time) string {
  424. b := make([]byte, 0, 32)
  425. if t.Hour() < 10 {
  426. b = append(b, '0')
  427. }
  428. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  429. b = append(b, az.timeSeparator...)
  430. if t.Minute() < 10 {
  431. b = append(b, '0')
  432. }
  433. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  434. b = append(b, az.timeSeparator...)
  435. if t.Second() < 10 {
  436. b = append(b, '0')
  437. }
  438. b = strconv.AppendInt(b, int64(t.Second()), 10)
  439. b = append(b, []byte{0x20}...)
  440. tz, _ := t.Zone()
  441. b = append(b, tz...)
  442. return string(b)
  443. }
  444. // FmtTimeFull returns the full time representation of 't' for 'az'
  445. func (az *az) FmtTimeFull(t time.Time) string {
  446. b := make([]byte, 0, 32)
  447. if t.Hour() < 10 {
  448. b = append(b, '0')
  449. }
  450. b = strconv.AppendInt(b, int64(t.Hour()), 10)
  451. b = append(b, az.timeSeparator...)
  452. if t.Minute() < 10 {
  453. b = append(b, '0')
  454. }
  455. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  456. b = append(b, az.timeSeparator...)
  457. if t.Second() < 10 {
  458. b = append(b, '0')
  459. }
  460. b = strconv.AppendInt(b, int64(t.Second()), 10)
  461. b = append(b, []byte{0x20}...)
  462. tz, _ := t.Zone()
  463. if btz, ok := az.timezones[tz]; ok {
  464. b = append(b, btz...)
  465. } else {
  466. b = append(b, tz...)
  467. }
  468. return string(b)
  469. }