github.com/go-chrono/chrono@v0.0.0-20240102183611-532f0d0d7c34/duration_test_data_test.go (about) 1 package chrono_test 2 3 import "github.com/go-chrono/chrono" 4 5 var ( 6 formatDurationCases = []struct { 7 name string 8 of chrono.Extent 9 exclusive []chrono.Designator 10 expected string 11 }{ 12 { 13 name: "default HMS", 14 of: 1*chrono.Hour + 15*chrono.Minute + 30*chrono.Second + 500*chrono.Millisecond, 15 exclusive: []chrono.Designator{}, 16 expected: "PT1H15M30.5S", 17 }, 18 { 19 name: "default HM", 20 of: 1*chrono.Hour + 15*chrono.Minute, 21 exclusive: []chrono.Designator{}, 22 expected: "PT1H15M", 23 }, 24 { 25 name: "default HS", 26 of: 12*chrono.Hour + 30*chrono.Second + 500*chrono.Millisecond, 27 exclusive: []chrono.Designator{}, 28 expected: "PT12H0M30.5S", 29 }, 30 { 31 name: "default H", 32 of: 1 * chrono.Hour, 33 exclusive: []chrono.Designator{}, 34 expected: "PT1H", 35 }, 36 { 37 name: "default MS", 38 of: 15*chrono.Minute + 30*chrono.Second + 500*chrono.Millisecond, 39 exclusive: []chrono.Designator{}, 40 expected: "PT15M30.5S", 41 }, 42 { 43 name: "default M", 44 of: 15 * chrono.Minute, 45 exclusive: []chrono.Designator{}, 46 expected: "PT15M", 47 }, 48 { 49 name: "default S", 50 of: 500 * chrono.Millisecond, 51 exclusive: []chrono.Designator{}, 52 expected: "PT0.5S", 53 }, 54 { 55 name: "default zero value", 56 of: 0, 57 exclusive: []chrono.Designator{}, 58 expected: "PT0S", 59 }, 60 { 61 name: "exclusive HMS", 62 of: 1*chrono.Hour + 15*chrono.Minute + 30*chrono.Second + 500*chrono.Millisecond, 63 exclusive: []chrono.Designator{chrono.Hours, chrono.Minutes, chrono.Seconds}, 64 expected: "PT1H15M30.5S", 65 }, 66 { 67 name: "exclusive HMS zero value", 68 of: 0, 69 exclusive: []chrono.Designator{chrono.Hours, chrono.Minutes, chrono.Seconds}, 70 expected: "PT0H0M0S", 71 }, 72 { 73 name: "exclusive HM", 74 of: 1*chrono.Hour + 15*chrono.Minute + 30*chrono.Second + 600*chrono.Millisecond, 75 exclusive: []chrono.Designator{chrono.Hours, chrono.Minutes}, 76 expected: "PT1H15.51M", 77 }, 78 { 79 name: "exclusive HM zero value", 80 of: 0, 81 exclusive: []chrono.Designator{chrono.Hours, chrono.Minutes}, 82 expected: "PT0H0M", 83 }, 84 { 85 name: "exclusive HS", 86 of: 12*chrono.Hour + 1*chrono.Minute + 30*chrono.Second + 500*chrono.Millisecond, 87 exclusive: []chrono.Designator{chrono.Hours, chrono.Seconds}, 88 expected: "PT12H90.5S", 89 }, 90 { 91 name: "exclusive HS zero value", 92 of: 0, 93 exclusive: []chrono.Designator{chrono.Hours, chrono.Seconds}, 94 expected: "PT0H0S", 95 }, 96 { 97 name: "exclusive H", 98 of: 1*chrono.Hour + 30*chrono.Minute + 36*chrono.Second + 36*chrono.Millisecond, 99 exclusive: []chrono.Designator{chrono.Hours}, 100 expected: "PT1.51001H", 101 }, 102 { 103 name: "exclusive H zero value", 104 of: 0, 105 exclusive: []chrono.Designator{chrono.Hours}, 106 expected: "PT0H", 107 }, 108 { 109 name: "exclusive MS", 110 of: 1*chrono.Hour + 15*chrono.Minute + 30*chrono.Second + 500*chrono.Millisecond, 111 exclusive: []chrono.Designator{chrono.Minutes, chrono.Seconds}, 112 expected: "PT75M30.5S", 113 }, 114 { 115 name: "exclusive MS zero value", 116 of: 0, 117 exclusive: []chrono.Designator{chrono.Minutes, chrono.Seconds}, 118 expected: "PT0M0S", 119 }, 120 { 121 name: "exclusive M", 122 of: 1*chrono.Hour + 15*chrono.Minute + 30*chrono.Second + 600*chrono.Millisecond, 123 exclusive: []chrono.Designator{chrono.Minutes}, 124 expected: "PT75.51M", 125 }, 126 { 127 name: "exclusive M zero value", 128 of: 0, 129 exclusive: []chrono.Designator{chrono.Minutes}, 130 expected: "PT0M", 131 }, 132 { 133 name: "exclusive S", 134 of: 1*chrono.Hour + 15*chrono.Minute + 30*chrono.Second + 500*chrono.Millisecond, 135 exclusive: []chrono.Designator{chrono.Seconds}, 136 expected: "PT4530.5S", 137 }, 138 { 139 name: "exclusive S zero value", 140 of: 0, 141 exclusive: []chrono.Designator{chrono.Seconds}, 142 expected: "PT0S", 143 }, 144 } 145 146 parseDurationCases = []struct { 147 name string 148 input string 149 expected chrono.Extent 150 }{ 151 { 152 name: "valid HMS integers", 153 input: "PT5H3M1S", 154 expected: 5*chrono.Hour + 3*chrono.Minute + 1*chrono.Second, 155 }, 156 { 157 name: "valid HMS floats", 158 input: "PT4.5H3.25M1.1S", 159 expected: chrono.Extent(4.5*float64(chrono.Hour) + 3.25*float64(chrono.Minute) + 1.1*float64(chrono.Second)), 160 }, 161 { 162 name: "valid HM integers", 163 input: "PT5H3M", 164 expected: 5*chrono.Hour + 3*chrono.Minute, 165 }, 166 { 167 name: "valid HM floats", 168 input: "PT4.5H3.25M", 169 expected: chrono.Extent(4.5*float64(chrono.Hour) + 3.25*float64(chrono.Minute)), 170 }, 171 { 172 name: "valid HS integers", 173 input: "PT5H1S", 174 expected: 5*chrono.Hour + 1*chrono.Second, 175 }, 176 { 177 name: "valid HS floats", 178 input: "PT4.5H1.1S", 179 expected: chrono.Extent(4.5*float64(chrono.Hour) + 1.1*float64(chrono.Second)), 180 }, 181 { 182 name: "valid H integer", 183 input: "PT5H", 184 expected: 5 * chrono.Hour, 185 }, 186 { 187 name: "valid H float", 188 input: "PT4.5H", 189 expected: chrono.Extent(4.5 * float64(chrono.Hour)), 190 }, 191 { 192 name: "valid MS integers", 193 input: "PT3M1S", 194 expected: 3*chrono.Minute + 1*chrono.Second, 195 }, 196 { 197 name: "valid MS floats", 198 input: "PT3.25M1.1S", 199 expected: chrono.Extent(3.25*float64(chrono.Minute) + 1.1*float64(chrono.Second)), 200 }, 201 { 202 name: "valid M integer", 203 input: "PT3M", 204 expected: 3 * chrono.Minute, 205 }, 206 { 207 name: "valid M float", 208 input: "PT3.25M", 209 expected: chrono.Extent(3.25 * float64(chrono.Minute)), 210 }, 211 { 212 name: "valid S integer", 213 input: "PT1S", 214 expected: 1 * chrono.Second, 215 }, 216 { 217 name: "valid S float", 218 input: "PT1.1S", 219 expected: chrono.Extent(1.1 * float64(chrono.Second)), 220 }, 221 } 222 )