@@ -70,7 +70,16 @@ def to_client_timezone(date)
7070 date - @timezone_offset . hours
7171 end
7272
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 )
7483 return nil unless is_date_operator? operator
7584
7685 filter = case operator
@@ -79,18 +88,18 @@ def get_date_filter(operator, value)
7988 when OPERATOR_PAST
8089 "<= '#{ Time . now } '"
8190 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 ) ) } '"
8493 when OPERATOR_PREVIOUS_X_DAYS
8594 ensure_integer_value ( value )
8695 "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 ) ) } '"
8998 when OPERATOR_PREVIOUS_X_DAYS_TO_DATE
9099 ensure_integer_value ( value )
91100 "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 ) } '"
94103 when OPERATOR_BEFORE_X_HOURS_AGO
95104 ensure_integer_value ( value )
96105 "< '#{ ( Integer ( value ) ) . hour . ago } '"
@@ -109,35 +118,35 @@ def get_date_filter(operator, value)
109118 to_date = PERIODS [ operator ] [ :to_date ]
110119
111120 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 )
114123 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 } " ) ) )
119128 end
120129
121130 "BETWEEN '#{ from } ' AND '#{ to } '"
122131 end
123132
124- def get_date_filter_for_previous_interval ( operator , value )
133+ def get_date_filter_for_previous_interval ( operator , value , field_schema )
125134 return nil unless has_previous_interval? operator
126135
127136 case operator
128137 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 ) ) } '"
131140 when OPERATOR_PREVIOUS_X_DAYS
132141 ensure_integer_value ( value )
133142 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 ) ) } '"
136145 when OPERATOR_PREVIOUS_X_DAYS_TO_DATE
137146 ensure_integer_value ( value )
138147 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 ) ) } '"
141150 end
142151
143152 duration = PERIODS [ operator ] [ :duration ]
@@ -146,14 +155,14 @@ def get_date_filter_for_previous_interval(operator, value)
146155 to_date = PERIODS [ operator ] [ :to_date ]
147156
148157 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 ) )
152161 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 } " ) ) )
157166 end
158167
159168 "BETWEEN '#{ from } ' AND '#{ to } '"
0 commit comments