dz.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. package dz
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type dz struct {
  10. locale string
  11. pluralsCardinal []locales.PluralRule
  12. pluralsOrdinal []locales.PluralRule
  13. pluralsRange []locales.PluralRule
  14. decimal string
  15. group string
  16. minus string
  17. percent string
  18. percentSuffix string
  19. perMille string
  20. timeSeparator string
  21. inifinity string
  22. currencies []string // idx = enum of currency code
  23. monthsAbbreviated []string
  24. monthsNarrow []string
  25. monthsWide []string
  26. daysAbbreviated []string
  27. daysNarrow []string
  28. daysShort []string
  29. daysWide []string
  30. periodsAbbreviated []string
  31. periodsNarrow []string
  32. periodsShort []string
  33. periodsWide []string
  34. erasAbbreviated []string
  35. erasNarrow []string
  36. erasWide []string
  37. timezones map[string]string
  38. }
  39. // New returns a new instance of translator for the 'dz' locale
  40. func New() locales.Translator {
  41. return &dz{
  42. locale: "dz",
  43. pluralsCardinal: []locales.PluralRule{6},
  44. pluralsOrdinal: nil,
  45. pluralsRange: nil,
  46. decimal: ".",
  47. group: ",",
  48. minus: "-",
  49. percent: "%",
  50. perMille: "‰",
  51. timeSeparator: ":",
  52. inifinity: "∞",
  53. 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 ", "Nu.", "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 ", "ILS", "₹", "IQD ", "IRR ", "ISJ ", "ISK ", "ITL ", "JMD ", "JOD ", "JP¥", "KES ", "KGS ", "KHR ", "KMF ", "KPW ", "KRH ", "KRO ", "KR₩", "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 ", "TH฿", "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 ", "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 "},
  54. percentSuffix: " ",
  55. monthsAbbreviated: []string{"", "༡", "༢", "༣", "༤", "༥", "༦", "༧", "༨", "༩", "༡༠", "༡༡", "12"},
  56. monthsNarrow: []string{"", "༡", "༢", "༣", "4", "༥", "༦", "༧", "༨", "9", "༡༠", "༡༡", "༡༢"},
  57. monthsWide: []string{"", "ཟླ་དངཔ་", "ཟླ་གཉིས་པ་", "ཟླ་གསུམ་པ་", "ཟླ་བཞི་པ་", "ཟླ་ལྔ་པ་", "ཟླ་དྲུག་པ", "ཟླ་བདུན་པ་", "ཟླ་བརྒྱད་པ་", "ཟླ་དགུ་པ་", "ཟླ་བཅུ་པ་", "ཟླ་བཅུ་གཅིག་པ་", "ཟླ་བཅུ་གཉིས་པ་"},
  58. daysAbbreviated: []string{"ཟླ་", "མིར་", "ལྷག་", "ཕུར་", "སངས་", "སྤེན་", "ཉི་"},
  59. daysNarrow: []string{"ཟླ", "མིར", "ལྷག", "ཕུར", "སངྶ", "སྤེན", "ཉི"},
  60. daysShort: []string{"ཟླ་", "མིར་", "ལྷག་", "ཕུར་", "སངས་", "སྤེན་", "ཉི་"},
  61. daysWide: []string{"གཟའ་ཟླ་བ་", "གཟའ་མིག་དམར་", "གཟའ་ལྷག་པ་", "གཟའ་ཕུར་བུ་", "གཟའ་པ་སངས་", "གཟའ་སྤེན་པ་", "གཟའ་ཉི་མ་"},
  62. periodsAbbreviated: []string{"སྔ་ཆ་", "ཕྱི་ཆ་"},
  63. periodsNarrow: []string{"སྔ་ཆ་", "ཕྱི་ཆ་"},
  64. periodsWide: []string{"སྔ་ཆ་", "ཕྱི་ཆ་"},
  65. erasAbbreviated: []string{"BCE", "CE"},
  66. erasNarrow: []string{"", ""},
  67. erasWide: []string{"", ""},
  68. timezones: map[string]string{"IST": "རྒྱ་གར་ཆུ་ཚོད", "OEZ": "ཤར་ཕྱོགས་ཡུ་རོ་པེན་ཚད་ལྡན་ཆུ་ཚོད", "PDT": "བྱང་ཨ་མི་རི་ཀ་པེ་སི་ཕིག་ཉིན་སྲུང་ཆུ་ཚོད", "UYST": "ཡུ་རུ་གུ་ཝཱའི་བྱཱར་དུས་ཆུ་ཚོད", "WEZ": "ནུབ་ཕྱོགས་ཡུ་རོ་པེན་ཚད་ལྡན་ཆུ་ཚོད", "CAT": "དབུས་ཕྱོགས་ཨཕ་རི་ཀཱ་ཆུ་ཚོད", "ADT": "ཨེཊ་ལེན་ཊིཀ་ཉིན་སྲུང་ཆུ་ཚོད", "SAST": "ལྷོ་ཕྱོགས་ཨཕ་རི་ཀཱ་ཆུ་ཚོད", "TMST": "TMST", "LHST": "LHST", "UYT": "ཡུ་རུ་གུ་ཝཱའི་ཚད་ལྡན་ཆུ་ཚོད", "AWDT": "ནུབ་ཕྱོགས་ཨཱོས་ཊྲེལ་ལི་ཡ་ཉིན་སྲུང་ཆུ་ཚོད", "MESZ": "དབུས་ཕྱོགས་ཡུ་རོ་པེན་བྱཱར་དུས་ཆུ་ཚོད", "CLT": "ཅི་ལི་ཚད་ལྡན་ཆུ་ཚོད", "ACST": "དབུས་ཕྱོགས་ཨཱོས་ཊྲེལ་ལི་ཡ་ཚད་ལྡན་ཆུ་ཚོད", "PST": "བྱང་ཨ་མི་རི་ཀ་པེ་སི་ཕིག་ཚད་ལྡན་ཆུ་ཚོད", "CST": "བྱང་ཨ་མི་རི་ཀ་དབུས་ཕྱོགས་ཚད་ལྡན་ཆུ་ཚོད", "BOT": "བྷོ་ལི་བི་ཡ་ཆུ་ཚོད", "VET": "བེ་ནི་ཛུ་ཝེ་ལ་ཆུ་ཚོད", "AEDT": "ཤར་ཕྱོགས་ཕྱོགས་ཨཱོས་ཊྲེལ་ལི་ཡ་ཉིན་སྲུང་ཆུ་ཚོད", "ChST": "ChST", "OESZ": "ཤར་ཕྱོགས་ཡུ་རོ་པེན་བྱཱར་དུས་ཆུ་ཚོད", "HNT": "ནིའུ་ཕའུནཌ་ལེནཌ་ཚད་ལྡན་ཆུ་ཚོད", "TMT": "TMT", "LHDT": "LHDT", "CHAST": "CHAST", "EST": "བྱང་ཨ་མི་རི་ཀ་ཤར་ཕྱོགས་ཚད་ལྡན་ཆུ་ཚོད", "EDT": "བྱང་ཨ་མི་རི་ཀ་ཤར་ཕྱོགས་ཉིན་སྲུང་ཆུ་ཚོད", "SRT": "སུ་རི་ནཱམ་ཆུ་ཚོད", "AKST": "ཨ་ལསི་ཀ་ཚད་ལྡན་ཆུ་ཚོད", "NZST": "ནིའུ་ཛི་ལེནཌ་ཚད་ལྡན་ཆུ་ཚོད", "WAST": "ནུབ་ཕྱོགས་ཨཕ་རི་ཀཱ་བྱཱར་དུས་ཆུ་ཚོད", "MST": "MST", "∅∅∅": "ཨེ་མ་ཛཱོན་བྱཱར་དུས་ཆུ་ཚོད", "JDT": "ཇ་པཱན་ཉིན་སྲུང་ཆུ་ཚོད", "HADT": "ཧ་ཝའི་-ཨེ་ལིའུ་ཤེན་ཉིན་སྲུང་ཆུ་ཚོད", "WIB": "ནུབ་ཕྱོགས་ཨིན་ཌོ་ནེ་ཤི་ཡ་ཆུ་ཚོད", "AKDT": "ཨ་ལསི་ཀ་ཉིན་སྲུང་ཆུ་ཚོད", "WESZ": "ནུབ་ཕྱོགས་ཡུ་རོ་པེན་བྱཱར་དུས་ཆུ་ཚོད", "HAT": "ནིའུ་ཕའུནཌ་ལེནཌ་ཉིན་སྲུང་ཆུ་ཚོད", "EAT": "ཤར་ཕྱོགས་ཨཕ་རི་ཀཱ་ཆུ་ཚོད", "MDT": "MDT", "MYT": "MYT", "AST": "ཨེཊ་ལེན་ཊིཀ་ཚད་ལྡན་ཆུ་ཚོད", "BT": "འབྲུག་ཡུལ་ཆུ་ཚོད", "WITA": "དབུས་ཕྱོགས་ཨིན་ཌོ་ནེ་ཤི་ཡ་ཆུ་ཚོད", "MEZ": "དབུས་ཕྱོགས་ཡུ་རོ་པེན་ཚད་ལྡན་ཆུ་ཚོད", "ACWDT": "དབུས་ནུབ་ཕྱོགས་ཨཱོས་ཊྲེལ་ལི་ཡ་ཉིན་སྲུང་ཆུ་ཚོད", "ECT": "ཨེ་ཀུ་ཌཽ་ཆུ་ཚོད", "HKST": "HKST", "WART": "ནུབ་ཕྱོགས་ཨར་ཇེན་ཊི་ན་ཚད་ལྡན་ཆུ་ཚོད", "GMT": "གིརིན་ཝིཆ་ལུ་ཡོད་པའི་ཆུ་ཚོད", "ART": "ཨར་ཇེན་ཊི་ན་ཚད་ལྡན་ཆུ་ཚོད", "NZDT": "ནིའུ་ཛི་ལེནཌ་ཉིན་སྲུང་ཆུ་ཚོད", "HAST": "ཧ་ཝའི་-ཨེ་ལིའུ་ཤེན་ཚད་ལྡན་ཆུ་ཚོད", "WAT": "ནུབ་ཕྱོགས་ཨཕ་རི་ཀཱ་ཚད་ལྡན་ཆུ་ཚོད", "ACDT": "དབུས་ཕྱོགས་ཨཱོས་ཊྲེལ་ལི་ཡ་ཉིན་སྲུང་ཆུ་ཚོད", "AWST": "ནུབ་ཕྱོགས་ཨཱོས་ཊྲེལ་ལི་ཡ་ཚད་ལྡན་ཆུ་ཚོད", "JST": "ཇ་པཱན་ཚད་ལྡན་ཆུ་ཚོད", "CDT": "བྱང་ཨ་མི་རི་ཀ་དབུས་ཕྱོགས་ཉིན་སྲུང་ཆུ་ཚོད", "AEST": "ཤར་ཕྱོགས་ཕྱོགས་ཨཱོས་ཊྲེལ་ལི་ཡ་ཚད་ལྡན་ཆུ་ཚོད", "COT": "ཀོ་ལོམ་བྷི་ཡ་ཚད་ལྡན་ཆུ་ཚོད", "WARST": "ནུབ་ཕྱོགས་ཨར་ཇེན་ཊི་ན་བྱཱར་དུས་ཆུ་ཚོད", "COST": "ཀོ་ལོམ་བྷི་ཡ་བྱཱར་དུས་ཆུ་ཚོད", "HKT": "HKT", "ACWST": "དབུས་ནུབ་ཕྱོགས་ཨཱོས་ཊྲེལ་ལི་ཡ་ཚད་ལྡན་ཆུ་ཚོད", "GFT": "ཕིརེནཅ་གི་ཡ་ན་ཆུ་ཚོད", "GYT": "གུ་ཡ་ན་ཆུ་ཚོད", "CLST": "ཅི་ལི་བྱཱར་དུས་ཆུ་ཚོད", "WIT": "ཤར་ཕྱོགས་ཨིན་ཌོ་ནེ་ཤི་ཡ་ཆུ་ཚོད", "ARST": "ཨར་ཇེན་ཊི་ན་བྱཱར་དུས་ཆུ་ཚོད", "CHADT": "CHADT", "SGT": "SGT"},
  69. }
  70. }
  71. // Locale returns the current translators string locale
  72. func (dz *dz) Locale() string {
  73. return dz.locale
  74. }
  75. // PluralsCardinal returns the list of cardinal plural rules associated with 'dz'
  76. func (dz *dz) PluralsCardinal() []locales.PluralRule {
  77. return dz.pluralsCardinal
  78. }
  79. // PluralsOrdinal returns the list of ordinal plural rules associated with 'dz'
  80. func (dz *dz) PluralsOrdinal() []locales.PluralRule {
  81. return dz.pluralsOrdinal
  82. }
  83. // PluralsRange returns the list of range plural rules associated with 'dz'
  84. func (dz *dz) PluralsRange() []locales.PluralRule {
  85. return dz.pluralsRange
  86. }
  87. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'dz'
  88. func (dz *dz) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  89. return locales.PluralRuleOther
  90. }
  91. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'dz'
  92. func (dz *dz) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  93. return locales.PluralRuleUnknown
  94. }
  95. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'dz'
  96. func (dz *dz) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  97. return locales.PluralRuleUnknown
  98. }
  99. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  100. func (dz *dz) MonthAbbreviated(month time.Month) string {
  101. return dz.monthsAbbreviated[month]
  102. }
  103. // MonthsAbbreviated returns the locales abbreviated months
  104. func (dz *dz) MonthsAbbreviated() []string {
  105. return dz.monthsAbbreviated[1:]
  106. }
  107. // MonthNarrow returns the locales narrow month given the 'month' provided
  108. func (dz *dz) MonthNarrow(month time.Month) string {
  109. return dz.monthsNarrow[month]
  110. }
  111. // MonthsNarrow returns the locales narrow months
  112. func (dz *dz) MonthsNarrow() []string {
  113. return dz.monthsNarrow[1:]
  114. }
  115. // MonthWide returns the locales wide month given the 'month' provided
  116. func (dz *dz) MonthWide(month time.Month) string {
  117. return dz.monthsWide[month]
  118. }
  119. // MonthsWide returns the locales wide months
  120. func (dz *dz) MonthsWide() []string {
  121. return dz.monthsWide[1:]
  122. }
  123. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  124. func (dz *dz) WeekdayAbbreviated(weekday time.Weekday) string {
  125. return dz.daysAbbreviated[weekday]
  126. }
  127. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  128. func (dz *dz) WeekdaysAbbreviated() []string {
  129. return dz.daysAbbreviated
  130. }
  131. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  132. func (dz *dz) WeekdayNarrow(weekday time.Weekday) string {
  133. return dz.daysNarrow[weekday]
  134. }
  135. // WeekdaysNarrow returns the locales narrow weekdays
  136. func (dz *dz) WeekdaysNarrow() []string {
  137. return dz.daysNarrow
  138. }
  139. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  140. func (dz *dz) WeekdayShort(weekday time.Weekday) string {
  141. return dz.daysShort[weekday]
  142. }
  143. // WeekdaysShort returns the locales short weekdays
  144. func (dz *dz) WeekdaysShort() []string {
  145. return dz.daysShort
  146. }
  147. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  148. func (dz *dz) WeekdayWide(weekday time.Weekday) string {
  149. return dz.daysWide[weekday]
  150. }
  151. // WeekdaysWide returns the locales wide weekdays
  152. func (dz *dz) WeekdaysWide() []string {
  153. return dz.daysWide
  154. }
  155. // FmtNumber returns 'num' with digits/precision of 'v' for 'dz' and handles both Whole and Real numbers based on 'v'
  156. func (dz *dz) FmtNumber(num float64, v uint64) string {
  157. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  158. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  159. count := 0
  160. inWhole := v == 0
  161. inSecondary := false
  162. groupThreshold := 3
  163. b := make([]byte, 0, l)
  164. for i := len(s) - 1; i >= 0; i-- {
  165. if s[i] == '.' {
  166. b = append(b, dz.decimal[0])
  167. inWhole = true
  168. continue
  169. }
  170. if inWhole {
  171. if count == groupThreshold {
  172. b = append(b, dz.group[0])
  173. count = 1
  174. if !inSecondary {
  175. inSecondary = true
  176. groupThreshold = 2
  177. }
  178. } else {
  179. count++
  180. }
  181. }
  182. b = append(b, s[i])
  183. }
  184. if num < 0 {
  185. b = append(b, dz.minus[0])
  186. }
  187. // reverse
  188. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  189. b[i], b[j] = b[j], b[i]
  190. }
  191. return string(b)
  192. }
  193. // FmtPercent returns 'num' with digits/precision of 'v' for 'dz' and handles both Whole and Real numbers based on 'v'
  194. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  195. func (dz *dz) FmtPercent(num float64, v uint64) string {
  196. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  197. l := len(s) + 5
  198. b := make([]byte, 0, l)
  199. for i := len(s) - 1; i >= 0; i-- {
  200. if s[i] == '.' {
  201. b = append(b, dz.decimal[0])
  202. continue
  203. }
  204. b = append(b, s[i])
  205. }
  206. if num < 0 {
  207. b = append(b, dz.minus[0])
  208. }
  209. // reverse
  210. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  211. b[i], b[j] = b[j], b[i]
  212. }
  213. b = append(b, dz.percentSuffix...)
  214. b = append(b, dz.percent...)
  215. return string(b)
  216. }
  217. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'dz'
  218. func (dz *dz) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  219. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  220. symbol := dz.currencies[currency]
  221. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  222. count := 0
  223. inWhole := v == 0
  224. inSecondary := false
  225. groupThreshold := 3
  226. b := make([]byte, 0, l)
  227. for i := len(s) - 1; i >= 0; i-- {
  228. if s[i] == '.' {
  229. b = append(b, dz.decimal[0])
  230. inWhole = true
  231. continue
  232. }
  233. if inWhole {
  234. if count == groupThreshold {
  235. b = append(b, dz.group[0])
  236. count = 1
  237. if !inSecondary {
  238. inSecondary = true
  239. groupThreshold = 2
  240. }
  241. } else {
  242. count++
  243. }
  244. }
  245. b = append(b, s[i])
  246. }
  247. for j := len(symbol) - 1; j >= 0; j-- {
  248. b = append(b, symbol[j])
  249. }
  250. if num < 0 {
  251. b = append(b, dz.minus[0])
  252. }
  253. // reverse
  254. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  255. b[i], b[j] = b[j], b[i]
  256. }
  257. if int(v) < 2 {
  258. if v == 0 {
  259. b = append(b, dz.decimal...)
  260. }
  261. for i := 0; i < 2-int(v); i++ {
  262. b = append(b, '0')
  263. }
  264. }
  265. return string(b)
  266. }
  267. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'dz'
  268. // in accounting notation.
  269. func (dz *dz) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  270. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  271. symbol := dz.currencies[currency]
  272. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  273. count := 0
  274. inWhole := v == 0
  275. inSecondary := false
  276. groupThreshold := 3
  277. b := make([]byte, 0, l)
  278. for i := len(s) - 1; i >= 0; i-- {
  279. if s[i] == '.' {
  280. b = append(b, dz.decimal[0])
  281. inWhole = true
  282. continue
  283. }
  284. if inWhole {
  285. if count == groupThreshold {
  286. b = append(b, dz.group[0])
  287. count = 1
  288. if !inSecondary {
  289. inSecondary = true
  290. groupThreshold = 2
  291. }
  292. } else {
  293. count++
  294. }
  295. }
  296. b = append(b, s[i])
  297. }
  298. if num < 0 {
  299. for j := len(symbol) - 1; j >= 0; j-- {
  300. b = append(b, symbol[j])
  301. }
  302. b = append(b, dz.minus[0])
  303. } else {
  304. for j := len(symbol) - 1; j >= 0; j-- {
  305. b = append(b, symbol[j])
  306. }
  307. }
  308. // reverse
  309. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  310. b[i], b[j] = b[j], b[i]
  311. }
  312. if int(v) < 2 {
  313. if v == 0 {
  314. b = append(b, dz.decimal...)
  315. }
  316. for i := 0; i < 2-int(v); i++ {
  317. b = append(b, '0')
  318. }
  319. }
  320. return string(b)
  321. }
  322. // FmtDateShort returns the short date representation of 't' for 'dz'
  323. func (dz *dz) FmtDateShort(t time.Time) string {
  324. b := make([]byte, 0, 32)
  325. b = strconv.AppendInt(b, int64(t.Year()), 10)
  326. b = append(b, []byte{0x2d}...)
  327. if t.Month() < 10 {
  328. b = append(b, '0')
  329. }
  330. b = strconv.AppendInt(b, int64(t.Month()), 10)
  331. b = append(b, []byte{0x2d}...)
  332. if t.Day() < 10 {
  333. b = append(b, '0')
  334. }
  335. b = strconv.AppendInt(b, int64(t.Day()), 10)
  336. return string(b)
  337. }
  338. // FmtDateMedium returns the medium date representation of 't' for 'dz'
  339. func (dz *dz) FmtDateMedium(t time.Time) string {
  340. b := make([]byte, 0, 32)
  341. b = append(b, []byte{0xe0, 0xbd, 0xa6, 0xe0, 0xbe, 0xa4, 0xe0, 0xbe, 0xb1, 0xe0, 0xbd, 0xb2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0xa3, 0xe0, 0xbd, 0xbc, 0xe0, 0xbc, 0x8b}...)
  342. b = strconv.AppendInt(b, int64(t.Year()), 10)
  343. b = append(b, []byte{0x20, 0xe0, 0xbd, 0x9f, 0xe0, 0xbe, 0xb3, 0xe0, 0xbc, 0x8b}...)
  344. b = append(b, dz.monthsAbbreviated[t.Month()]...)
  345. b = append(b, []byte{0x20, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xba, 0xe0, 0xbd, 0xa6, 0xe0, 0xbc, 0x8b}...)
  346. if t.Day() < 10 {
  347. b = append(b, '0')
  348. }
  349. b = strconv.AppendInt(b, int64(t.Day()), 10)
  350. return string(b)
  351. }
  352. // FmtDateLong returns the long date representation of 't' for 'dz'
  353. func (dz *dz) FmtDateLong(t time.Time) string {
  354. b := make([]byte, 0, 32)
  355. b = append(b, []byte{0xe0, 0xbd, 0xa6, 0xe0, 0xbe, 0xa4, 0xe0, 0xbe, 0xb1, 0xe0, 0xbd, 0xb2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0xa3, 0xe0, 0xbd, 0xbc, 0xe0, 0xbc, 0x8b}...)
  356. b = strconv.AppendInt(b, int64(t.Year()), 10)
  357. b = append(b, []byte{0x20}...)
  358. b = append(b, dz.monthsWide[t.Month()]...)
  359. b = append(b, []byte{0x20, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xba, 0xe0, 0xbd, 0xa6, 0xe0, 0xbc, 0x8b, 0x20}...)
  360. if t.Day() < 10 {
  361. b = append(b, '0')
  362. }
  363. b = strconv.AppendInt(b, int64(t.Day()), 10)
  364. return string(b)
  365. }
  366. // FmtDateFull returns the full date representation of 't' for 'dz'
  367. func (dz *dz) FmtDateFull(t time.Time) string {
  368. b := make([]byte, 0, 32)
  369. b = append(b, dz.daysWide[t.Weekday()]...)
  370. b = append(b, []byte{0x2c, 0x20, 0xe0, 0xbd, 0xa6, 0xe0, 0xbe, 0xa4, 0xe0, 0xbe, 0xb1, 0xe0, 0xbd, 0xb2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0xa3, 0xe0, 0xbd, 0xbc, 0xe0, 0xbc, 0x8b}...)
  371. b = strconv.AppendInt(b, int64(t.Year()), 10)
  372. b = append(b, []byte{0x20}...)
  373. b = append(b, dz.monthsWide[t.Month()]...)
  374. b = append(b, []byte{0x20, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xba, 0xe0, 0xbd, 0xa6, 0xe0, 0xbc, 0x8b}...)
  375. if t.Day() < 10 {
  376. b = append(b, '0')
  377. }
  378. b = strconv.AppendInt(b, int64(t.Day()), 10)
  379. return string(b)
  380. }
  381. // FmtTimeShort returns the short time representation of 't' for 'dz'
  382. func (dz *dz) FmtTimeShort(t time.Time) string {
  383. b := make([]byte, 0, 32)
  384. b = append(b, []byte{0xe0, 0xbd, 0x86, 0xe0, 0xbd, 0xb4, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xbc, 0xe0, 0xbd, 0x91, 0xe0, 0xbc, 0x8b, 0x20}...)
  385. h := t.Hour()
  386. if h > 12 {
  387. h -= 12
  388. }
  389. b = strconv.AppendInt(b, int64(h), 10)
  390. b = append(b, []byte{0x20, 0xe0, 0xbd, 0xa6, 0xe0, 0xbe, 0x90, 0xe0, 0xbd, 0xa2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x98, 0xe0, 0xbc, 0x8b, 0x20}...)
  391. if t.Minute() < 10 {
  392. b = append(b, '0')
  393. }
  394. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  395. b = append(b, []byte{0x20}...)
  396. if t.Hour() < 12 {
  397. b = append(b, dz.periodsAbbreviated[0]...)
  398. } else {
  399. b = append(b, dz.periodsAbbreviated[1]...)
  400. }
  401. return string(b)
  402. }
  403. // FmtTimeMedium returns the medium time representation of 't' for 'dz'
  404. func (dz *dz) FmtTimeMedium(t time.Time) string {
  405. b := make([]byte, 0, 32)
  406. b = append(b, []byte{0xe0, 0xbd, 0x86, 0xe0, 0xbd, 0xb4, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xbc, 0xe0, 0xbd, 0x91, 0xe0, 0xbc, 0x8b}...)
  407. h := t.Hour()
  408. if h > 12 {
  409. h -= 12
  410. }
  411. b = strconv.AppendInt(b, int64(h), 10)
  412. b = append(b, dz.timeSeparator...)
  413. if t.Minute() < 10 {
  414. b = append(b, '0')
  415. }
  416. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  417. b = append(b, dz.timeSeparator...)
  418. if t.Second() < 10 {
  419. b = append(b, '0')
  420. }
  421. b = strconv.AppendInt(b, int64(t.Second()), 10)
  422. b = append(b, []byte{0x20}...)
  423. if t.Hour() < 12 {
  424. b = append(b, dz.periodsAbbreviated[0]...)
  425. } else {
  426. b = append(b, dz.periodsAbbreviated[1]...)
  427. }
  428. return string(b)
  429. }
  430. // FmtTimeLong returns the long time representation of 't' for 'dz'
  431. func (dz *dz) FmtTimeLong(t time.Time) string {
  432. b := make([]byte, 0, 32)
  433. b = append(b, []byte{0xe0, 0xbd, 0x86, 0xe0, 0xbd, 0xb4, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xbc, 0xe0, 0xbd, 0x91, 0xe0, 0xbc, 0x8b, 0x20}...)
  434. h := t.Hour()
  435. if h > 12 {
  436. h -= 12
  437. }
  438. b = strconv.AppendInt(b, int64(h), 10)
  439. b = append(b, []byte{0x20, 0xe0, 0xbd, 0xa6, 0xe0, 0xbe, 0x90, 0xe0, 0xbd, 0xa2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x98, 0xe0, 0xbc, 0x8b, 0x20}...)
  440. if t.Minute() < 10 {
  441. b = append(b, '0')
  442. }
  443. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  444. b = append(b, dz.timeSeparator...)
  445. if t.Second() < 10 {
  446. b = append(b, '0')
  447. }
  448. b = strconv.AppendInt(b, int64(t.Second()), 10)
  449. b = append(b, []byte{0x20}...)
  450. if t.Hour() < 12 {
  451. b = append(b, dz.periodsAbbreviated[0]...)
  452. } else {
  453. b = append(b, dz.periodsAbbreviated[1]...)
  454. }
  455. b = append(b, []byte{0x20}...)
  456. tz, _ := t.Zone()
  457. b = append(b, tz...)
  458. return string(b)
  459. }
  460. // FmtTimeFull returns the full time representation of 't' for 'dz'
  461. func (dz *dz) FmtTimeFull(t time.Time) string {
  462. b := make([]byte, 0, 32)
  463. b = append(b, []byte{0xe0, 0xbd, 0x86, 0xe0, 0xbd, 0xb4, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xbc, 0xe0, 0xbd, 0x91, 0xe0, 0xbc, 0x8b, 0x20}...)
  464. h := t.Hour()
  465. if h > 12 {
  466. h -= 12
  467. }
  468. b = strconv.AppendInt(b, int64(h), 10)
  469. b = append(b, []byte{0x20, 0xe0, 0xbd, 0xa6, 0xe0, 0xbe, 0x90, 0xe0, 0xbd, 0xa2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x98, 0xe0, 0xbc, 0x8b, 0x20}...)
  470. if t.Minute() < 10 {
  471. b = append(b, '0')
  472. }
  473. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  474. b = append(b, dz.timeSeparator...)
  475. if t.Second() < 10 {
  476. b = append(b, '0')
  477. }
  478. b = strconv.AppendInt(b, int64(t.Second()), 10)
  479. b = append(b, []byte{0x20}...)
  480. if t.Hour() < 12 {
  481. b = append(b, dz.periodsAbbreviated[0]...)
  482. } else {
  483. b = append(b, dz.periodsAbbreviated[1]...)
  484. }
  485. b = append(b, []byte{0x20}...)
  486. tz, _ := t.Zone()
  487. if btz, ok := dz.timezones[tz]; ok {
  488. b = append(b, btz...)
  489. } else {
  490. b = append(b, tz...)
  491. }
  492. return string(b)
  493. }