github.com/tawesoft/golib/v2@v2.10.0/legacy/humanize/common.go (about) 1 package humanize 2 3 var CommonUnits = struct{ 4 None Unit 5 Second Unit 6 Meter Unit 7 Byte Unit 8 Bit Unit 9 BitsPerSecond Unit 10 }{ 11 None: Unit{"", ""}, 12 Second: Unit{"s", "s"}, 13 Meter: Unit{"m", "m"}, 14 Byte: Unit{"B", "B"}, 15 Bit: Unit{"b", "b"}, 16 BitsPerSecond: Unit{"bps", "bps"}, 17 } 18 19 var CommonFactors = struct{ 20 // Time is time units in seconds, minutes, hours, days and years as min, h, 21 // d, and y. These are non-SI units but generally accepted in context. 22 // For times smaller than a second (e.g. nanoseconds), use SI instead. 23 // The expected unit is a second (Unit{"s", "s"} or CommonUnits.Second) 24 Time Factors 25 26 // Distance are SI units that stop at kilo (because nobody uses 27 // megametres or gigametres!) but includes centi. The expected unit is the 28 // SI unit for distance, the metre (Unit{"m", "m"} or CommonUnits.Meter) 29 Distance Factors 30 31 // IEC are the "ibi" unit prefixes for bytes e.g. Ki, Mi, Gi with a 32 // factor of 1024. 33 IEC Factors 34 35 // JEDEC are the old unit prefixes for bytes: K, M, G (only) with a factor 36 // of 1024. 37 JEDEC Factors 38 39 // SIBytes are the SI unit prefixes for bytes e.g. k, M, G with a 40 // factor of 1000. Unlike the normal SI Factors, it is assumed based on 41 // context that when a "K" is input this is intended to mean the "k" SI 42 // unit prefix instead of Kelvin - I've never heard of a Kelvin-Byte! 43 SIBytes Factors 44 45 // SIUncommon are the SI unit prefixes including deci, deca, and hecto 46 SIUncommon Factors 47 48 // SI are the SI unit prefixes except centi, deci, deca, and hecto 49 SI Factors 50 }{ 51 Time: Factors{ 52 Factors: []Factor{ 53 {1, Unit{"s", "s"}, FactorModeReplace}, 54 {60, Unit{"min", "min"}, FactorModeReplace}, 55 {60 * 60, Unit{"h", "h"}, FactorModeReplace}, 56 {24 * 60 * 60, Unit{"d", "d"}, FactorModeReplace}, 57 {365.2422 * 24 * 60 * 60, Unit{"y", "y"}, FactorModeReplace}, 58 }, 59 Components: 2, 60 }, 61 Distance: Factors{ 62 Factors: []Factor{ 63 {1E-9, Unit{"n", "n"}, FactorModeUnitPrefix}, // nano 64 {1E-6, Unit{"μ", "u"}, FactorModeUnitPrefix}, // micro 65 {1E-3, Unit{"m", "m"}, FactorModeUnitPrefix}, // milli 66 {1E-2, Unit{"c", "c"}, FactorModeUnitPrefix}, // centi 67 {1, Unit{ "", ""}, FactorModeIdentity}, 68 {1000, Unit{"k", "k"}, FactorModeUnitPrefix}, // kilo 69 }, 70 }, 71 IEC: Factors{ 72 Factors: []Factor{ 73 {1, Unit{ "", ""}, FactorModeUnitPrefix}, 74 {1024, Unit{"Ki", "Ki"}, FactorModeUnitPrefix}, 75 {1024 * 1024, Unit{"Mi", "Mi"}, FactorModeUnitPrefix}, 76 {1024 * 1024 * 1024, Unit{"Gi", "Gi"}, FactorModeUnitPrefix}, 77 {1024 * 1024 * 1024 * 1024, Unit{"Ti", "Ti"}, FactorModeUnitPrefix}, 78 }, 79 }, 80 JEDEC: Factors{ 81 Factors: []Factor{ 82 {1, Unit{ "", ""}, FactorModeIdentity}, 83 {1024, Unit{"K", "K"}, FactorModeUnitPrefix}, 84 {1024 * 1024, Unit{"M", "M"}, FactorModeUnitPrefix}, 85 {1024 * 1024 * 1024, Unit{"G", "G"}, FactorModeUnitPrefix}, 86 }, 87 }, 88 SIBytes: Factors{ 89 Factors: []Factor{ 90 {1, Unit{ "", ""}, FactorModeIdentity}, 91 { 1E3, Unit{"k", "k"}, FactorModeUnitPrefix}, 92 { 1E3, Unit{"K", "K"}, FactorModeUnitPrefix | FactorModeInputCompat}, // Kelvin-Bytes(!) 93 { 1E6, Unit{"M", "M"}, FactorModeUnitPrefix}, 94 { 1E9, Unit{"G", "G"}, FactorModeUnitPrefix}, 95 {1E12, Unit{"T", "T"}, FactorModeUnitPrefix}, 96 }, 97 }, 98 SIUncommon: Factors{ 99 Factors: []Factor{ 100 {1E-9, Unit{"n", "n"}, FactorModeUnitPrefix}, // nano 101 {1E-6, Unit{"μ", "u"}, FactorModeUnitPrefix}, // micro 102 {1E-3, Unit{"m", "m"}, FactorModeUnitPrefix}, // milli 103 {1E-2, Unit{"c", "c"}, FactorModeUnitPrefix}, // centi 104 {1E-1, Unit{"d", "d"}, FactorModeUnitPrefix}, // deci 105 {1, Unit{ "", ""}, FactorModeIdentity}, 106 { 1E1, Unit{"da", "da"}, FactorModeUnitPrefix}, // deca 107 { 1E2, Unit{"h", "h"}, FactorModeUnitPrefix}, // hecto 108 { 1E3, Unit{"k", "k"}, FactorModeUnitPrefix}, // kilo 109 { 1E6, Unit{"M", "M"}, FactorModeUnitPrefix}, 110 { 1E9, Unit{"G", "G"}, FactorModeUnitPrefix}, 111 {1E12, Unit{"T", "T"}, FactorModeUnitPrefix}, 112 }, 113 }, 114 SI: Factors{ 115 Factors: []Factor{ 116 {1E-9, Unit{"n", "n"}, FactorModeUnitPrefix}, // nano 117 {1E-6, Unit{"μ", "u"}, FactorModeUnitPrefix}, // micro 118 {1E-3, Unit{"m", "m"}, FactorModeUnitPrefix}, // milli 119 {1, Unit{ "", ""}, FactorModeIdentity}, 120 { 1E3, Unit{"k", "k"}, FactorModeUnitPrefix}, // kilo 121 { 1E6, Unit{"M", "M"}, FactorModeUnitPrefix}, 122 { 1E9, Unit{"G", "G"}, FactorModeUnitPrefix}, 123 {1E12, Unit{"T", "T"}, FactorModeUnitPrefix}, 124 }, 125 }, 126 }