@@ -70,7 +70,16 @@ def to_client_timezone(date)
70
70
date - @timezone_offset . hours
71
71
end
72
72
73
- def get_date_filter ( operator , value )
73
+
74
+ def format_date ( field_type , value )
75
+ if field_type == 'Dateonly'
76
+ return value . strftime ( '%Y-%m-%d' )
77
+ end
78
+
79
+ value
80
+ end
81
+
82
+ def get_date_filter ( operator , value , field_schema )
74
83
return nil unless is_date_operator? operator
75
84
76
85
filter = case operator
@@ -79,18 +88,18 @@ def get_date_filter(operator, value)
79
88
when OPERATOR_PAST
80
89
"<= '#{ Time . now } '"
81
90
when OPERATOR_TODAY
82
- "BETWEEN '#{ to_client_timezone ( Time . now . beginning_of_day ) } ' " +
83
- "AND '#{ to_client_timezone ( Time . now . end_of_day ) } '"
91
+ "BETWEEN '#{ format_date ( field_schema [ :type ] , to_client_timezone ( Time . now . beginning_of_day ) ) } ' " +
92
+ "AND '#{ format_date ( field_schema [ :type ] , to_client_timezone ( Time . now . end_of_day ) ) } '"
84
93
when OPERATOR_PREVIOUS_X_DAYS
85
94
ensure_integer_value ( value )
86
95
"BETWEEN '" +
87
- "#{ to_client_timezone ( Integer ( value ) . day . ago . beginning_of_day ) } '" +
88
- " AND '#{ to_client_timezone ( 1 . day . ago . end_of_day ) } '"
96
+ "#{ format_date ( field_schema [ :type ] , to_client_timezone ( Integer ( value ) . day . ago . beginning_of_day ) ) } '" +
97
+ " AND '#{ format_date ( field_schema [ :type ] , to_client_timezone ( 1 . day . ago . end_of_day ) ) } '"
89
98
when OPERATOR_PREVIOUS_X_DAYS_TO_DATE
90
99
ensure_integer_value ( value )
91
100
"BETWEEN '" +
92
- "#{ to_client_timezone ( ( Integer ( value ) - 1 ) . day . ago . beginning_of_day ) } '" +
93
- " AND '#{ Time . now } '"
101
+ "#{ format_date ( field_schema [ :type ] , to_client_timezone ( ( Integer ( value ) - 1 ) . day . ago . beginning_of_day ) ) } '" +
102
+ " AND '#{ format_date ( field_schema [ :type ] , Time . now ) } '"
94
103
when OPERATOR_BEFORE_X_HOURS_AGO
95
104
ensure_integer_value ( value )
96
105
"< '#{ ( Integer ( value ) ) . hour . ago } '"
@@ -109,35 +118,35 @@ def get_date_filter(operator, value)
109
118
to_date = PERIODS [ operator ] [ :to_date ]
110
119
111
120
if to_date
112
- from = to_client_timezone ( Time . now . send ( "beginning_of_#{ period_of_time } " ) )
113
- to = Time . now
121
+ from = format_date ( field_schema [ :type ] , to_client_timezone ( Time . now . send ( "beginning_of_#{ period_of_time } " ) ) )
122
+ to = format_date ( field_schema [ :type ] , Time . now )
114
123
else
115
- from = to_client_timezone ( duration . send ( period ) . ago
116
- . send ( "beginning_of_#{ period_of_time } " ) )
117
- to = to_client_timezone ( duration . send ( period ) . ago
118
- . send ( "end_of_#{ period_of_time } " ) )
124
+ from = format_date ( field_schema [ :type ] , to_client_timezone ( duration . send ( period ) . ago
125
+ . send ( "beginning_of_#{ period_of_time } " ) ) )
126
+ to = format_date ( field_schema [ :type ] , to_client_timezone ( duration . send ( period ) . ago
127
+ . send ( "end_of_#{ period_of_time } " ) ) )
119
128
end
120
129
121
130
"BETWEEN '#{ from } ' AND '#{ to } '"
122
131
end
123
132
124
- def get_date_filter_for_previous_interval ( operator , value )
133
+ def get_date_filter_for_previous_interval ( operator , value , field_schema )
125
134
return nil unless has_previous_interval? operator
126
135
127
136
case operator
128
137
when OPERATOR_TODAY
129
- return "BETWEEN '#{ to_client_timezone ( 1 . day . ago . beginning_of_day ) } ' AND " +
130
- "'#{ to_client_timezone ( 1 . day . ago . end_of_day ) } '"
138
+ return "BETWEEN '#{ format_date ( field_schema [ :type ] , to_client_timezone ( 1 . day . ago . beginning_of_day ) ) } ' AND " +
139
+ "'#{ format_date ( field_schema [ :type ] , to_client_timezone ( 1 . day . ago . end_of_day ) ) } '"
131
140
when OPERATOR_PREVIOUS_X_DAYS
132
141
ensure_integer_value ( value )
133
142
return "BETWEEN '" +
134
- "#{ to_client_timezone ( ( Integer ( value ) * 2 ) . day . ago . beginning_of_day ) } '" +
135
- " AND '#{ to_client_timezone ( ( Integer ( value ) + 1 ) . day . ago . end_of_day ) } '"
143
+ "#{ format_date ( field_schema [ :type ] , to_client_timezone ( ( Integer ( value ) * 2 ) . day . ago . beginning_of_day ) ) } '" +
144
+ " AND '#{ format_date ( field_schema [ :type ] , to_client_timezone ( ( Integer ( value ) + 1 ) . day . ago . end_of_day ) ) } '"
136
145
when OPERATOR_PREVIOUS_X_DAYS_TO_DATE
137
146
ensure_integer_value ( value )
138
147
return "BETWEEN '" +
139
- "#{ to_client_timezone ( ( ( Integer ( value ) * 2 ) - 1 ) . day . ago . beginning_of_day ) } '" +
140
- " AND '#{ to_client_timezone ( Integer ( value ) . day . ago ) } '"
148
+ "#{ format_date ( field_schema [ :type ] , to_client_timezone ( ( ( Integer ( value ) * 2 ) - 1 ) . day . ago . beginning_of_day ) ) } '" +
149
+ " AND '#{ format_date ( field_schema [ :type ] , to_client_timezone ( Integer ( value ) . day . ago ) ) } '"
141
150
end
142
151
143
152
duration = PERIODS [ operator ] [ :duration ]
@@ -146,14 +155,14 @@ def get_date_filter_for_previous_interval(operator, value)
146
155
to_date = PERIODS [ operator ] [ :to_date ]
147
156
148
157
if to_date
149
- from = to_client_timezone ( ( duration )
150
- . send ( period ) . ago . send ( "beginning_of_#{ period_of_time } " ) )
151
- to = to_client_timezone ( ( duration ) . send ( period ) . ago )
158
+ from = format_date ( field_schema [ :type ] , to_client_timezone ( ( duration )
159
+ . send ( period ) . ago . send ( "beginning_of_#{ period_of_time } " ) ) )
160
+ to = format_date ( field_schema [ :type ] , to_client_timezone ( ( duration ) . send ( period ) . ago ) )
152
161
else
153
- from = to_client_timezone ( ( duration * 2 ) . send ( period ) . ago
154
- . send ( "beginning_of_#{ period_of_time } " ) )
155
- to = to_client_timezone ( ( duration * 2 ) . send ( period ) . ago
156
- . send ( "end_of_#{ period_of_time } " ) )
162
+ from = format_date ( field_schema [ :type ] , to_client_timezone ( ( duration * 2 ) . send ( period ) . ago
163
+ . send ( "beginning_of_#{ period_of_time } " ) ) )
164
+ to = format_date ( field_schema [ :type ] , to_client_timezone ( ( duration * 2 ) . send ( period ) . ago
165
+ . send ( "end_of_#{ period_of_time } " ) ) )
157
166
end
158
167
159
168
"BETWEEN '#{ from } ' AND '#{ to } '"
0 commit comments