Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package time | 5 package time |
6 | 6 |
7 import "errors" | 7 import "errors" |
8 | 8 |
9 // These are predefined layouts for use in Time.Format and Time.Parse. | 9 // These are predefined layouts for use in Time.Format and Time.Parse. |
10 // The reference time used in the layouts is: | 10 // The reference time used in the layouts is: |
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 | 1197 |
1198 // Consume (\.[0-9]*)? | 1198 // Consume (\.[0-9]*)? |
1199 post := false | 1199 post := false |
1200 if s != "" && s[0] == '.' { | 1200 if s != "" && s[0] == '.' { |
1201 s = s[1:] | 1201 s = s[1:] |
1202 pl := len(s) | 1202 pl := len(s) |
1203 x, s, err = leadingInt(s) | 1203 x, s, err = leadingInt(s) |
1204 if err != nil { | 1204 if err != nil { |
1205 return 0, errors.New("time: invalid duration " + orig) | 1205 return 0, errors.New("time: invalid duration " + orig) |
1206 } | 1206 } |
1207 » » » scale := int64(1) | 1207 » » » scale := 1.0 |
rsc
2013/10/18 17:26:36
might as well do 1.0 (float64).
the int64 is good
minux1
2013/10/20 01:20:45
i originally used int64 because if scale can be re
| |
1208 for n := pl - len(s); n > 0; n-- { | 1208 for n := pl - len(s); n > 0; n-- { |
1209 scale *= 10 | 1209 scale *= 10 |
1210 } | 1210 } |
1211 » » » g += float64(x) / float64(scale) | 1211 » » » g += float64(x) / scale |
1212 post = pl != len(s) | 1212 post = pl != len(s) |
1213 } | 1213 } |
1214 if !pre && !post { | 1214 if !pre && !post { |
1215 // no digits (e.g. ".s" or "-.s") | 1215 // no digits (e.g. ".s" or "-.s") |
1216 return 0, errors.New("time: invalid duration " + orig) | 1216 return 0, errors.New("time: invalid duration " + orig) |
1217 } | 1217 } |
1218 | 1218 |
1219 // Consume unit. | 1219 // Consume unit. |
1220 i := 0 | 1220 i := 0 |
1221 for ; i < len(s); i++ { | 1221 for ; i < len(s); i++ { |
(...skipping 13 matching lines...) Expand all Loading... | |
1235 } | 1235 } |
1236 | 1236 |
1237 f += g * unit | 1237 f += g * unit |
1238 } | 1238 } |
1239 | 1239 |
1240 if neg { | 1240 if neg { |
1241 f = -f | 1241 f = -f |
1242 } | 1242 } |
1243 return Duration(f), nil | 1243 return Duration(f), nil |
1244 } | 1244 } |
LEFT | RIGHT |