@@ -76,10 +76,10 @@ func parse(period string, normalise bool) (*period64, error) {
76
76
}
77
77
remaining = remaining [1 :]
78
78
79
- var number , weekValue , prevFraction int64
79
+ var integer , fraction , weekValue int64
80
80
result := & period64 {input : period , neg : neg }
81
81
var years , months , weeks , days , hours , minutes , seconds itemState
82
- var designator , prevDesignator byte
82
+ var designator , previousFractionDesignator byte
83
83
var err error
84
84
nComponents := 0
85
85
@@ -99,16 +99,17 @@ func parse(period string, normalise bool) (*period64, error) {
99
99
remaining = remaining [1 :]
100
100
101
101
} else {
102
- number , designator , remaining , err = parseNextField (remaining , period )
102
+ integer , fraction , designator , remaining , err = parseNextField (remaining , period )
103
103
if err != nil {
104
104
return nil , err
105
105
}
106
106
107
- fraction := number % 10
108
- if prevFraction != 0 && fraction != 0 {
109
- return nil , fmt .Errorf ("%s: '%c' & '%c' only the last field can have a fraction" , period , prevDesignator , designator )
107
+ if previousFractionDesignator != 0 && fraction != 0 {
108
+ return nil , fmt .Errorf ("%s: '%c' & '%c' only the last field can have a fraction" , period , previousFractionDesignator , designator )
110
109
}
111
110
111
+ number := integer * 10 + fraction
112
+
112
113
switch designator {
113
114
case 'Y' :
114
115
years , err = years .testAndSet (number , 'Y' , result , & result .years )
@@ -135,8 +136,9 @@ func parse(period string, normalise bool) (*period64, error) {
135
136
return nil , err
136
137
}
137
138
138
- prevFraction = fraction
139
- prevDesignator = designator
139
+ if fraction != 0 {
140
+ previousFractionDesignator = designator
141
+ }
140
142
}
141
143
}
142
144
@@ -177,19 +179,19 @@ func (i itemState) testAndSet(number int64, designator byte, result *period64, v
177
179
178
180
//-------------------------------------------------------------------------------------------------
179
181
180
- func parseNextField (str , original string ) (int64 , byte , string , error ) {
182
+ func parseNextField (str , original string ) (int64 , int64 , byte , string , error ) {
181
183
i := scanDigits (str )
182
184
if i < 0 {
183
- return 0 , 0 , "" , fmt .Errorf ("%s: missing designator at the end" , original )
185
+ return 0 , 0 , 0 , "" , fmt .Errorf ("%s: missing designator at the end" , original )
184
186
}
185
187
186
188
des := str [i ]
187
- number , err := parseDecimalNumber (str [:i ], original , des )
188
- return number , des , str [i + 1 :], err
189
+ integer , fraction , err := parseDecimalNumber (str [:i ], original , des )
190
+ return integer , fraction , des , str [i + 1 :], err
189
191
}
190
192
191
193
// Fixed-point one decimal place
192
- func parseDecimalNumber (number , original string , des byte ) (int64 , error ) {
194
+ func parseDecimalNumber (number , original string , des byte ) (int64 , int64 , error ) {
193
195
dec := strings .IndexByte (number , '.' )
194
196
if dec < 0 {
195
197
dec = strings .IndexByte (number , ',' )
@@ -214,10 +216,10 @@ func parseDecimalNumber(number, original string, des byte) (int64, error) {
214
216
}
215
217
216
218
if err != nil {
217
- return 0 , fmt .Errorf ("%s: expected a number but found '%c'" , original , des )
219
+ return 0 , 0 , fmt .Errorf ("%s: expected a number but found '%c'" , original , des )
218
220
}
219
221
220
- return integer * 10 + fraction , err
222
+ return integer , fraction , err
221
223
}
222
224
223
225
// scanDigits finds the first non-digit byte after a given starting point.
0 commit comments