Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
d3e124d1
Commit
d3e124d1
authored
Oct 01, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into t
* master: go/zodb: Don't truncate Tid time precision to 1µs
parents
74f0c47b
9112f21e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
14 deletions
+25
-14
go/zodb/time.go
go/zodb/time.go
+11
-7
go/zodb/time_test.go
go/zodb/time_test.go
+14
-7
No files found.
go/zodb/time.go
View file @
d3e124d1
...
...
@@ -36,8 +36,17 @@ func (t TimeStamp) String() string {
}
func
(
t
TimeStamp
)
XFmtString
(
b
[]
byte
)
[]
byte
{
// NOTE UTC() in case we get TimeStamp with modified from-outside location
return
t
.
UTC
()
.
AppendFormat
(
b
,
"2006-01-02 15:04:05.000000"
)
// round to microsecond on formatting: zodb/py does this, and without rounding it is sometimes
// not exactly bit-to-bit the same in text output compared to zodb/py. Example:
// 037969f722a53488: timeStr = "2008-10-24 05:11:08.119999" ; want "2008-10-24 05:11:08.120000"
//
// This happens because Go's time.Format() does not perform rounding,
// and so even if t = 0.999, formatting it with .00 won't give 0.10.
//
// NOTE UTC() in case we get TimeStamp with modified from-outside location.
tµs
:=
t
.
UTC
()
.
Round
(
time
.
Microsecond
)
return
tµs
.
AppendFormat
(
b
,
"2006-01-02 15:04:05.000000"
)
}
...
...
@@ -65,11 +74,6 @@ func (tid Tid) Time() TimeStamp {
int
(
nsec
),
time
.
UTC
)
// round to microsecond: zodb/py does this, and without rounding it is sometimes
// not exactly bit-to-bit the same in text output compared to zodb/py. Example:
// 037969f722a53488: timeStr = "2008-10-24 05:11:08.119999" ; want "2008-10-24 05:11:08.120000"
t
=
t
.
Round
(
time
.
Microsecond
)
return
TimeStamp
{
t
}
}
...
...
go/zodb/time_test.go
View file @
d3e124d1
...
...
@@ -22,18 +22,25 @@ package zodb
import
"testing"
func
TestTidTime
(
t
*
testing
.
T
)
{
var
testv
=
[]
struct
{
tid
Tid
;
timeStr
string
}
{
{
0x0000000000000000
,
"1900-01-01 00:00:00.000000"
},
{
0x0285cbac258bf266
,
"1979-01-03 21:00:08.800000"
},
{
0x0285cbad27ae14e6
,
"1979-01-03 21:01:09.300001"
},
{
0x037969f722a53488
,
"2008-10-24 05:11:08.120000"
},
{
0x03b84285d71c57dd
,
"2016-07-01 09:41:50.416574"
},
var
testv
=
[]
struct
{
tid
Tid
;
timeStr
string
;
timeFloat
float64
}
{
{
0x0000000000000000
,
"1900-01-01 00:00:00.000000"
,
-
2208988800.000000000
},
{
0x0285cbac258bf266
,
"1979-01-03 21:00:08.800000"
,
284245208.800000191
},
{
0x0285cbad27ae14e6
,
"1979-01-03 21:01:09.300001"
,
284245269.300001502
},
{
0x037969f722a53488
,
"2008-10-24 05:11:08.120000"
,
1224825068.120000124
},
{
0x03b84285d71c57dd
,
"2016-07-01 09:41:50.416574"
,
1467366110.416574001
},
{
0x03caa84275fc1166
,
"2018-10-01 16:34:27.652650"
,
1538411667.652650118
},
}
for
_
,
tt
:=
range
testv
{
timeStr
:=
tt
.
tid
.
Time
()
.
String
()
tidtime
:=
tt
.
tid
.
Time
()
timeStr
:=
tidtime
.
String
()
if
timeStr
!=
tt
.
timeStr
{
t
.
Errorf
(
"%v: timeStr = %q ; want %q"
,
tt
.
tid
,
timeStr
,
tt
.
timeStr
)
}
timeFloat
:=
float64
(
tidtime
.
UnixNano
())
*
1E-9
if
timeFloat
!=
tt
.
timeFloat
{
t
.
Errorf
(
"%v: timeFloat = %.9f ; want %.9f"
,
tt
.
tid
,
timeFloat
,
tt
.
timeFloat
)
}
}
}
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