File: query_time.go

package info (click to toggle)
golang-gopkg-dancannon-gorethink.v1 1.4.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 764 kB
  • sloc: makefile: 3
file content (187 lines) | stat: -rw-r--r-- 8,480 bytes parent folder | download | duplicates (2)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package gorethink

import (
	p "gopkg.in/dancannon/gorethink.v1/ql2"
)

// Now returns a time object representing the current time in UTC
func Now(args ...interface{}) Term {
	return constructRootTerm("Now", p.Term_NOW, args, map[string]interface{}{})
}

// Time creates a time object for a specific time
func Time(args ...interface{}) Term {
	return constructRootTerm("Time", p.Term_TIME, args, map[string]interface{}{})
}

// EpochTime returns a time object based on seconds since epoch
func EpochTime(args ...interface{}) Term {
	return constructRootTerm("EpochTime", p.Term_EPOCH_TIME, args, map[string]interface{}{})
}

// ISO8601Opts contains the optional arguments for the ISO8601 term
type ISO8601Opts struct {
	DefaultTimezone interface{} `gorethink:"default_timezone,omitempty"`
}

func (o *ISO8601Opts) toMap() map[string]interface{} {
	return optArgsToMap(o)
}

// ISO8601 returns a time object based on an ISO8601 formatted date-time string
func ISO8601(date interface{}, optArgs ...ISO8601Opts) Term {

	opts := map[string]interface{}{}
	if len(optArgs) >= 1 {
		opts = optArgs[0].toMap()
	}
	return constructRootTerm("ISO8601", p.Term_ISO8601, []interface{}{date}, opts)
}

// InTimezone returns a new time object with a different time zone. While the
// time stays the same, the results returned by methods such as hours() will
// change since they take the timezone into account. The timezone argument
// has to be of the ISO 8601 format.
func (t Term) InTimezone(args ...interface{}) Term {
	return constructMethodTerm(t, "InTimezone", p.Term_IN_TIMEZONE, args, map[string]interface{}{})
}

// Timezone returns the timezone of the time object
func (t Term) Timezone(args ...interface{}) Term {
	return constructMethodTerm(t, "Timezone", p.Term_TIMEZONE, args, map[string]interface{}{})
}

// DuringOpts contains the optional arguments for the During term
type DuringOpts struct {
	LeftBound  interface{} `gorethink:"left_bound,omitempty"`
	RightBound interface{} `gorethink:"right_bound,omitempty"`
}

func (o *DuringOpts) toMap() map[string]interface{} {
	return optArgsToMap(o)
}

// During returns true if a time is between two other times
// (by default, inclusive for the start, exclusive for the end).
func (t Term) During(startTime, endTime interface{}, optArgs ...DuringOpts) Term {
	opts := map[string]interface{}{}
	if len(optArgs) >= 1 {
		opts = optArgs[0].toMap()
	}
	return constructMethodTerm(t, "During", p.Term_DURING, []interface{}{startTime, endTime}, opts)
}

// Date returns a new time object only based on the day, month and year
// (ie. the same day at 00:00).
func (t Term) Date(args ...interface{}) Term {
	return constructMethodTerm(t, "Date", p.Term_DATE, args, map[string]interface{}{})
}

// TimeOfDay returns the number of seconds elapsed since the beginning of the
// day stored in the time object.
func (t Term) TimeOfDay(args ...interface{}) Term {
	return constructMethodTerm(t, "TimeOfDay", p.Term_TIME_OF_DAY, args, map[string]interface{}{})
}

// Year returns the year of a time object.
func (t Term) Year(args ...interface{}) Term {
	return constructMethodTerm(t, "Year", p.Term_YEAR, args, map[string]interface{}{})
}

// Month returns the month of a time object as a number between 1 and 12.
// For your convenience, the terms r.January(), r.February() etc. are
// defined and map to the appropriate integer.
func (t Term) Month(args ...interface{}) Term {
	return constructMethodTerm(t, "Month", p.Term_MONTH, args, map[string]interface{}{})
}

// Day return the day of a time object as a number between 1 and 31.
func (t Term) Day(args ...interface{}) Term {
	return constructMethodTerm(t, "Day", p.Term_DAY, args, map[string]interface{}{})
}

// DayOfWeek returns the day of week of a time object as a number between
// 1 and 7 (following ISO 8601 standard). For your convenience,
// the terms r.Monday(), r.Tuesday() etc. are defined and map to
// the appropriate integer.
func (t Term) DayOfWeek(args ...interface{}) Term {
	return constructMethodTerm(t, "DayOfWeek", p.Term_DAY_OF_WEEK, args, map[string]interface{}{})
}

// DayOfYear returns the day of the year of a time object as a number between
// 1 and 366 (following ISO 8601 standard).
func (t Term) DayOfYear(args ...interface{}) Term {
	return constructMethodTerm(t, "DayOfYear", p.Term_DAY_OF_YEAR, args, map[string]interface{}{})
}

// Hours returns the hour in a time object as a number between 0 and 23.
func (t Term) Hours(args ...interface{}) Term {
	return constructMethodTerm(t, "Hours", p.Term_HOURS, args, map[string]interface{}{})
}

// Minutes returns the minute in a time object as a number between 0 and 59.
func (t Term) Minutes(args ...interface{}) Term {
	return constructMethodTerm(t, "Minutes", p.Term_MINUTES, args, map[string]interface{}{})
}

// Seconds returns the seconds in a time object as a number between 0 and
// 59.999 (double precision).
func (t Term) Seconds(args ...interface{}) Term {
	return constructMethodTerm(t, "Seconds", p.Term_SECONDS, args, map[string]interface{}{})
}

// ToISO8601 converts a time object to its iso 8601 format.
func (t Term) ToISO8601(args ...interface{}) Term {
	return constructMethodTerm(t, "ToISO8601", p.Term_TO_ISO8601, args, map[string]interface{}{})
}

// ToEpochTime converts a time object to its epoch time.
func (t Term) ToEpochTime(args ...interface{}) Term {
	return constructMethodTerm(t, "ToEpochTime", p.Term_TO_EPOCH_TIME, args, map[string]interface{}{})
}

var (
	// Days

	// Monday is a constant representing the day of the week Monday
	Monday = constructRootTerm("Monday", p.Term_MONDAY, []interface{}{}, map[string]interface{}{})
	// Tuesday is a constant representing the day of the week Tuesday
	Tuesday = constructRootTerm("Tuesday", p.Term_TUESDAY, []interface{}{}, map[string]interface{}{})
	// Wednesday is a constant representing the day of the week Wednesday
	Wednesday = constructRootTerm("Wednesday", p.Term_WEDNESDAY, []interface{}{}, map[string]interface{}{})
	// Thursday is a constant representing the day of the week Thursday
	Thursday = constructRootTerm("Thursday", p.Term_THURSDAY, []interface{}{}, map[string]interface{}{})
	// Friday is a constant representing the day of the week Friday
	Friday = constructRootTerm("Friday", p.Term_FRIDAY, []interface{}{}, map[string]interface{}{})
	// Saturday is a constant representing the day of the week Saturday
	Saturday = constructRootTerm("Saturday", p.Term_SATURDAY, []interface{}{}, map[string]interface{}{})
	// Sunday is a constant representing the day of the week Sunday
	Sunday = constructRootTerm("Sunday", p.Term_SUNDAY, []interface{}{}, map[string]interface{}{})

	// Months

	// January is a constant representing the month January
	January = constructRootTerm("January", p.Term_JANUARY, []interface{}{}, map[string]interface{}{})
	// February is a constant representing the month February
	February = constructRootTerm("February", p.Term_FEBRUARY, []interface{}{}, map[string]interface{}{})
	// March is a constant representing the month March
	March = constructRootTerm("March", p.Term_MARCH, []interface{}{}, map[string]interface{}{})
	// April is a constant representing the month April
	April = constructRootTerm("April", p.Term_APRIL, []interface{}{}, map[string]interface{}{})
	// May is a constant representing the month May
	May = constructRootTerm("May", p.Term_MAY, []interface{}{}, map[string]interface{}{})
	// June is a constant representing the month June
	June = constructRootTerm("June", p.Term_JUNE, []interface{}{}, map[string]interface{}{})
	// July is a constant representing the month July
	July = constructRootTerm("July", p.Term_JULY, []interface{}{}, map[string]interface{}{})
	// August is a constant representing the month August
	August = constructRootTerm("August", p.Term_AUGUST, []interface{}{}, map[string]interface{}{})
	// September is a constant representing the month September
	September = constructRootTerm("September", p.Term_SEPTEMBER, []interface{}{}, map[string]interface{}{})
	// October is a constant representing the month October
	October = constructRootTerm("October", p.Term_OCTOBER, []interface{}{}, map[string]interface{}{})
	// November is a constant representing the month November
	November = constructRootTerm("November", p.Term_NOVEMBER, []interface{}{}, map[string]interface{}{})
	// December is a constant representing the month December
	December = constructRootTerm("December", p.Term_DECEMBER, []interface{}{}, map[string]interface{}{})
)