Skip to content

Commit 77fc279

Browse files
adonovangopherbot
authored andcommitted
doc/next: improve new(expr) release note
One reader pointed out that the example isn't compelling because &age would have worked just as well. This CL changes the example to use a nontrivial expression. Don't nitpick the arithmetic. For golang#45624 Change-Id: Icc745f5ee7000c1d3559da1388c6a5596c4d1f46 Reviewed-on: https://go-review.googlesource.com/c/go/+/714040 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent d94a8c5 commit 77fc279

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

doc/next/2-language.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ type Person struct {
1919
Age *int `json:"age"` // age if known; nil otherwise
2020
}
2121

22-
func personJSON(name string, age int) ([]byte, error) {
22+
func personJSON(name string, born time.Time) ([]byte, error) {
2323
return json.Marshal(Person{
2424
Name: name,
25-
Age: new(age),
25+
Age: new(yearsSince(born)),
2626
})
2727
}
28+
29+
func yearsSince(t time.Time) int {
30+
return int(time.Since(t).Hours() / (365.25 * 24)) // approximately
31+
}
2832
```

0 commit comments

Comments
 (0)