-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatetime_tstzspan.go
More file actions
104 lines (90 loc) · 2.58 KB
/
datetime_tstzspan.go
File metadata and controls
104 lines (90 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package gomeos
/*
#include "meos.h"
#include <stdio.h>
#include <stdlib.h>
#include "cast.h"
*/
import "C"
import (
"fmt"
"time"
"unsafe"
"github.com/leekchan/timeutil"
)
type TsTzSpan struct {
_inner *C.Span
}
func NewTsTzSpan(g_tts_in string) *TsTzSpan {
c_tts_in := C.CString(g_tts_in)
defer C.free(unsafe.Pointer(c_tts_in))
c_tts := C.tstzspan_in(c_tts_in)
g_tts := &TsTzSpan{_inner: c_tts}
return g_tts
}
func (g_tts *TsTzSpan) TsTzSpanOut() string {
c_tts_out := C.tstzspan_out(g_tts._inner)
defer C.free(unsafe.Pointer(c_tts_out))
g_tts_out := C.GoString(c_tts_out)
return g_tts_out
}
func (g_tts *TsTzSpan) ToSpanSet() TsTzSpanSet {
c_ds := C.span_to_spanset(g_tts._inner)
return TsTzSpanSet{_inner: c_ds}
}
func (g_tts *TsTzSpan) Duration() timeutil.Timedelta {
duration := C.tstzspan_duration(g_tts._inner)
return IntervalToTimeDelta(*duration)
}
func (g_tts *TsTzSpan) Lower() time.Time {
s := C.tstzspan_lower(g_tts._inner)
return TimestamptzToDatetime(s)
}
func (g_tts *TsTzSpan) Upper() time.Time {
s := C.tstzspan_upper(g_tts._inner)
return TimestamptzToDatetime(s)
}
func (g_tss *TsTzSpan) ShiftScale(shift interface{}, duration interface{}) (*TsTzSpan, error) {
if shift == nil && duration == nil {
return nil, fmt.Errorf("shift and duration must not be both nil")
}
var shift_delta, duration_delta int
var shift_in, duration_in timeutil.Timedelta
var shift_interval, duration_interval C.Interval
switch s := shift.(type) {
case timeutil.Timedelta:
shift_delta = 1
shift_in = s
shift_interval = TimeDeltaToInterval(shift_in)
case nil:
shift_delta = 0
default:
return &TsTzSpan{}, fmt.Errorf("operation not supported with type %T", shift)
}
switch d := duration.(type) {
case timeutil.Timedelta:
duration_delta = 1
duration_in = d
duration_interval = TimeDeltaToInterval(duration_in)
case nil:
duration_delta = 0
default:
return &TsTzSpan{}, fmt.Errorf("operation not supported with type %T", duration)
}
if (shift_delta == 1) && (duration_delta == 1) {
tss := C.tstzspan_shift_scale(g_tss._inner, &shift_interval, &duration_interval)
return &TsTzSpan{_inner: tss}, nil
} else if shift_delta == 0 {
tss := C.tstzspan_shift_scale(g_tss._inner, nil, &duration_interval)
return &TsTzSpan{_inner: tss}, nil
} else {
tss := C.tstzspan_shift_scale(g_tss._inner, &shift_interval, nil)
return &TsTzSpan{_inner: tss}, nil
}
}
func (g_tss *TsTzSpan) Shift(delta interface{}) (*TsTzSpan, error) {
return g_tss.ShiftScale(delta, nil)
}
func (g_tss *TsTzSpan) Scale(duration interface{}) (*TsTzSpan, error) {
return g_tss.ShiftScale(nil, duration)
}