Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
fdb09d28
Commit
fdb09d28
authored
Dec 10, 2011
by
Hector Chu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time: fix Time.Add
R=rsc, r CC=golang-dev
https://golang.org/cl/5448121
parent
1084ab98
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
time.go
src/pkg/time/time.go
+1
-1
time_test.go
src/pkg/time/time_test.go
+11
-0
No files found.
src/pkg/time/time.go
View file @
fdb09d28
...
...
@@ -548,7 +548,7 @@ func (d Duration) Hours() float64 {
func
(
t
Time
)
Add
(
d
Duration
)
Time
{
t
.
sec
+=
int64
(
d
/
1e9
)
t
.
nsec
+=
int32
(
d
%
1e9
)
if
t
.
nsec
>
1e9
{
if
t
.
nsec
>
=
1e9
{
t
.
sec
++
t
.
nsec
-=
1e9
}
else
if
t
.
nsec
<
0
{
...
...
src/pkg/time/time_test.go
View file @
fdb09d28
...
...
@@ -655,6 +655,17 @@ func TestDaysIn(t *testing.T) {
}
}
func
TestAddToExactSecond
(
t
*
testing
.
T
)
{
// Add an amount to the current time to round it up to the next exact second.
// This test checks that the nsec field still lies within the range [0, 999999999].
t1
:=
Now
()
t2
:=
t1
.
Add
(
Second
-
Duration
(
t1
.
Nanosecond
()))
sec
:=
(
t1
.
Second
()
+
1
)
%
60
if
t2
.
Second
()
!=
sec
||
t2
.
Nanosecond
()
!=
0
{
t
.
Errorf
(
"sec = %d, nsec = %d, want sec = %d, nsec = 0"
,
t2
.
Second
(),
t2
.
Nanosecond
(),
sec
)
}
}
func
BenchmarkNow
(
b
*
testing
.
B
)
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
Now
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment