kn.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. package kn
  2. import (
  3. "math"
  4. "strconv"
  5. "time"
  6. "github.com/go-playground/locales"
  7. "github.com/go-playground/locales/currency"
  8. )
  9. type kn 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. monthsAbbreviated []string
  23. monthsNarrow []string
  24. monthsWide []string
  25. daysAbbreviated []string
  26. daysNarrow []string
  27. daysShort []string
  28. daysWide []string
  29. periodsAbbreviated []string
  30. periodsNarrow []string
  31. periodsShort []string
  32. periodsWide []string
  33. erasAbbreviated []string
  34. erasNarrow []string
  35. erasWide []string
  36. timezones map[string]string
  37. }
  38. // New returns a new instance of translator for the 'kn' locale
  39. func New() locales.Translator {
  40. return &kn{
  41. locale: "kn",
  42. pluralsCardinal: []locales.PluralRule{2, 6},
  43. pluralsOrdinal: []locales.PluralRule{6},
  44. pluralsRange: []locales.PluralRule{2, 6},
  45. decimal: ".",
  46. group: ",",
  47. minus: "-",
  48. percent: "%",
  49. perMille: "‰",
  50. timeSeparator: ":",
  51. inifinity: "∞",
  52. 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", "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", "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"},
  53. monthsAbbreviated: []string{"", "ಜನವರಿ", "ಫೆಬ್ರವರಿ", "ಮಾರ್ಚ್", "ಏಪ್ರಿ", "ಮೇ", "ಜೂನ್", "ಜುಲೈ", "ಆಗ", "ಸೆಪ್ಟೆಂ", "ಅಕ್ಟೋ", "ನವೆಂ", "ಡಿಸೆಂ"},
  54. monthsNarrow: []string{"", "ಜ", "ಫೆ", "ಮಾ", "ಏ", "ಮೇ", "ಜೂ", "ಜು", "ಆ", "ಸೆ", "ಅ", "ನ", "ಡಿ"},
  55. monthsWide: []string{"", "ಜನವರಿ", "ಫೆಬ್ರವರಿ", "ಮಾರ್ಚ್", "ಏಪ್ರಿಲ್", "ಮೇ", "ಜೂನ್", "ಜುಲೈ", "ಆಗಸ್ಟ್", "ಸೆಪ್ಟೆಂಬರ್", "ಅಕ್ಟೋಬರ್", "ನವೆಂಬರ್", "ಡಿಸೆಂಬರ್"},
  56. daysAbbreviated: []string{"ಭಾನು", "ಸೋಮ", "ಮಂಗಳ", "ಬುಧ", "ಗುರು", "ಶುಕ್ರ", "ಶನಿ"},
  57. daysNarrow: []string{"ಭಾ", "ಸೋ", "ಮಂ", "ಬು", "ಗು", "ಶು", "ಶ"},
  58. daysShort: []string{"ಭಾನು", "ಸೋಮ", "ಮಂಗಳ", "ಬುಧ", "ಗುರು", "ಶುಕ್ರ", "ಶನಿ"},
  59. daysWide: []string{"ಭಾನುವಾರ", "ಸೋಮವಾರ", "ಮಂಗಳವಾರ", "ಬುಧವಾರ", "ಗುರುವಾರ", "ಶುಕ್ರವಾರ", "ಶನಿವಾರ"},
  60. periodsAbbreviated: []string{"ಪೂರ್ವಾಹ್ನ", "ಅಪರಾಹ್ನ"},
  61. periodsNarrow: []string{"ಪೂ", "ಅ"},
  62. periodsWide: []string{"ಪೂರ್ವಾಹ್ನ", "ಅಪರಾಹ್ನ"},
  63. erasAbbreviated: []string{"ಕ್ರಿ.ಪೂ", "ಕ್ರಿ.ಶ"},
  64. erasNarrow: []string{"", ""},
  65. erasWide: []string{"ಕ್ರಿಸ್ತ ಪೂರ್ವ", "ಕ್ರಿಸ್ತ ಶಕ"},
  66. timezones: map[string]string{"WITA": "ಮಧ್ಯ ಇಂಡೋನೇಷಿಯಾ ಸಮಯ", "COT": "ಕೊಲಂಬಿಯಾ ಪ್ರಮಾಣಿತ ಸಮಯ", "AKST": "ಅಲಸ್ಕಾ ಪ್ರಮಾಣಿತ ಸಮಯ", "ACWST": "ಆಸ್ಟ್ರೇಲಿಯಾದ ಕೇಂದ್ರ ಪಶ್ಚಿಮ ಪ್ರಮಾಣಿತ ಸಮಯ", "NZST": "ನ್ಯೂಜಿಲ್ಯಾಂಡ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "BOT": "ಬೊಲಿವಿಯಾ ಸಮಯ", "AKDT": "\u200cಅಲಾಸ್ಕಾ ಹಗಲು ಸಮಯ", "MEZ": "ಮಧ್ಯ ಯುರೋಪಿಯನ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "ARST": "ಅರ್ಜೆಂಟಿನಾ ಬೇಸಿಗೆ ಸಮಯ", "CHADT": "ಚಥಾಮ್ ಹಗಲು ಸಮಯ", "CDT": "ಉತ್ತರ ಅಮೆರಿಕದ ಕೇಂದ್ರೀಯ ದಿನದ ಸಮಯ", "HNT": "ನ್ಯೂಫೌಂಡ್\u200cಲ್ಯಾಂಡ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "CLST": "ಚಿಲಿ ಬೇಸಿಗೆ ಸಮಯ", "TMST": "ತುರ್ಕ್\u200cಮೇನಿಸ್ತಾನ್ ಬೇಸಿಗೆ ಸಮಯ", "WAT": "ಪಶ್ಚಿಮ ಆಫ್ರಿಕಾ ಪ್ರಮಾಣಿತ ಸಮಯ", "PDT": "ಉತ್ತರ ಅಮೆರಿಕದ ಪೆಸಿಫಿಕ್ ದಿನದ ಸಮಯ", "HNOG": "ಪಶ್ಚಿಮ ಗ್ರೀನ್\u200cಲ್ಯಾಂಡ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "HNPM": "ಸೇಂಟ್ ಪಿಯರ್ ಮತ್ತು ಮಿಕ್ವೆಲನ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "TMT": "ತುರ್ಕ್\u200cಮೇನಿಸ್ತಾನ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "UYST": "ಉರುಗ್ವೇ ಬೇಸಿಗೆ ಸಮಯ", "HNCU": "ಕ್ಯೂಬಾ ಪ್ರಮಾಣಿತ ಸಮಯ", "MST": "ಮಕಾವ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "HNEG": "ಪೂರ್ವ ಗ್ರೀನ್\u200cಲ್ಯಾಂಡ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "AWDT": "ಆಸ್ಟ್ರೇಲಿಯಾದ ಪಶ್ಚಿಮ ಹಗಲು ಸಮಯ", "AWST": "ಆಸ್ಟ್ರೇಲಿಯಾದ ಪಶ್ಚಿಮ ಪ್ರಮಾಣಿತ ಸಮಯ", "AEST": "ಆಸ್ಟ್ರೇಲಿಯಾದ ಪೂರ್ವ ಪ್ರಮಾಣಿತ ಸಮಯ", "IST": "ಭಾರತೀಯ ಪ್ರಮಾಣಿತ ಸಮಯ", "HENOMX": "ವಾಯವ್ಯ ಮೆಕ್ಸಿಕೊ ಹಗಲು ಸಮಯ", "OEZ": "ಪೂರ್ವ ಯುರೋಪಿಯನ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "GYT": "ಗಯಾನಾ ಸಮಯ", "MDT": "ಮಕಾವ್ ಬೇಸಿಗೆ ಸಮಯ", "SRT": "ಸುರಿನೇಮ್ ಸಮಯ", "COST": "ಕೊಲಂಬಿಯಾ ಬೇಸಿಗೆ ಸಮಯ", "UYT": "ಉರುಗ್ವೇ ಪ್ರಮಾಣಿತ ಸಮಯ", "AST": "ಅಟ್ಲಾಂಟಿಕ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "SGT": "ಸಿಂಗಾಪುರ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "ECT": "ಈಕ್ವೆಡಾರ್ ಸಮಯ", "MESZ": "ಮಧ್ಯ ಯುರೋಪಿಯನ್ ಬೇಸಿಗೆ ಸಮಯ", "CLT": "ಚಿಲಿ ಪ್ರಮಾಣಿತ ಸಮಯ", "HAST": "ಹವಾಯಿ-ಅಲ್ಯುಟಿಯನ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "ART": "ಅರ್ಜೆಂಟೀನಾ ಪ್ರಮಾಣಿತ ಸಮಯ", "SAST": "ದಕ್ಷಿಣ ಆಫ್ರಿಕಾ ಪ್ರಮಾಣಿತ ಸಮಯ", "MYT": "ಮಲೇಷಿಯಾ ಸಮಯ", "JST": "ಜಪಾನ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "ACWDT": "ಆಸ್ಟ್ರೇಲಿಯಾದ ಕೇಂದ್ರ ಪಶ್ಚಿಮ ಹಗಲು ಸಮಯ", "HKT": "ಹಾಂಗ್ ಕಾಂಗ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "HECU": "ಕ್ಯೂಬಾ ದಿನದ ಸಮಯ", "PST": "ಉತ್ತರ ಅಮೆರಿಕದ ಪೆಸಿಫಿಕ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "HEPMX": "ಮೆಕ್ಸಿಕನ್ ಪೆಸಿಫಿಕ್ ಹಗಲು ಸಮಯ", "WART": "ಪಶ್ಚಿಮ ಅರ್ಜೆಂಟೀನಾ ಪ್ರಮಾಣಿತ ಸಮಯ", "HEOG": "ಪಶ್ಚಿಮ ಗ್ರೀನ್\u200cಲ್ಯಾಂಡ್ ಬೇಸಿಗೆ ಸಮಯ", "LHST": "ಲಾರ್ಡ್ ಹೋವ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "WARST": "ಪಶ್ಚಿಮ ಅರ್ಜೆಂಟೀನಾ ಬೇಸಿಗೆ ಸಮಯ", "∅∅∅": "ಅಮೆಜಾನ್ ಬೇಸಿಗೆ ಸಮಯ", "ADT": "ಅಟ್ಲಾಂಟಿಕ್ ದಿನದ ಸಮಯ", "BT": "ಭೂತಾನ್ ಸಮಯ", "WIT": "ಪೂರ್ವ ಇಂಡೋನೇಷಿಯಾ ಸಮಯ", "HADT": "ಹವಾಯಿ-ಅಲ್ಯುಟಿಯನ್ ಹಗಲು ಸಮಯ", "HNPMX": "ಮೆಕ್ಸಿಕನ್ ಪೆಸಿಫಿಕ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "JDT": "ಜಪಾನ್ ಹಗಲು ಸಮಯ", "ACST": "ಆಸ್ಟ್ರೇಲಿಯಾದ ಕೇಂದ್ರ ಪ್ರಮಾಣಿತ ಸಮಯ", "HNNOMX": "ವಾಯವ್ಯ ಮೆಕ್ಸಿಕೊ ಪ್ರಮಾಣಿತ ಸಮಯ", "CAT": "ಮಧ್ಯ ಆಫ್ರಿಕಾ ಸಮಯ", "EAT": "ಪೂರ್ವ ಆಫ್ರಿಕಾ ಸಮಯ", "ACDT": "ಆಸ್ಟ್ರೇಲಿಯಾದ ಕೇಂದ್ರ ಹಗಲು ಸಮಯ", "LHDT": "ಲಾರ್ಡ್ ಹೋವ್ ಬೆಳಗಿನ ಸಮಯ", "HEPM": "ಸೇಂಟ್ ಪಿಯರ್ ಮತ್ತು ಮಿಕ್ವೆಲನ್ ಹಗಲು ಸಮಯ", "EST": "ಉತ್ತರ ಅಮೆರಿಕದ ಪೂರ್ವದ ಪ್ರಮಾಣಿತ ಸಮಯ", "WAST": "ಪಶ್ಚಿಮ ಆಫ್ರಿಕಾ ಬೇಸಿಗೆ ಸಮಯ", "WESZ": "ಪಶ್ಚಿಮ ಯುರೋಪಿಯನ್ ಬೇಸಿಗೆ ಸಮಯ", "GFT": "ಫ್ರೆಂಚ್ ಗಯಾನಾ ಸಮಯ", "HEEG": "ಪೂರ್ವ ಗ್ರೀನ್\u200cಲ್ಯಾಂಡ್ ಬೇಸಿಗೆ ಸಮಯ", "HAT": "ನ್ಯೂಫೌಂಡ್\u200cಲ್ಯಾಂಡ್ ದಿನದ ಸಮಯ", "ChST": "ಚಮೋರೋ ಪ್ರಮಾಣಿತ ಸಮಯ", "WEZ": "ಪಶ್ಚಿಮ ಯುರೋಪಿಯನ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "EDT": "ಉತ್ತರ ಅಮೆರಿಕದ ಪೂರ್ವದ ದಿನದ ಸಮಯ", "HKST": "ಹಾಂಗ್ ಕಾಂಗ್ ಬೇಸಿಗೆ ಸಮಯ", "VET": "ವೆನಿಜುವೆಲಾ ಸಮಯ", "GMT": "ಗ್ರೀನ್\u200cವಿಚ್ ಸರಾಸರಿ ಕಾಲಮಾನ", "CST": "ಉತ್ತರ ಅಮೆರಿಕದ ಕೇಂದ್ರ ಪ್ರಮಾಣಿತ ಸಮಯ", "WIB": "ಪಶ್ಚಿಮ ಇಂಡೋನೇಷಿಯ ಸಮಯ", "NZDT": "ನ್ಯೂಜಿಲ್ಯಾಂಡ್ ಹಗಲು ಸಮಯ", "OESZ": "ಪೂರ್ವ ಯುರೋಪಿಯನ್ ಬೇಸಿಗೆ ಸಮಯ", "CHAST": "ಚಥಾಮ್ ಪ್ರಮಾಣಿತ ಸಮಯ", "AEDT": "ಪೂರ್ವ ಆಸ್ಟ್ರೇಲಿಯಾದ ಹಗಲು ಸಮಯ"},
  67. }
  68. }
  69. // Locale returns the current translators string locale
  70. func (kn *kn) Locale() string {
  71. return kn.locale
  72. }
  73. // PluralsCardinal returns the list of cardinal plural rules associated with 'kn'
  74. func (kn *kn) PluralsCardinal() []locales.PluralRule {
  75. return kn.pluralsCardinal
  76. }
  77. // PluralsOrdinal returns the list of ordinal plural rules associated with 'kn'
  78. func (kn *kn) PluralsOrdinal() []locales.PluralRule {
  79. return kn.pluralsOrdinal
  80. }
  81. // PluralsRange returns the list of range plural rules associated with 'kn'
  82. func (kn *kn) PluralsRange() []locales.PluralRule {
  83. return kn.pluralsRange
  84. }
  85. // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'kn'
  86. func (kn *kn) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
  87. n := math.Abs(num)
  88. i := int64(n)
  89. if (i == 0) || (n == 1) {
  90. return locales.PluralRuleOne
  91. }
  92. return locales.PluralRuleOther
  93. }
  94. // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'kn'
  95. func (kn *kn) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
  96. return locales.PluralRuleOther
  97. }
  98. // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'kn'
  99. func (kn *kn) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
  100. start := kn.CardinalPluralRule(num1, v1)
  101. end := kn.CardinalPluralRule(num2, v2)
  102. if start == locales.PluralRuleOne && end == locales.PluralRuleOne {
  103. return locales.PluralRuleOne
  104. } else if start == locales.PluralRuleOne && end == locales.PluralRuleOther {
  105. return locales.PluralRuleOther
  106. }
  107. return locales.PluralRuleOther
  108. }
  109. // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
  110. func (kn *kn) MonthAbbreviated(month time.Month) string {
  111. return kn.monthsAbbreviated[month]
  112. }
  113. // MonthsAbbreviated returns the locales abbreviated months
  114. func (kn *kn) MonthsAbbreviated() []string {
  115. return kn.monthsAbbreviated[1:]
  116. }
  117. // MonthNarrow returns the locales narrow month given the 'month' provided
  118. func (kn *kn) MonthNarrow(month time.Month) string {
  119. return kn.monthsNarrow[month]
  120. }
  121. // MonthsNarrow returns the locales narrow months
  122. func (kn *kn) MonthsNarrow() []string {
  123. return kn.monthsNarrow[1:]
  124. }
  125. // MonthWide returns the locales wide month given the 'month' provided
  126. func (kn *kn) MonthWide(month time.Month) string {
  127. return kn.monthsWide[month]
  128. }
  129. // MonthsWide returns the locales wide months
  130. func (kn *kn) MonthsWide() []string {
  131. return kn.monthsWide[1:]
  132. }
  133. // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
  134. func (kn *kn) WeekdayAbbreviated(weekday time.Weekday) string {
  135. return kn.daysAbbreviated[weekday]
  136. }
  137. // WeekdaysAbbreviated returns the locales abbreviated weekdays
  138. func (kn *kn) WeekdaysAbbreviated() []string {
  139. return kn.daysAbbreviated
  140. }
  141. // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
  142. func (kn *kn) WeekdayNarrow(weekday time.Weekday) string {
  143. return kn.daysNarrow[weekday]
  144. }
  145. // WeekdaysNarrow returns the locales narrow weekdays
  146. func (kn *kn) WeekdaysNarrow() []string {
  147. return kn.daysNarrow
  148. }
  149. // WeekdayShort returns the locales short weekday given the 'weekday' provided
  150. func (kn *kn) WeekdayShort(weekday time.Weekday) string {
  151. return kn.daysShort[weekday]
  152. }
  153. // WeekdaysShort returns the locales short weekdays
  154. func (kn *kn) WeekdaysShort() []string {
  155. return kn.daysShort
  156. }
  157. // WeekdayWide returns the locales wide weekday given the 'weekday' provided
  158. func (kn *kn) WeekdayWide(weekday time.Weekday) string {
  159. return kn.daysWide[weekday]
  160. }
  161. // WeekdaysWide returns the locales wide weekdays
  162. func (kn *kn) WeekdaysWide() []string {
  163. return kn.daysWide
  164. }
  165. // Decimal returns the decimal point of number
  166. func (kn *kn) Decimal() string {
  167. return kn.decimal
  168. }
  169. // Group returns the group of number
  170. func (kn *kn) Group() string {
  171. return kn.group
  172. }
  173. // Group returns the minus sign of number
  174. func (kn *kn) Minus() string {
  175. return kn.minus
  176. }
  177. // FmtNumber returns 'num' with digits/precision of 'v' for 'kn' and handles both Whole and Real numbers based on 'v'
  178. func (kn *kn) FmtNumber(num float64, v uint64) string {
  179. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  180. l := len(s) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  181. count := 0
  182. inWhole := v == 0
  183. b := make([]byte, 0, l)
  184. for i := len(s) - 1; i >= 0; i-- {
  185. if s[i] == '.' {
  186. b = append(b, kn.decimal[0])
  187. inWhole = true
  188. continue
  189. }
  190. if inWhole {
  191. if count == 3 {
  192. b = append(b, kn.group[0])
  193. count = 1
  194. } else {
  195. count++
  196. }
  197. }
  198. b = append(b, s[i])
  199. }
  200. if num < 0 {
  201. b = append(b, kn.minus[0])
  202. }
  203. // reverse
  204. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  205. b[i], b[j] = b[j], b[i]
  206. }
  207. return string(b)
  208. }
  209. // FmtPercent returns 'num' with digits/precision of 'v' for 'kn' and handles both Whole and Real numbers based on 'v'
  210. // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
  211. func (kn *kn) FmtPercent(num float64, v uint64) string {
  212. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  213. l := len(s) + 3
  214. b := make([]byte, 0, l)
  215. for i := len(s) - 1; i >= 0; i-- {
  216. if s[i] == '.' {
  217. b = append(b, kn.decimal[0])
  218. continue
  219. }
  220. b = append(b, s[i])
  221. }
  222. if num < 0 {
  223. b = append(b, kn.minus[0])
  224. }
  225. // reverse
  226. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  227. b[i], b[j] = b[j], b[i]
  228. }
  229. b = append(b, kn.percent...)
  230. return string(b)
  231. }
  232. // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'kn'
  233. func (kn *kn) FmtCurrency(num float64, v uint64, currency currency.Type) string {
  234. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  235. symbol := kn.currencies[currency]
  236. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  237. count := 0
  238. inWhole := v == 0
  239. b := make([]byte, 0, l)
  240. for i := len(s) - 1; i >= 0; i-- {
  241. if s[i] == '.' {
  242. b = append(b, kn.decimal[0])
  243. inWhole = true
  244. continue
  245. }
  246. if inWhole {
  247. if count == 3 {
  248. b = append(b, kn.group[0])
  249. count = 1
  250. } else {
  251. count++
  252. }
  253. }
  254. b = append(b, s[i])
  255. }
  256. for j := len(symbol) - 1; j >= 0; j-- {
  257. b = append(b, symbol[j])
  258. }
  259. if num < 0 {
  260. b = append(b, kn.minus[0])
  261. }
  262. // reverse
  263. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  264. b[i], b[j] = b[j], b[i]
  265. }
  266. if int(v) < 2 {
  267. if v == 0 {
  268. b = append(b, kn.decimal...)
  269. }
  270. for i := 0; i < 2-int(v); i++ {
  271. b = append(b, '0')
  272. }
  273. }
  274. return string(b)
  275. }
  276. // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'kn'
  277. // in accounting notation.
  278. func (kn *kn) FmtAccounting(num float64, v uint64, currency currency.Type) string {
  279. s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
  280. symbol := kn.currencies[currency]
  281. l := len(s) + len(symbol) + 2 + 1*len(s[:len(s)-int(v)-1])/3
  282. count := 0
  283. inWhole := v == 0
  284. b := make([]byte, 0, l)
  285. for i := len(s) - 1; i >= 0; i-- {
  286. if s[i] == '.' {
  287. b = append(b, kn.decimal[0])
  288. inWhole = true
  289. continue
  290. }
  291. if inWhole {
  292. if count == 3 {
  293. b = append(b, kn.group[0])
  294. count = 1
  295. } else {
  296. count++
  297. }
  298. }
  299. b = append(b, s[i])
  300. }
  301. if num < 0 {
  302. for j := len(symbol) - 1; j >= 0; j-- {
  303. b = append(b, symbol[j])
  304. }
  305. b = append(b, kn.minus[0])
  306. } else {
  307. for j := len(symbol) - 1; j >= 0; j-- {
  308. b = append(b, symbol[j])
  309. }
  310. }
  311. // reverse
  312. for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
  313. b[i], b[j] = b[j], b[i]
  314. }
  315. if int(v) < 2 {
  316. if v == 0 {
  317. b = append(b, kn.decimal...)
  318. }
  319. for i := 0; i < 2-int(v); i++ {
  320. b = append(b, '0')
  321. }
  322. }
  323. return string(b)
  324. }
  325. // FmtDateShort returns the short date representation of 't' for 'kn'
  326. func (kn *kn) FmtDateShort(t time.Time) string {
  327. b := make([]byte, 0, 32)
  328. b = strconv.AppendInt(b, int64(t.Day()), 10)
  329. b = append(b, []byte{0x2f}...)
  330. b = strconv.AppendInt(b, int64(t.Month()), 10)
  331. b = append(b, []byte{0x2f}...)
  332. if t.Year() > 9 {
  333. b = append(b, strconv.Itoa(t.Year())[2:]...)
  334. } else {
  335. b = append(b, strconv.Itoa(t.Year())[1:]...)
  336. }
  337. return string(b)
  338. }
  339. // FmtDateMedium returns the medium date representation of 't' for 'kn'
  340. func (kn *kn) FmtDateMedium(t time.Time) string {
  341. b := make([]byte, 0, 32)
  342. b = append(b, kn.monthsAbbreviated[t.Month()]...)
  343. b = append(b, []byte{0x20}...)
  344. b = strconv.AppendInt(b, int64(t.Day()), 10)
  345. b = append(b, []byte{0x2c, 0x20}...)
  346. if t.Year() > 0 {
  347. b = strconv.AppendInt(b, int64(t.Year()), 10)
  348. } else {
  349. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  350. }
  351. return string(b)
  352. }
  353. // FmtDateLong returns the long date representation of 't' for 'kn'
  354. func (kn *kn) FmtDateLong(t time.Time) string {
  355. b := make([]byte, 0, 32)
  356. b = append(b, kn.monthsWide[t.Month()]...)
  357. b = append(b, []byte{0x20}...)
  358. b = strconv.AppendInt(b, int64(t.Day()), 10)
  359. b = append(b, []byte{0x2c, 0x20}...)
  360. if t.Year() > 0 {
  361. b = strconv.AppendInt(b, int64(t.Year()), 10)
  362. } else {
  363. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  364. }
  365. return string(b)
  366. }
  367. // FmtDateFull returns the full date representation of 't' for 'kn'
  368. func (kn *kn) FmtDateFull(t time.Time) string {
  369. b := make([]byte, 0, 32)
  370. b = append(b, kn.daysWide[t.Weekday()]...)
  371. b = append(b, []byte{0x2c, 0x20}...)
  372. b = append(b, kn.monthsWide[t.Month()]...)
  373. b = append(b, []byte{0x20}...)
  374. b = strconv.AppendInt(b, int64(t.Day()), 10)
  375. b = append(b, []byte{0x2c, 0x20}...)
  376. if t.Year() > 0 {
  377. b = strconv.AppendInt(b, int64(t.Year()), 10)
  378. } else {
  379. b = strconv.AppendInt(b, int64(-t.Year()), 10)
  380. }
  381. return string(b)
  382. }
  383. // FmtTimeShort returns the short time representation of 't' for 'kn'
  384. func (kn *kn) FmtTimeShort(t time.Time) string {
  385. b := make([]byte, 0, 32)
  386. h := t.Hour()
  387. if h > 12 {
  388. h -= 12
  389. }
  390. if h < 10 {
  391. b = append(b, '0')
  392. }
  393. b = strconv.AppendInt(b, int64(h), 10)
  394. b = append(b, kn.timeSeparator...)
  395. if t.Minute() < 10 {
  396. b = append(b, '0')
  397. }
  398. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  399. b = append(b, []byte{0x20}...)
  400. if t.Hour() < 12 {
  401. b = append(b, kn.periodsAbbreviated[0]...)
  402. } else {
  403. b = append(b, kn.periodsAbbreviated[1]...)
  404. }
  405. return string(b)
  406. }
  407. // FmtTimeMedium returns the medium time representation of 't' for 'kn'
  408. func (kn *kn) FmtTimeMedium(t time.Time) string {
  409. b := make([]byte, 0, 32)
  410. h := t.Hour()
  411. if h > 12 {
  412. h -= 12
  413. }
  414. if h < 10 {
  415. b = append(b, '0')
  416. }
  417. b = strconv.AppendInt(b, int64(h), 10)
  418. b = append(b, kn.timeSeparator...)
  419. if t.Minute() < 10 {
  420. b = append(b, '0')
  421. }
  422. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  423. b = append(b, kn.timeSeparator...)
  424. if t.Second() < 10 {
  425. b = append(b, '0')
  426. }
  427. b = strconv.AppendInt(b, int64(t.Second()), 10)
  428. b = append(b, []byte{0x20}...)
  429. if t.Hour() < 12 {
  430. b = append(b, kn.periodsAbbreviated[0]...)
  431. } else {
  432. b = append(b, kn.periodsAbbreviated[1]...)
  433. }
  434. return string(b)
  435. }
  436. // FmtTimeLong returns the long time representation of 't' for 'kn'
  437. func (kn *kn) FmtTimeLong(t time.Time) string {
  438. b := make([]byte, 0, 32)
  439. h := t.Hour()
  440. if h > 12 {
  441. h -= 12
  442. }
  443. if h < 10 {
  444. b = append(b, '0')
  445. }
  446. b = strconv.AppendInt(b, int64(h), 10)
  447. b = append(b, kn.timeSeparator...)
  448. if t.Minute() < 10 {
  449. b = append(b, '0')
  450. }
  451. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  452. b = append(b, kn.timeSeparator...)
  453. if t.Second() < 10 {
  454. b = append(b, '0')
  455. }
  456. b = strconv.AppendInt(b, int64(t.Second()), 10)
  457. b = append(b, []byte{0x20}...)
  458. if t.Hour() < 12 {
  459. b = append(b, kn.periodsAbbreviated[0]...)
  460. } else {
  461. b = append(b, kn.periodsAbbreviated[1]...)
  462. }
  463. b = append(b, []byte{0x20}...)
  464. tz, _ := t.Zone()
  465. b = append(b, tz...)
  466. return string(b)
  467. }
  468. // FmtTimeFull returns the full time representation of 't' for 'kn'
  469. func (kn *kn) FmtTimeFull(t time.Time) string {
  470. b := make([]byte, 0, 32)
  471. h := t.Hour()
  472. if h > 12 {
  473. h -= 12
  474. }
  475. if h < 10 {
  476. b = append(b, '0')
  477. }
  478. b = strconv.AppendInt(b, int64(h), 10)
  479. b = append(b, kn.timeSeparator...)
  480. if t.Minute() < 10 {
  481. b = append(b, '0')
  482. }
  483. b = strconv.AppendInt(b, int64(t.Minute()), 10)
  484. b = append(b, kn.timeSeparator...)
  485. if t.Second() < 10 {
  486. b = append(b, '0')
  487. }
  488. b = strconv.AppendInt(b, int64(t.Second()), 10)
  489. b = append(b, []byte{0x20}...)
  490. if t.Hour() < 12 {
  491. b = append(b, kn.periodsAbbreviated[0]...)
  492. } else {
  493. b = append(b, kn.periodsAbbreviated[1]...)
  494. }
  495. b = append(b, []byte{0x20}...)
  496. tz, _ := t.Zone()
  497. if btz, ok := kn.timezones[tz]; ok {
  498. b = append(b, btz...)
  499. } else {
  500. b = append(b, tz...)
  501. }
  502. return string(b)
  503. }