Merge lp://staging/~jbaikge/goyaml/time.Duration-support into lp://staging/goyaml
Proposed by
Jake T
Status: | Needs review |
---|---|
Proposed branch: | lp://staging/~jbaikge/goyaml/time.Duration-support |
Merge into: | lp://staging/goyaml |
Diff against target: |
76 lines (+34/-0) 2 files modified
decode.go (+9/-0) decode_test.go (+25/-0) |
To merge this branch: | bzr merge lp://staging/~jbaikge/goyaml/time.Duration-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
goyaml maintainers | Pending | ||
Review via email: mp+171337@code.staging.launchpad.net |
Description of the change
Add time.Duration Support
Adds support for parsing time.Duration values (eg 10m, 42s, etc.) into vars or
fields of type time.Duration. Support for using integer values remains.
To post a comment you must log in.
Unmerged revisions
- 47. By Jacob Tews <jake@sable>
-
Added decode support for time.Duration with supporting tests
Reviewers: mp+171337_ code.launchpad. net,
Message:
Please take a look.
Description:
Add time.Duration Support
Adds support for parsing time.Duration values (eg 10m, 42s, etc.) into
vars or
fields of type time.Duration. Support for using integer values remains.
https:/ /code.launchpad .net/~jbaikge/ goyaml/ time.Duration- support/ +merge/ 171337
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/10548043/
Affected files:
A [revision details]
M decode.go
M decode_test.go
Index: [revision details] 20130625151823- ry78brqct2dp1e4 7
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: jake@sable-
Index: decode.go
=== modified file 'decode.go'
--- decode.go 2013-06-19 17:52:23 +0000
+++ decode.go 2013-06-25 15:18:23 +0000
@@ -3,6 +3,7 @@
import (
"reflect"
"strconv"
+ "time"
)
const (
@@ -23,6 +24,8 @@
anchors map[string]*node
}
+var durationType = reflect. TypeOf( time.Duration( 0)) ------- ------- ------- ------- ------- ------- ------- ------- ------- ------
+
//
-------
// Parser, produces a node tree out of a libyaml event stream.
@@ -315,6 +318,12 @@ SetInt( resolved) ion(resolved) d.Nanoseconds( ))
out.
good = true
}
+ case string:
+ if out.Type() == durationType {
+ d, err := time.ParseDurat
+ out.SetInt(
+ good = err == nil
+ }
}
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32,
reflect.Uint64, reflect.Uintptr:
switch resolved := resolved.(type) {
Index: decode_test.go net/goyaml"
=== modified file 'decode_test.go'
--- decode_test.go 2013-06-19 18:05:58 +0000
+++ decode_test.go 2013-06-25 15:18:23 +0000
@@ -5,6 +5,7 @@
"launchpad.
"math"
"reflect"
+ "time"
)
var unmarshalIntTest = 123 Duration( 42)},
@@ -341,6 +342,30 @@
C inlineB `yaml:",inline"`
}{1, inlineB{2, inlineC{3}}},
},
+
+ // Durations
+ {
+ "a: 10m",
+ &struct{ A time.Duration }{10 * time.Minute},
+ },
+ {
+ "a: 10m5s",
+ &struct{ A time.Duration }{10*time.Minute + 5*time.Second},
+ },
+ {
+ "a: 10ms",
+ &struct{ A time.Duration }{10 * time.Millisecond},
+ },
+ {
+ "a: 1h2m3.004005006s",
+ &struct{ A time.Duration }{
+ 1*time.Hour + 2*time.Minute + 3*time.Second + 4*time.Millisecond +
5*time.Microsecond + 6*time.Nanosecond,
+ },
+ },
+ {
+ "a: 42",
+ &struct{ A time.Duration }{time.
+ },
}
type inlineB struct {