Commit 28cc70a5 authored by gwenn's avatar gwenn

Add Julian day conversion function.

parent c7b3ac8f
......@@ -13,4 +13,7 @@ CGOFILES=\
trace.go\
blob.go
GOFILES=\
date.go
include $(GOROOT)/src/Make.pkg
// 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
}
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)
}
}
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment