Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
28cc70a5
Commit
28cc70a5
authored
Sep 11, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Julian day conversion function.
parent
c7b3ac8f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
0 deletions
+58
-0
Makefile
Makefile
+3
-0
date.go
date.go
+35
-0
date_test.go
date_test.go
+18
-0
sqlite.go
sqlite.go
+2
-0
No files found.
Makefile
View file @
28cc70a5
...
...
@@ -13,4 +13,7 @@ CGOFILES=\
trace.go
\
blob.go
GOFILES
=
\
date.go
include
$(GOROOT)/src/Make.pkg
date.go
0 → 100644
View file @
28cc70a5
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package sqlite provides access to the SQLite library, version 3.
package
sqlite
import
(
"time"
)
const
(
JULIAN_DAY
=
2440587.5
// 1970-01-01 00:00:00 is JD 2440587.5
DAY_IN_NANOSECONDS
=
60
*
60
*
24
*
10E6
)
func
JulianDayToUTC
(
jd
float64
)
*
time
.
Time
{
jd
-=
JULIAN_DAY
jd
*=
DAY_IN_NANOSECONDS
return
time
.
NanosecondsToUTC
(
int64
(
jd
))
}
func
JulianDayToLocalTime
(
jd
float64
)
*
time
.
Time
{
jd
-=
JULIAN_DAY
jd
*=
DAY_IN_NANOSECONDS
return
time
.
NanosecondsToLocalTime
(
int64
(
jd
))
}
func
JulianDay
(
t
*
time
.
Time
)
float64
{
ns
:=
float64
(
t
.
Nanoseconds
())
if
ns
>=
0
{
ns
+=
0.5
}
return
ns
/
DAY_IN_NANOSECONDS
+
JULIAN_DAY
}
date_test.go
0 → 100644
View file @
28cc70a5
package
sqlite
import
(
"testing"
"time"
)
func
TestJulianDay
(
t
*
testing
.
T
)
{
utc
:=
JulianDayToUTC
(
JULIAN_DAY
)
if
utc
.
Nanoseconds
()
!=
0
{
t
.
Errorf
(
"Error, expecting %d got %d"
,
0
,
utc
.
Nanoseconds
())
}
now
:=
time
.
LocalTime
()
r
:=
JulianDayToLocalTime
(
JulianDay
(
now
))
if
r
.
Nanoseconds
()
/
10000
!=
now
.
Nanoseconds
()
/
10000
{
// FIXME Rounding problem?
t
.
Errorf
(
"%#v <> %#v"
,
now
,
r
)
}
}
sqlite.go
View file @
28cc70a5
...
...
@@ -384,6 +384,8 @@ func (s *Stmt) Exec(args ...interface{}) os.Error {
return
nil
}
// Don't use it with SELECT or anything that returns data.
// Like Exec but returns the number of rows that were changed or inserted or deleted.
func
(
s
*
Stmt
)
ExecUpdate
(
args
...
interface
{})
(
int
,
os
.
Error
)
{
err
:=
s
.
Exec
(
args
...
)
if
err
!=
nil
{
...
...
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