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
340387f5
Commit
340387f5
authored
Jan 28, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a55a9258
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
9 deletions
+49
-9
go/zodb/time.go
go/zodb/time.go
+35
-6
go/zodb/time_test.go
go/zodb/time_test.go
+14
-3
No files found.
go/zodb/time.go
View file @
340387f5
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
// Copyright (C) 2017
-2019
Nexedi SA and Contributors.
//
Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
...
...
@@ -53,7 +53,7 @@ func (t TimeStamp) XFmtString(b []byte) []byte {
// Time converts tid to time.
func
(
tid
Tid
)
Time
()
TimeStamp
{
// the same as _parseRaw in TimeStamp/py
// https://github.com/zopefoundation/persistent/blob/
aba23595/persistent/timestamp.py#L75
// https://github.com/zopefoundation/persistent/blob/
8c645429/persistent/timestamp.py#L72
a
:=
uint64
(
tid
)
>>
32
b
:=
uint64
(
tid
)
&
(
1
<<
32
-
1
)
min
:=
a
%
60
...
...
@@ -77,11 +77,40 @@ func (tid Tid) Time() TimeStamp {
return
TimeStamp
{
t
}
}
// TidFromTime converts time to tid.
func
TidFromTime
(
t
time
.
Time
)
Tid
{
t
=
t
.
UTC
()
// TODO TidFromTime()
// TODO TidFromTimeStamp()
// TODO TidForNow() ?
// the same as _makeRaw in TimeStamp/py
// https://github.com/zopefoundation/persistent/blob/8c645429/persistent/timestamp.py#L66
year
:=
uint64
(
t
.
Year
())
month
:=
uint64
(
t
.
Month
())
day
:=
uint64
(
t
.
Day
())
hour
:=
uint64
(
t
.
Hour
())
min
:=
uint64
(
t
.
Minute
())
sec
:=
uint64
(
t
.
Second
())
nsec
:=
uint64
(
t
.
Nanosecond
())
a
:=
((
year
-
1900
)
*
12
+
month
-
1
)
*
31
+
day
-
1
a
=
(
a
*
24
+
hour
)
*
60
+
min
// for seconds/nseconds: use 2 extra bits of precision to be able to
// round after / 1E9 and / 60 divisions. We are safe to use 2 bits,
// since 10^9 ≤ 2^30 and it all fits into uint32. However for b for
// intermediate values we are free to use whole uint64, so x can be >
// than 2 too.
const
x
=
2
b
:=
sec
<<
(
32
+
x
)
b
+=
(
nsec
<<
(
32
+
x
))
/
1E9
b
/=
60
roundup
:=
(
b
&
((
1
<<
x
)
-
1
))
>=
(
1
<<
(
x
-
1
))
b
/=
(
1
<<
x
)
if
roundup
{
b
+=
1
}
return
Tid
((
a
<<
32
)
|
b
)
}
// δtid returns distance from tid1 to tid2 in term of time.
//
...
...
go/zodb/time_test.go
View file @
340387f5
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
// Copyright (C) 2017
-2019
Nexedi SA and Contributors.
//
Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
...
...
@@ -19,7 +19,10 @@
package
zodb
import
"testing"
import
(
"testing"
"time"
)
func
TestTidTime
(
t
*
testing
.
T
)
{
var
testv
=
[]
struct
{
tid
Tid
;
timeStr
string
;
timeFloat
float64
}
{
...
...
@@ -42,5 +45,13 @@ func TestTidTime(t *testing.T) {
if
timeFloat
!=
tt
.
timeFloat
{
t
.
Errorf
(
"%v: timeFloat = %.9f ; want %.9f"
,
tt
.
tid
,
timeFloat
,
tt
.
timeFloat
)
}
locv
:=
[]
*
time
.
Location
{
time
.
UTC
,
time
.
FixedZone
(
"UTC+4"
,
+
4
*
60
*
60
)}
for
_
,
loc
:=
range
locv
{
tid
:=
TidFromTime
(
tidtime
.
In
(
loc
))
if
tid
!=
tt
.
tid
{
t
.
Errorf
(
"%v: ->time(%s)->tid != identity (= %v; δ: %s)"
,
tt
.
tid
,
loc
,
tid
,
tt
.
tid
-
tid
)
}
}
}
}
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