1package ml
2
3import (
4	"math"
5	"strconv"
6	"time"
7
8	"github.com/go-playground/locales"
9	"github.com/go-playground/locales/currency"
10)
11
12type ml struct {
13	locale                 string
14	pluralsCardinal        []locales.PluralRule
15	pluralsOrdinal         []locales.PluralRule
16	pluralsRange           []locales.PluralRule
17	decimal                string
18	group                  string
19	minus                  string
20	percent                string
21	perMille               string
22	timeSeparator          string
23	inifinity              string
24	currencies             []string // idx = enum of currency code
25	currencyNegativePrefix string
26	currencyNegativeSuffix string
27	monthsAbbreviated      []string
28	monthsNarrow           []string
29	monthsWide             []string
30	daysAbbreviated        []string
31	daysNarrow             []string
32	daysShort              []string
33	daysWide               []string
34	periodsAbbreviated     []string
35	periodsNarrow          []string
36	periodsShort           []string
37	periodsWide            []string
38	erasAbbreviated        []string
39	erasNarrow             []string
40	erasWide               []string
41	timezones              map[string]string
42}
43
44// New returns a new instance of translator for the 'ml' locale
45func New() locales.Translator {
46	return &ml{
47		locale:                 "ml",
48		pluralsCardinal:        []locales.PluralRule{2, 6},
49		pluralsOrdinal:         []locales.PluralRule{6},
50		pluralsRange:           []locales.PluralRule{2, 6},
51		decimal:                ".",
52		group:                  ",",
53		minus:                  "-",
54		percent:                "%",
55		perMille:               "‰",
56		timeSeparator:          ":",
57		inifinity:              "∞",
58		currencies:             []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "A$", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "R$", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CA$", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CN¥", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "€", "FIM", "FJD", "FKP", "FRF", "£", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HK$", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "₪", "₹", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "₩", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "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", "STN", "SUR", "SVC", "SYP", "SZL", "฿", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "NT$", "TZS", "UAH", "UAK", "UGS", "UGX", "$", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "₫", "VNN", "VUV", "WST", "FCFA", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "EC$", "XDR", "XEU", "XFO", "XFU", "CFA", "XPD", "CFPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
59		currencyNegativePrefix: "(",
60		currencyNegativeSuffix: ")",
61		monthsAbbreviated:      []string{"", "ജനു", "ഫെബ്രു", "മാർ", "ഏപ്രി", "മേയ്", "ജൂൺ", "ജൂലൈ", "ഓഗ", "സെപ്റ്റം", "ഒക്ടോ", "നവം", "ഡിസം"},
62		monthsNarrow:           []string{"", "ജ", "ഫെ", "മാ", "ഏ", "മെ", "ജൂൺ", "ജൂ", "ഓ", "സെ", "ഒ", "ന", "ഡി"},
63		monthsWide:             []string{"", "ജനുവരി", "ഫെബ്രുവരി", "മാർച്ച്", "ഏപ്രിൽ", "മേയ്", "ജൂൺ", "ജൂലൈ", "ഓഗസ്റ്റ്", "സെപ്റ്റംബർ", "ഒക്\u200cടോബർ", "നവംബർ", "ഡിസംബർ"},
64		daysAbbreviated:        []string{"ഞായർ", "തിങ്കൾ", "ചൊവ്വ", "ബുധൻ", "വ്യാഴം", "വെള്ളി", "ശനി"},
65		daysNarrow:             []string{"ഞ", "തി", "ചൊ", "ബു", "വ്യാ", "വെ", "ശ"},
66		daysShort:              []string{"ഞാ", "തി", "ചൊ", "ബു", "വ്യാ", "വെ", "ശ"},
67		daysWide:               []string{"ഞായറാഴ്\u200cച", "തിങ്കളാഴ്\u200cച", "ചൊവ്വാഴ്ച", "ബുധനാഴ്\u200cച", "വ്യാഴാഴ്\u200cച", "വെള്ളിയാഴ്\u200cച", "ശനിയാഴ്\u200cച"},
68		periodsAbbreviated:     []string{"AM", "PM"},
69		periodsNarrow:          []string{"AM", "PM"},
70		periodsWide:            []string{"AM", "PM"},
71		erasAbbreviated:        []string{"ക്രി.മു.", "എഡി"},
72		erasNarrow:             []string{"ക്രി.മു.", "എഡി"},
73		erasWide:               []string{"ക്രിസ്\u200cതുവിന് മുമ്പ്", "ആന്നോ ഡൊമിനി"},
74		timezones:              map[string]string{"HEEG": "കിഴക്കൻ ഗ്രീൻലാൻഡ് ഗ്രീഷ്\u200cമകാല സമയം", "GYT": "ഗയാന സമയം", "AWDT": "ഓസ്\u200cട്രേലിയൻ പടിഞ്ഞാറൻ ഡേലൈറ്റ് സമയം", "AKDT": "അലാസ്\u200cക ഡേലൈറ്റ് സമയം", "ACDT": "ഓസ്ട്രേലിയൻ സെൻട്രൽ ഡേലൈറ്റ് സമയം", "CST": "വടക്കെ അമേരിക്കൻ സെൻട്രൽ സ്റ്റാൻഡേർഡ് സമയം", "WAST": "പടിഞ്ഞാറൻ ആഫ്രിക്ക ഗ്രീഷ്\u200cമകാല സമയം", "WART": "പടിഞ്ഞാറൻ അർജന്റീന സ്റ്റാൻഡേർഡ് സമയം", "HEPM": "സെന്റ് പിയറി ആൻഡ് മിക്വലൻ ഡേലൈറ്റ് സമയം", "CLST": "ചിലി ഗ്രീഷ്\u200cമകാല സമയം", "OESZ": "കിഴക്കൻ യൂറോപ്യൻ ഗ്രീഷ്മകാല സമയം", "MESZ": "സെൻട്രൽ യൂറോപ്യൻ ഗ്രീഷ്മകാല സമയം", "HKST": "ഹോങ്കോങ്ങ് ഗ്രീഷ്\u200cമകാല സമയം", "HENOMX": "വടക്കുപടിഞ്ഞാറൻ മെക്സിക്കൻ ഡേലൈറ്റ് സമയം", "CDT": "വടക്കെ അമേരിക്കൻ സെൻട്രൽ ഡേലൈറ്റ് സമയം", "EST": "വടക്കെ അമേരിക്കൻ കിഴക്കൻ സ്റ്റാൻഡേർഡ് സമയം", "MEZ": "സെൻട്രൽ യൂറോപ്യൻ സ്റ്റാൻഡേർഡ് സമയം", "LHDT": "ലോർഡ് ഹോവ് ഡേലൈറ്റ് സമയം", "MDT": "മകൌ വേനൽക്കാല സമയം", "COT": "കൊളംബിയ സ്റ്റാൻഡേർഡ് സമയം", "MYT": "മലേഷ്യ സമയം", "HAST": "ഹവായ്-അലൂഷ്യൻ സ്റ്റാൻഡേർഡ് സമയം", "HADT": "ഹവായ്-അലൂഷ്യൻ ഡേലൈറ്റ് സമയം", "ART": "അർജന്റീന സ്റ്റാൻഡേർഡ് സമയം", "AST": "അറ്റ്\u200cലാന്റിക് സ്റ്റാൻഡേർഡ് സമയം", "∅∅∅": "പെറു ഗ്രീഷ്\u200cമകാല സമയം", "CLT": "ചിലി സ്റ്റാൻഡേർഡ് സമയം", "TMT": "തുർക്ക്\u200cമെനിസ്ഥാൻ സ്റ്റാൻഡേർഡ് സമയം", "TMST": "തുർക്ക്\u200cമെനിസ്ഥാൻ ഗ്രീഷ്\u200cമകാല സമയം", "JDT": "ജപ്പാൻ ഡേലൈറ്റ് സമയം", "HKT": "ഹോങ്കോങ്ങ് സ്റ്റാൻഡേർഡ് സമയം", "ACWDT": "ഓസ്ട്രേലിയൻ സെൻട്രൽ പടിഞ്ഞാറൻ ഡേലൈറ്റ് സമയം", "HNEG": "കിഴക്കൻ ഗ്രീൻലാൻഡ് സ്റ്റാൻഡേർഡ് സമയം", "WARST": "പടിഞ്ഞാറൻ അർജന്റീന ഗ്രീഷ്\u200cമകാല സമയം", "JST": "ജപ്പാൻ സ്റ്റാൻഡേർഡ് സമയം", "NZDT": "ന്യൂസിലാൻഡ് ഡേലൈറ്റ് സമയം", "ACWST": "ഓസ്ട്രേലിയൻ സെൻട്രൽ പടിഞ്ഞാറൻ സ്റ്റാൻഡേർഡ് സമയം", "GFT": "ഫ്രഞ്ച് ഗയാന സമയം", "ECT": "ഇക്വഡോർ സമയം", "HNNOMX": "വടക്കുപടിഞ്ഞാറൻ മെക്\u200cസിക്കൻ സ്റ്റാൻഡേർഡ് സമയം", "SRT": "സുരിനെയിം സമയം", "ADT": "അറ്റ്\u200cലാന്റിക് ഡേലൈറ്റ് സമയം", "WEZ": "പടിഞ്ഞാറൻ യൂറോപ്യൻ സ്റ്റാൻഡേർഡ് സമയം", "IST": "ഇന്ത്യൻ സ്റ്റാൻഡേർഡ് സമയം", "OEZ": "കിഴക്കൻ യൂറോപ്യൻ സ്റ്റാൻഡേർഡ് സമയം", "CHADT": "ചാത്തം ഗ്രീഷ്\u200cമകാല സമയം", "AEST": "ഓസ്\u200cട്രേലിയൻ കിഴക്കൻ സ്റ്റാൻഡേർഡ് സമയം", "MST": "മകൌ സ്റ്റാൻഡേർഡ് സമയം", "GMT": "ഗ്രീൻവിച്ച് മീൻ സമയം", "SAST": "ദക്ഷിണാഫ്രിക്ക സ്റ്റാൻഡേർഡ് സമയം", "PDT": "വടക്കെ അമേരിക്കൻ പസഫിക് ഡേലൈറ്റ് സമയം", "HEPMX": "മെക്സിക്കൻ പസഫിക് ഡേലൈറ്റ് സമയം", "LHST": "ലോർഡ് ഹോവ് സ്റ്റാൻഡേർഡ് സമയം", "WIT": "കിഴക്കൻ ഇന്തോനേഷ്യ സമയം", "COST": "കൊളംബിയ ഗ്രീഷ്\u200cമകാല സമയം", "UYST": "ഉറുഗ്വേ ഗ്രീഷ്\u200cമകാല സമയം", "HECU": "ക്യൂബ ഡേലൈറ്റ് സമയം", "HNPMX": "മെക്\u200cസിക്കൻ പസഫിക് സ്റ്റാൻഡേർഡ് സമയം", "AEDT": "ഓസ്\u200cട്രേലിയൻ കിഴക്കൻ ഡേലൈറ്റ് സമയം", "WAT": "പടിഞ്ഞാറൻ ആഫ്രിക്ക സ്റ്റാൻഡേർഡ് സമയം", "HNT": "ന്യൂഫൗണ്ട്\u200cലാന്റ് സ്റ്റാൻഡേർഡ് സമയം", "VET": "വെനിസ്വേല സമയം", "ARST": "അർജന്റീന ഗ്രീഷ്\u200cമകാല സമയം", "HNCU": "ക്യൂബ സ്റ്റാൻഡേർഡ് സമയം", "HNOG": "പടിഞ്ഞാറൻ ഗ്രീൻലാൻഡ് സ്റ്റാൻഡേർഡ് സമയം", "ACST": "ഓസ്ട്രേലിയൻ സെൻട്രൽ സ്റ്റാൻഡേർഡ് സമയം", "WITA": "മധ്യ ഇന്തോനേഷ്യ സമയം", "CAT": "മധ്യ ആഫ്രിക്ക സമയം", "EAT": "കിഴക്കൻ ആഫ്രിക്ക സമയം", "AKST": "അലാസ്ക സ്റ്റാൻഡേർഡ് സമയം", "AWST": "ഓസ്\u200cട്രേലിയൻ പടിഞ്ഞാറൻ സ്റ്റാൻഡേർഡ് സമയം", "WIB": "പടിഞ്ഞാറൻ ഇന്തോനേഷ്യ സമയം", "EDT": "വടക്കെ അമേരിക്കൻ കിഴക്കൻ ഡേലൈറ്റ് സമയം", "HEOG": "പടിഞ്ഞാറൻ ഗ്രീൻലാൻഡ് ഗ്രീഷ്\u200cമകാല സമയം", "HAT": "ന്യൂഫൗണ്ട്\u200cലാന്റ് ഡേലൈറ്റ് സമയം", "PST": "വടക്കെ അമേരിക്കൻ പസഫിക് സ്റ്റാൻഡേർഡ് സമയം", "BT": "ഭൂട്ടാൻ സമയം", "BOT": "ബൊളീവിയ സമയം", "NZST": "ന്യൂസിലാൻഡ് സ്റ്റാൻഡേർഡ് സമയം", "SGT": "സിംഗപ്പൂർ സ്റ്റാൻഡേർഡ് സമയം", "HNPM": "സെന്റ് പിയറി ആൻഡ് മിക്വലൻ സ്റ്റാൻഡേർഡ് സമയം", "UYT": "ഉറുഗ്വേ സ്റ്റാൻഡേർഡ് സമയം", "CHAST": "ചാത്തം സ്റ്റാൻഡേർഡ് സമയം", "WESZ": "പടിഞ്ഞാറൻ യൂറോപ്യൻ ഗ്രീഷ്\u200cമകാല സമയം", "ChST": "ചമോറോ സ്റ്റാൻഡേർഡ് സമയം"},
75	}
76}
77
78// Locale returns the current translators string locale
79func (ml *ml) Locale() string {
80	return ml.locale
81}
82
83// PluralsCardinal returns the list of cardinal plural rules associated with 'ml'
84func (ml *ml) PluralsCardinal() []locales.PluralRule {
85	return ml.pluralsCardinal
86}
87
88// PluralsOrdinal returns the list of ordinal plural rules associated with 'ml'
89func (ml *ml) PluralsOrdinal() []locales.PluralRule {
90	return ml.pluralsOrdinal
91}
92
93// PluralsRange returns the list of range plural rules associated with 'ml'
94func (ml *ml) PluralsRange() []locales.PluralRule {
95	return ml.pluralsRange
96}
97
98// CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'ml'
99func (ml *ml) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
100
101	n := math.Abs(num)
102
103	if n == 1 {
104		return locales.PluralRuleOne
105	}
106
107	return locales.PluralRuleOther
108}
109
110// OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'ml'
111func (ml *ml) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
112	return locales.PluralRuleOther
113}
114
115// RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'ml'
116func (ml *ml) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
117
118	start := ml.CardinalPluralRule(num1, v1)
119	end := ml.CardinalPluralRule(num2, v2)
120
121	if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
122		return locales.PluralRuleOther
123	} else if start == locales.PluralRuleOther && end == locales.PluralRuleOne {
124		return locales.PluralRuleOne
125	}
126
127	return locales.PluralRuleOther
128
129}
130
131// MonthAbbreviated returns the locales abbreviated month given the 'month' provided
132func (ml *ml) MonthAbbreviated(month time.Month) string {
133	return ml.monthsAbbreviated[month]
134}
135
136// MonthsAbbreviated returns the locales abbreviated months
137func (ml *ml) MonthsAbbreviated() []string {
138	return ml.monthsAbbreviated[1:]
139}
140
141// MonthNarrow returns the locales narrow month given the 'month' provided
142func (ml *ml) MonthNarrow(month time.Month) string {
143	return ml.monthsNarrow[month]
144}
145
146// MonthsNarrow returns the locales narrow months
147func (ml *ml) MonthsNarrow() []string {
148	return ml.monthsNarrow[1:]
149}
150
151// MonthWide returns the locales wide month given the 'month' provided
152func (ml *ml) MonthWide(month time.Month) string {
153	return ml.monthsWide[month]
154}
155
156// MonthsWide returns the locales wide months
157func (ml *ml) MonthsWide() []string {
158	return ml.monthsWide[1:]
159}
160
161// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
162func (ml *ml) WeekdayAbbreviated(weekday time.Weekday) string {
163	return ml.daysAbbreviated[weekday]
164}
165
166// WeekdaysAbbreviated returns the locales abbreviated weekdays
167func (ml *ml) WeekdaysAbbreviated() []string {
168	return ml.daysAbbreviated
169}
170
171// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
172func (ml *ml) WeekdayNarrow(weekday time.Weekday) string {
173	return ml.daysNarrow[weekday]
174}
175
176// WeekdaysNarrow returns the locales narrow weekdays
177func (ml *ml) WeekdaysNarrow() []string {
178	return ml.daysNarrow
179}
180
181// WeekdayShort returns the locales short weekday given the 'weekday' provided
182func (ml *ml) WeekdayShort(weekday time.Weekday) string {
183	return ml.daysShort[weekday]
184}
185
186// WeekdaysShort returns the locales short weekdays
187func (ml *ml) WeekdaysShort() []string {
188	return ml.daysShort
189}
190
191// WeekdayWide returns the locales wide weekday given the 'weekday' provided
192func (ml *ml) WeekdayWide(weekday time.Weekday) string {
193	return ml.daysWide[weekday]
194}
195
196// WeekdaysWide returns the locales wide weekdays
197func (ml *ml) WeekdaysWide() []string {
198	return ml.daysWide
199}
200
201// Decimal returns the decimal point of number
202func (ml *ml) Decimal() string {
203	return ml.decimal
204}
205
206// Group returns the group of number
207func (ml *ml) Group() string {
208	return ml.group
209}
210
211// Group returns the minus sign of number
212func (ml *ml) Minus() string {
213	return ml.minus
214}
215
216// FmtNumber returns 'num' with digits/precision of 'v' for 'ml' and handles both Whole and Real numbers based on 'v'
217func (ml *ml) FmtNumber(num float64, v uint64) string {
218
219	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
220	l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
221	count := 0
222	inWhole := v == 0
223	inSecondary := false
224	groupThreshold := 3
225
226	b := make([]byte, 0, l)
227
228	for i := len(s) - 1; i >= 0; i-- {
229
230		if s[i] == '.' {
231			b = append(b, ml.decimal[0])
232			inWhole = true
233			continue
234		}
235
236		if inWhole {
237
238			if count == groupThreshold {
239				b = append(b, ml.group[0])
240				count = 1
241
242				if !inSecondary {
243					inSecondary = true
244					groupThreshold = 2
245				}
246			} else {
247				count++
248			}
249		}
250
251		b = append(b, s[i])
252	}
253
254	if num < 0 {
255		b = append(b, ml.minus[0])
256	}
257
258	// reverse
259	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
260		b[i], b[j] = b[j], b[i]
261	}
262
263	return string(b)
264}
265
266// FmtPercent returns 'num' with digits/precision of 'v' for 'ml' and handles both Whole and Real numbers based on 'v'
267// NOTE: 'num' passed into FmtPercent is assumed to be in percent already
268func (ml *ml) FmtPercent(num float64, v uint64) string {
269	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
270	l := len(s) + 3
271	b := make([]byte, 0, l)
272
273	for i := len(s) - 1; i >= 0; i-- {
274
275		if s[i] == '.' {
276			b = append(b, ml.decimal[0])
277			continue
278		}
279
280		b = append(b, s[i])
281	}
282
283	if num < 0 {
284		b = append(b, ml.minus[0])
285	}
286
287	// reverse
288	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
289		b[i], b[j] = b[j], b[i]
290	}
291
292	b = append(b, ml.percent...)
293
294	return string(b)
295}
296
297// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'ml'
298func (ml *ml) FmtCurrency(num float64, v uint64, currency currency.Type) string {
299
300	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
301	symbol := ml.currencies[currency]
302	l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
303	count := 0
304	inWhole := v == 0
305	b := make([]byte, 0, l)
306
307	for i := len(s) - 1; i >= 0; i-- {
308
309		if s[i] == '.' {
310			b = append(b, ml.decimal[0])
311			inWhole = true
312			continue
313		}
314
315		if inWhole {
316			if count == 3 {
317				b = append(b, ml.group[0])
318				count = 1
319			} else {
320				count++
321			}
322		}
323
324		b = append(b, s[i])
325	}
326
327	for j := len(symbol) - 1; j >= 0; j-- {
328		b = append(b, symbol[j])
329	}
330
331	if num < 0 {
332		b = append(b, ml.minus[0])
333	}
334
335	// reverse
336	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
337		b[i], b[j] = b[j], b[i]
338	}
339
340	if int(v) < 2 {
341
342		if v == 0 {
343			b = append(b, ml.decimal...)
344		}
345
346		for i := 0; i < 2-int(v); i++ {
347			b = append(b, '0')
348		}
349	}
350
351	return string(b)
352}
353
354// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'ml'
355// in accounting notation.
356func (ml *ml) FmtAccounting(num float64, v uint64, currency currency.Type) string {
357
358	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
359	symbol := ml.currencies[currency]
360	l := len(s) + len(symbol) + 4 + 1*len(s[:len(s)-int(v)-1])/3
361	count := 0
362	inWhole := v == 0
363	b := make([]byte, 0, l)
364
365	for i := len(s) - 1; i >= 0; i-- {
366
367		if s[i] == '.' {
368			b = append(b, ml.decimal[0])
369			inWhole = true
370			continue
371		}
372
373		if inWhole {
374			if count == 3 {
375				b = append(b, ml.group[0])
376				count = 1
377			} else {
378				count++
379			}
380		}
381
382		b = append(b, s[i])
383	}
384
385	if num < 0 {
386
387		for j := len(symbol) - 1; j >= 0; j-- {
388			b = append(b, symbol[j])
389		}
390
391		b = append(b, ml.currencyNegativePrefix[0])
392
393	} else {
394
395		for j := len(symbol) - 1; j >= 0; j-- {
396			b = append(b, symbol[j])
397		}
398
399	}
400
401	// reverse
402	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
403		b[i], b[j] = b[j], b[i]
404	}
405
406	if int(v) < 2 {
407
408		if v == 0 {
409			b = append(b, ml.decimal...)
410		}
411
412		for i := 0; i < 2-int(v); i++ {
413			b = append(b, '0')
414		}
415	}
416
417	if num < 0 {
418		b = append(b, ml.currencyNegativeSuffix...)
419	}
420
421	return string(b)
422}
423
424// FmtDateShort returns the short date representation of 't' for 'ml'
425func (ml *ml) FmtDateShort(t time.Time) string {
426
427	b := make([]byte, 0, 32)
428
429	b = strconv.AppendInt(b, int64(t.Day()), 10)
430	b = append(b, []byte{0x2f}...)
431	b = strconv.AppendInt(b, int64(t.Month()), 10)
432	b = append(b, []byte{0x2f}...)
433
434	if t.Year() > 9 {
435		b = append(b, strconv.Itoa(t.Year())[2:]...)
436	} else {
437		b = append(b, strconv.Itoa(t.Year())[1:]...)
438	}
439
440	return string(b)
441}
442
443// FmtDateMedium returns the medium date representation of 't' for 'ml'
444func (ml *ml) FmtDateMedium(t time.Time) string {
445
446	b := make([]byte, 0, 32)
447
448	if t.Year() > 0 {
449		b = strconv.AppendInt(b, int64(t.Year()), 10)
450	} else {
451		b = strconv.AppendInt(b, int64(-t.Year()), 10)
452	}
453
454	b = append(b, []byte{0x2c, 0x20}...)
455	b = append(b, ml.monthsAbbreviated[t.Month()]...)
456	b = append(b, []byte{0x20}...)
457	b = strconv.AppendInt(b, int64(t.Day()), 10)
458
459	return string(b)
460}
461
462// FmtDateLong returns the long date representation of 't' for 'ml'
463func (ml *ml) FmtDateLong(t time.Time) string {
464
465	b := make([]byte, 0, 32)
466
467	if t.Year() > 0 {
468		b = strconv.AppendInt(b, int64(t.Year()), 10)
469	} else {
470		b = strconv.AppendInt(b, int64(-t.Year()), 10)
471	}
472
473	b = append(b, []byte{0x2c, 0x20}...)
474	b = append(b, ml.monthsWide[t.Month()]...)
475	b = append(b, []byte{0x20}...)
476	b = strconv.AppendInt(b, int64(t.Day()), 10)
477
478	return string(b)
479}
480
481// FmtDateFull returns the full date representation of 't' for 'ml'
482func (ml *ml) FmtDateFull(t time.Time) string {
483
484	b := make([]byte, 0, 32)
485
486	if t.Year() > 0 {
487		b = strconv.AppendInt(b, int64(t.Year()), 10)
488	} else {
489		b = strconv.AppendInt(b, int64(-t.Year()), 10)
490	}
491
492	b = append(b, []byte{0x2c, 0x20}...)
493	b = append(b, ml.monthsWide[t.Month()]...)
494	b = append(b, []byte{0x20}...)
495	b = strconv.AppendInt(b, int64(t.Day()), 10)
496	b = append(b, []byte{0x2c, 0x20}...)
497	b = append(b, ml.daysWide[t.Weekday()]...)
498
499	return string(b)
500}
501
502// FmtTimeShort returns the short time representation of 't' for 'ml'
503func (ml *ml) FmtTimeShort(t time.Time) string {
504
505	b := make([]byte, 0, 32)
506
507	h := t.Hour()
508
509	if h > 12 {
510		h -= 12
511	}
512
513	b = strconv.AppendInt(b, int64(h), 10)
514	b = append(b, ml.timeSeparator...)
515
516	if t.Minute() < 10 {
517		b = append(b, '0')
518	}
519
520	b = strconv.AppendInt(b, int64(t.Minute()), 10)
521	b = append(b, []byte{0x20}...)
522
523	if t.Hour() < 12 {
524		b = append(b, ml.periodsAbbreviated[0]...)
525	} else {
526		b = append(b, ml.periodsAbbreviated[1]...)
527	}
528
529	return string(b)
530}
531
532// FmtTimeMedium returns the medium time representation of 't' for 'ml'
533func (ml *ml) FmtTimeMedium(t time.Time) string {
534
535	b := make([]byte, 0, 32)
536
537	h := t.Hour()
538
539	if h > 12 {
540		h -= 12
541	}
542
543	b = strconv.AppendInt(b, int64(h), 10)
544	b = append(b, ml.timeSeparator...)
545
546	if t.Minute() < 10 {
547		b = append(b, '0')
548	}
549
550	b = strconv.AppendInt(b, int64(t.Minute()), 10)
551	b = append(b, ml.timeSeparator...)
552
553	if t.Second() < 10 {
554		b = append(b, '0')
555	}
556
557	b = strconv.AppendInt(b, int64(t.Second()), 10)
558	b = append(b, []byte{0x20}...)
559
560	if t.Hour() < 12 {
561		b = append(b, ml.periodsAbbreviated[0]...)
562	} else {
563		b = append(b, ml.periodsAbbreviated[1]...)
564	}
565
566	return string(b)
567}
568
569// FmtTimeLong returns the long time representation of 't' for 'ml'
570func (ml *ml) FmtTimeLong(t time.Time) string {
571
572	b := make([]byte, 0, 32)
573
574	h := t.Hour()
575
576	if h > 12 {
577		h -= 12
578	}
579
580	b = strconv.AppendInt(b, int64(h), 10)
581	b = append(b, ml.timeSeparator...)
582
583	if t.Minute() < 10 {
584		b = append(b, '0')
585	}
586
587	b = strconv.AppendInt(b, int64(t.Minute()), 10)
588	b = append(b, ml.timeSeparator...)
589
590	if t.Second() < 10 {
591		b = append(b, '0')
592	}
593
594	b = strconv.AppendInt(b, int64(t.Second()), 10)
595	b = append(b, []byte{0x20}...)
596
597	if t.Hour() < 12 {
598		b = append(b, ml.periodsAbbreviated[0]...)
599	} else {
600		b = append(b, ml.periodsAbbreviated[1]...)
601	}
602
603	b = append(b, []byte{0x20}...)
604
605	tz, _ := t.Zone()
606	b = append(b, tz...)
607
608	return string(b)
609}
610
611// FmtTimeFull returns the full time representation of 't' for 'ml'
612func (ml *ml) FmtTimeFull(t time.Time) string {
613
614	b := make([]byte, 0, 32)
615
616	h := t.Hour()
617
618	if h > 12 {
619		h -= 12
620	}
621
622	b = strconv.AppendInt(b, int64(h), 10)
623	b = append(b, ml.timeSeparator...)
624
625	if t.Minute() < 10 {
626		b = append(b, '0')
627	}
628
629	b = strconv.AppendInt(b, int64(t.Minute()), 10)
630	b = append(b, ml.timeSeparator...)
631
632	if t.Second() < 10 {
633		b = append(b, '0')
634	}
635
636	b = strconv.AppendInt(b, int64(t.Second()), 10)
637	b = append(b, []byte{0x20}...)
638
639	if t.Hour() < 12 {
640		b = append(b, ml.periodsAbbreviated[0]...)
641	} else {
642		b = append(b, ml.periodsAbbreviated[1]...)
643	}
644
645	b = append(b, []byte{0x20}...)
646
647	tz, _ := t.Zone()
648
649	if btz, ok := ml.timezones[tz]; ok {
650		b = append(b, btz...)
651	} else {
652		b = append(b, tz...)
653	}
654
655	return string(b)
656}
657