en_US_POSIX.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. package en_US_POSIX
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type en_US_POSIX 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 'en_US_POSIX' locale
  41. func New() locales.Translator {
  42. return &en_US_POSIX{
  43. locale: "en_US_POSIX",
  44. pluralsCardinal: []locales.PluralRule{2, 6},
  45. pluralsOrdinal: []locales.PluralRule{2, 3, 4, 6},
  46. pluralsRange: []locales.PluralRule{6},
  47. decimal: ".",
  48. group: ",",
  49. minus: "-",
  50. percent: "%",
  51. perMille: "0/00",
  52. timeSeparator: ":",
  53. inifinity: "INF",
  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", "CAD", "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", "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", "STN", "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"},
  55. currencyPositivePrefix: " ",
  56. currencyNegativePrefix: " ",
  57. monthsAbbreviated: []string{"", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"},
  58. monthsNarrow: []string{"", "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"},
  59. monthsWide: []string{"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"},
  60. daysAbbreviated: []string{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"},
  61. daysNarrow: []string{"S", "M", "T", "W", "T", "F", "S"},
  62. daysShort: []string{"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"},
  63. daysWide: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
  64. periodsAbbreviated: []string{"am", "pm"},
  65. periodsNarrow: []string{"a", "p"},
  66. periodsWide: []string{"am", "pm"},
  67. erasAbbreviated: []string{"BC", "AD"},
  68. erasNarrow: []string{"B", "A"},
  69. erasWide: []string{"Before Christ", "Anno Domini"},
  70. timezones: map[string]string{"UYT": "Uruguay Standard Time", "MEZ": "Central European Standard Time", "MESZ": "Central European Summer Time", "CLT": "Chile Standard Time", "WAT": "West Africa Standard Time", "HKST": "Hong Kong Summer Time", "GMT": "Greenwich Mean Time", "UYST": "Uruguay Summer Time", "HKT": "Hong Kong Standard Time", "PST": "Pacific Standard Time", "WAST": "West Africa Summer Time", "AKDT": "Alaska Daylight Time", "HEOG": "West Greenland Summer Time", "HEEG": "East Greenland Summer Time", "HNEG": "East Greenland Standard Time", "HNCU": "Cuba Standard Time", "WEZ": "Western European Standard Time", "MST": "Macau Standard Time", "HECU": "Cuba Daylight Time", "VET": "Venezuela Time", "TMT": "Turkmenistan Standard Time", "ACST": "Australian Central Standard Time", "ACDT": "Australian Central Daylight Time", "HAT": "Newfoundland Daylight Time", "WIT": "Eastern Indonesia Time", "OESZ": "Eastern European Summer Time", "BT": "Bhutan Time", "ECT": "Ecuador Time", "HEPM": "St. Pierre & Miquelon Daylight Time", "CLST": "Chile Summer Time", "COST": "Colombia Summer Time", "ChST": "Chamorro Standard Time", "AST": "Atlantic Standard Time", "WIB": "Western Indonesia Time", "HNOG": "West Greenland Standard Time", "ACWST": "Australian Central Western Standard Time", "∅∅∅": "Azores Summer Time", "HAST": "Hawaii-Aleutian Standard Time", "CHADT": "Chatham Daylight Time", "SAST": "South Africa Standard Time", "JST": "Japan Standard Time", "IST": "India Standard Time", "HNNOMX": "Northwest Mexico Standard Time", "OEZ": "Eastern European Standard Time", "HADT": "Hawaii-Aleutian Daylight Time", "HNPMX": "Mexican Pacific Standard Time", "MYT": "Malaysia Time", "LHDT": "Lord Howe Daylight Time", "TMST": "Turkmenistan Summer Time", "EAT": "East Africa Time", "HNT": "Newfoundland Standard Time", "HNPM": "St. Pierre & Miquelon Standard Time", "ART": "Argentina Standard Time", "COT": "Colombia Standard Time", "HEPMX": "Mexican Pacific Daylight Time", "EST": "Eastern Standard Time", "ACWDT": "Australian Central Western Daylight Time", "LHST": "Lord Howe Standard Time", "GFT": "French Guiana Time", "GYT": "Guyana Time", "AWDT": "Australian Western Daylight Time", "JDT": "Japan Daylight Time", "AKST": "Alaska Standard Time", "WARST": "Western Argentina Summer Time", "ARST": "Argentina Summer Time", "SGT": "Singapore Standard Time", "EDT": "Eastern Daylight Time", "WART": "Western Argentina Standard Time", "AWST": "Australian Western Standard Time", "NZST": "New Zealand Standard Time", "NZDT": "New Zealand Daylight Time", "BOT": "Bolivia Time", "MDT": "Macau Summer Time", "CST": "Central Standard Time", "PDT": "Pacific Daylight Time", "AEDT": "Australian Eastern Daylight Time", "SRT": "Suriname Time", "ADT": "Atlantic Daylight Time", "AEST": "Australian Eastern Standard Time", "CHAST": "Chatham Standard Time", "CDT": "Central Daylight Time", "WESZ": "Western European Summer Time", "WITA": "Central Indonesia Time", "HENOMX": "Northwest Mexico Daylight Time", "CAT": "Central Africa Time"},
  71. }
  72. }
  73. // Locale returns the current translators string locale
  74. func (en *en_US_POSIX) Locale() string {
  75. return en.locale
  76. }
  77. // PluralsCardinal returns the list of cardinal plural rules associated with 'en_US_POSIX'
  78. func (en *en_US_POSIX) PluralsCardinal() []locales.PluralRule {
  79. return en.pluralsCardinal
  80. }
  81. // PluralsOrdinal returns the list of ordinal plural rules associated with 'en_US_POSIX'
  82. func (en *en_US_POSIX) PluralsOrdinal() []locales.PluralRule {
  83. return en.pluralsOrdinal
  84. }
  85. // PluralsRange returns the list of range plural rules associated with 'en_US_POSIX'
  86. func (en *en_US_POSIX) PluralsRange() []locales.PluralRule {
  87. return en.pluralsRange
  88. }
  89. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'en_US_POSIX'
  90. func (en *en_US_POSIX) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  91. n := math.Abs(num)
  92. i := int64(n)
  93. if i == 1 && v == 0 {
  94. return locales.PluralRuleOne
  95. }
  96. return locales.PluralRuleOther
  97. }
  98. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'en_US_POSIX'
  99. func (en *en_US_POSIX) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  100. n := math.Abs(num)
  101. nMod10 := math.Mod(n, 10)
  102. nMod100 := math.Mod(n, 100)
  103. if nMod10 == 1 && nMod100 != 11 {
  104. return locales.PluralRuleOne
  105. } else if nMod10 == 2 && nMod100 != 12 {
  106. return locales.PluralRuleTwo
  107. } else if nMod10 == 3 && nMod100 != 13 {
  108. return locales.PluralRuleFew
  109. }
  110. return locales.PluralRuleOther
  111. }
  112. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'en_US_POSIX'
  113. func (en *en_US_POSIX) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  114. return locales.PluralRuleOther
  115. }
  116. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  117. func (en *en_US_POSIX) MonthAbbreviated(month time.Month) string {
  118. return en.monthsAbbreviated[month]
  119. }
  120. // MonthsAbbreviated returns the locales abbreviated months
  121. func (en *en_US_POSIX) MonthsAbbreviated() []string {
  122. return en.monthsAbbreviated[1:]
  123. }
  124. // MonthNarrow returns the locales narrow month given the 'month' provided
  125. func (en *en_US_POSIX) MonthNarrow(month time.Month) string {
  126. return en.monthsNarrow[month]
  127. }
  128. // MonthsNarrow returns the locales narrow months
  129. func (en *en_US_POSIX) MonthsNarrow() []string {
  130. return en.monthsNarrow[1:]
  131. }
  132. // MonthWide returns the locales wide month given the 'month' provided
  133. func (en *en_US_POSIX) MonthWide(month time.Month) string {
  134. return en.monthsWide[month]
  135. }
  136. // MonthsWide returns the locales wide months
  137. func (en *en_US_POSIX) MonthsWide() []string {
  138. return en.monthsWide[1:]
  139. }
  140. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  141. func (en *en_US_POSIX) WeekdayAbbreviated(weekday time.Weekday) string {
  142. return en.daysAbbreviated[weekday]
  143. }
  144. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  145. func (en *en_US_POSIX) WeekdaysAbbreviated() []string {
  146. return en.daysAbbreviated
  147. }
  148. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  149. func (en *en_US_POSIX) WeekdayNarrow(weekday time.Weekday) string {
  150. return en.daysNarrow[weekday]
  151. }
  152. // WeekdaysNarrow returns the locales narrow weekdays
  153. func (en *en_US_POSIX) WeekdaysNarrow() []string {
  154. return en.daysNarrow
  155. }
  156. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  157. func (en *en_US_POSIX) WeekdayShort(weekday time.Weekday) string {
  158. return en.daysShort[weekday]
  159. }
  160. // WeekdaysShort returns the locales short weekdays
  161. func (en *en_US_POSIX) WeekdaysShort() []string {
  162. return en.daysShort
  163. }
  164. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  165. func (en *en_US_POSIX) WeekdayWide(weekday time.Weekday) string {
  166. return en.daysWide[weekday]
  167. }
  168. // WeekdaysWide returns the locales wide weekdays
  169. func (en *en_US_POSIX) WeekdaysWide() []string {
  170. return en.daysWide
  171. }
  172. // Decimal returns the decimal point of number
  173. func (en *en_US_POSIX) Decimal() string {
  174. return en.decimal
  175. }
  176. // Group returns the group of number
  177. func (en *en_US_POSIX) Group() string {
  178. return en.group
  179. }
  180. // Group returns the minus sign of number
  181. func (en *en_US_POSIX) Minus() string {
  182. return en.minus
  183. }
  184. // FmtNumber returns 'num' with digits/precision of 'v' for 'en_US_POSIX' and handles both Whole and Real numbers based on 'v'
  185. func (en *en_US_POSIX) FmtNumber(num float64, v uint64) string {
  186. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  187. l := len(s) + 2
  188. b := make([]byte, 0, l)
  189. for i := len(s) - 1; i >= 0; i-- {
  190. if s[i] == '.' {
  191. b = append(b, en.decimal[0])
  192. continue
  193. }
  194. b = append(b, s[i])
  195. }
  196. if num < 0 {
  197. b = append(b, en.minus[0])
  198. }
  199. // reverse
  200. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  201. b[i], b[j] = b[j], b[i]
  202. }
  203. return string(b)
  204. }
  205. // FmtPercent returns 'num' with digits/precision of 'v' for 'en_US_POSIX' and handles both Whole and Real numbers based on 'v'
  206. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  207. func (en *en_US_POSIX) FmtPercent(num float64, v uint64) string {
  208. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  209. l := len(s) + 3
  210. b := make([]byte, 0, l)
  211. for i := len(s) - 1; i >= 0; i-- {
  212. if s[i] == '.' {
  213. b = append(b, en.decimal[0])
  214. continue
  215. }
  216. b = append(b, s[i])
  217. }
  218. if num < 0 {
  219. b = append(b, en.minus[0])
  220. }
  221. // reverse
  222. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  223. b[i], b[j] = b[j], b[i]
  224. }
  225. b = append(b, en.percent...)
  226. return string(b)
  227. }
  228. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'en_US_POSIX'
  229. func (en *en_US_POSIX) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  230. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  231. symbol := en.currencies[currency]
  232. l := len(s) + len(symbol) + 4
  233. b := make([]byte, 0, l)
  234. for i := len(s) - 1; i >= 0; i-- {
  235. if s[i] == '.' {
  236. b = append(b, en.decimal[0])
  237. continue
  238. }
  239. b = append(b, s[i])
  240. }
  241. for j := len(symbol) - 1; j >= 0; j-- {
  242. b = append(b, symbol[j])
  243. }
  244. for j := len(en.currencyPositivePrefix) - 1; j >= 0; j-- {
  245. b = append(b, en.currencyPositivePrefix[j])
  246. }
  247. if num < 0 {
  248. b = append(b, en.minus[0])
  249. }
  250. // reverse
  251. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  252. b[i], b[j] = b[j], b[i]
  253. }
  254. if int(v) < 2 {
  255. if v == 0 {
  256. b = append(b, en.decimal...)
  257. }
  258. for i := 0; i < 2-int(v); i++ {
  259. b = append(b, '0')
  260. }
  261. }
  262. return string(b)
  263. }
  264. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'en_US_POSIX'
  265. // in accounting notation.
  266. func (en *en_US_POSIX) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  267. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  268. symbol := en.currencies[currency]
  269. l := len(s) + len(symbol) + 4
  270. b := make([]byte, 0, l)
  271. for i := len(s) - 1; i >= 0; i-- {
  272. if s[i] == '.' {
  273. b = append(b, en.decimal[0])
  274. continue
  275. }
  276. b = append(b, s[i])
  277. }
  278. if num < 0 {
  279. for j := len(symbol) - 1; j >= 0; j-- {
  280. b = append(b, symbol[j])
  281. }
  282. for j := len(en.currencyNegativePrefix) - 1; j >= 0; j-- {
  283. b = append(b, en.currencyNegativePrefix[j])
  284. }
  285. b = append(b, en.minus[0])
  286. } else {
  287. for j := len(symbol) - 1; j >= 0; j-- {
  288. b = append(b, symbol[j])
  289. }
  290. for j := len(en.currencyPositivePrefix) - 1; j >= 0; j-- {
  291. b = append(b, en.currencyPositivePrefix[j])
  292. }
  293. }
  294. // reverse
  295. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  296. b[i], b[j] = b[j], b[i]
  297. }
  298. if int(v) < 2 {
  299. if v == 0 {
  300. b = append(b, en.decimal...)
  301. }
  302. for i := 0; i < 2-int(v); i++ {
  303. b = append(b, '0')
  304. }
  305. }
  306. return string(b)
  307. }
  308. // FmtDateShort returns the short date representation of 't' for 'en_US_POSIX'
  309. func (en *en_US_POSIX) FmtDateShort(t time.Time) string {
  310. b := make([]byte, 0, 32)
  311. b = strconv.AppendInt(b, int64(t.Month()), 10)
  312. b = append(b, []byte{0x2f}...)
  313. b = strconv.AppendInt(b, int64(t.Day()), 10)
  314. b = append(b, []byte{0x2f}...)
  315. if t.Year() > 9 {
  316. b = append(b, strconv.Itoa(t.Year())[2:]...)
  317. } else {
  318. b = append(b, strconv.Itoa(t.Year())[1:]...)
  319. }
  320. return string(b)
  321. }
  322. // FmtDateMedium returns the medium date representation of 't' for 'en_US_POSIX'
  323. func (en *en_US_POSIX) FmtDateMedium(t time.Time) string {
  324. b := make([]byte, 0, 32)
  325. b = append(b, en.monthsAbbreviated[t.Month()]...)
  326. b = append(b, []byte{0x20}...)
  327. b = strconv.AppendInt(b, int64(t.Day()), 10)
  328. b = append(b, []byte{0x2c, 0x20}...)
  329. if t.Year() > 0 {
  330. b = strconv.AppendInt(b, int64(t.Year()), 10)
  331. } else {
  332. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  333. }
  334. return string(b)
  335. }
  336. // FmtDateLong returns the long date representation of 't' for 'en_US_POSIX'
  337. func (en *en_US_POSIX) FmtDateLong(t time.Time) string {
  338. b := make([]byte, 0, 32)
  339. b = append(b, en.monthsWide[t.Month()]...)
  340. b = append(b, []byte{0x20}...)
  341. b = strconv.AppendInt(b, int64(t.Day()), 10)
  342. b = append(b, []byte{0x2c, 0x20}...)
  343. if t.Year() > 0 {
  344. b = strconv.AppendInt(b, int64(t.Year()), 10)
  345. } else {
  346. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  347. }
  348. return string(b)
  349. }
  350. // FmtDateFull returns the full date representation of 't' for 'en_US_POSIX'
  351. func (en *en_US_POSIX) FmtDateFull(t time.Time) string {
  352. b := make([]byte, 0, 32)
  353. b = append(b, en.daysWide[t.Weekday()]...)
  354. b = append(b, []byte{0x2c, 0x20}...)
  355. b = append(b, en.monthsWide[t.Month()]...)
  356. b = append(b, []byte{0x20}...)
  357. b = strconv.AppendInt(b, int64(t.Day()), 10)
  358. b = append(b, []byte{0x2c, 0x20}...)
  359. if t.Year() > 0 {
  360. b = strconv.AppendInt(b, int64(t.Year()), 10)
  361. } else {
  362. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  363. }
  364. return string(b)
  365. }
  366. // FmtTimeShort returns the short time representation of 't' for 'en_US_POSIX'
  367. func (en *en_US_POSIX) FmtTimeShort(t time.Time) string {
  368. b := make([]byte, 0, 32)
  369. h := t.Hour()
  370. if h > 12 {
  371. h -= 12
  372. }
  373. b = strconv.AppendInt(b, int64(h), 10)
  374. b = append(b, en.timeSeparator...)
  375. if t.Minute() < 10 {
  376. b = append(b, '0')
  377. }
  378. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  379. b = append(b, []byte{0x20}...)
  380. if t.Hour() < 12 {
  381. b = append(b, en.periodsAbbreviated[0]...)
  382. } else {
  383. b = append(b, en.periodsAbbreviated[1]...)
  384. }
  385. return string(b)
  386. }
  387. // FmtTimeMedium returns the medium time representation of 't' for 'en_US_POSIX'
  388. func (en *en_US_POSIX) FmtTimeMedium(t time.Time) string {
  389. b := make([]byte, 0, 32)
  390. h := t.Hour()
  391. if h > 12 {
  392. h -= 12
  393. }
  394. b = strconv.AppendInt(b, int64(h), 10)
  395. b = append(b, en.timeSeparator...)
  396. if t.Minute() < 10 {
  397. b = append(b, '0')
  398. }
  399. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  400. b = append(b, en.timeSeparator...)
  401. if t.Second() < 10 {
  402. b = append(b, '0')
  403. }
  404. b = strconv.AppendInt(b, int64(t.Second()), 10)
  405. b = append(b, []byte{0x20}...)
  406. if t.Hour() < 12 {
  407. b = append(b, en.periodsAbbreviated[0]...)
  408. } else {
  409. b = append(b, en.periodsAbbreviated[1]...)
  410. }
  411. return string(b)
  412. }
  413. // FmtTimeLong returns the long time representation of 't' for 'en_US_POSIX'
  414. func (en *en_US_POSIX) FmtTimeLong(t time.Time) string {
  415. b := make([]byte, 0, 32)
  416. h := t.Hour()
  417. if h > 12 {
  418. h -= 12
  419. }
  420. b = strconv.AppendInt(b, int64(h), 10)
  421. b = append(b, en.timeSeparator...)
  422. if t.Minute() < 10 {
  423. b = append(b, '0')
  424. }
  425. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  426. b = append(b, en.timeSeparator...)
  427. if t.Second() < 10 {
  428. b = append(b, '0')
  429. }
  430. b = strconv.AppendInt(b, int64(t.Second()), 10)
  431. b = append(b, []byte{0x20}...)
  432. if t.Hour() < 12 {
  433. b = append(b, en.periodsAbbreviated[0]...)
  434. } else {
  435. b = append(b, en.periodsAbbreviated[1]...)
  436. }
  437. b = append(b, []byte{0x20}...)
  438. tz, _ := t.Zone()
  439. b = append(b, tz...)
  440. return string(b)
  441. }
  442. // FmtTimeFull returns the full time representation of 't' for 'en_US_POSIX'
  443. func (en *en_US_POSIX) FmtTimeFull(t time.Time) string {
  444. b := make([]byte, 0, 32)
  445. h := t.Hour()
  446. if h > 12 {
  447. h -= 12
  448. }
  449. b = strconv.AppendInt(b, int64(h), 10)
  450. b = append(b, en.timeSeparator...)
  451. if t.Minute() < 10 {
  452. b = append(b, '0')
  453. }
  454. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  455. b = append(b, en.timeSeparator...)
  456. if t.Second() < 10 {
  457. b = append(b, '0')
  458. }
  459. b = strconv.AppendInt(b, int64(t.Second()), 10)
  460. b = append(b, []byte{0x20}...)
  461. if t.Hour() < 12 {
  462. b = append(b, en.periodsAbbreviated[0]...)
  463. } else {
  464. b = append(b, en.periodsAbbreviated[1]...)
  465. }
  466. b = append(b, []byte{0x20}...)
  467. tz, _ := t.Zone()
  468. if btz, ok := en.timezones[tz]; ok {
  469. b = append(b, btz...)
  470. } else {
  471. b = append(b, tz...)
  472. }
  473. return string(b)
  474. }