Class: Refine::Conditions::DateCondition
- Inherits:
-
Condition
- Object
- Condition
- Refine::Conditions::DateCondition
show all
- Includes:
- ActiveModel::Validations, HasClauses
- Defined in:
- app/models/refine/conditions/date_condition.rb
Constant Summary
collapse
- CLAUSE_EQUALS =
Clauses::EQUALS
- CLAUSE_DOESNT_EQUAL =
Clauses::DOESNT_EQUAL
- CLAUSE_LESS_THAN =
Clauses::LESS_THAN
- CLAUSE_LESS_THAN_OR_EQUAL =
Clauses::LESS_THAN_OR_EQUAL
- CLAUSE_GREATER_THAN =
Clauses::GREATER_THAN
- CLAUSE_GREATER_THAN_OR_EQUAL =
Clauses::GREATER_THAN_OR_EQUAL
- CLAUSE_BETWEEN =
Clauses::BETWEEN
- CLAUSE_NOT_BETWEEN =
Clauses::NOT_BETWEEN
- CLAUSE_EXACTLY =
Clauses::EXACTLY
- CLAUSE_SET =
Clauses::SET
- CLAUSE_NOT_SET =
Clauses::NOT_SET
- ATTRIBUTE_TYPE_DATE =
0
- ATTRIBUTE_TYPE_DATE_WITH_TIME =
1
- ATTRIBUTE_TYPE_UNIX_TIMESTAMP =
2
- I18N_PREFIX =
"refine.refine_blueprints.date_condition."
SupportsFlatQueries::LEFT_JOIN_CLAUSES
Instance Attribute Summary collapse
Attributes inherited from Condition
#attribute, #before_validations, #clause, #display, #ensurances, #filter, #id, #is_flat_query, #is_refinement
Instance Method Summary
collapse
-
#apply_clause_between(table, first_date, second_date) ⇒ Object
-
#apply_clause_doesnt_equal(value, table) ⇒ Object
-
#apply_clause_equals(value, table) ⇒ Object
-
#apply_clause_greater_than(value, table) ⇒ Object
-
#apply_clause_greater_than_or_equal(value, table) ⇒ Object
-
#apply_clause_less_than(value, table) ⇒ Object
-
#apply_clause_less_than_or_equal(value, table) ⇒ Object
-
#apply_clause_not_between(table, first_date, second_date) ⇒ Object
-
#apply_clause_not_set(table) ⇒ Object
-
#apply_clause_set(table) ⇒ Object
-
#apply_condition(input, table, _inverse_clause) ⇒ Object
-
#apply_standardized_values(table) ⇒ Object
-
#apply_standardized_values_with_time(table) ⇒ Object
-
#attribute_is(type) ⇒ Object
-
#attribute_is_date ⇒ Object
-
#attribute_is_date_with_time ⇒ Object
-
#attribute_is_unix_timestamp ⇒ Object
-
#boot ⇒ Object
-
#clauses ⇒ Object
-
#comparison_date(input) ⇒ Object
-
#comparison_time(day) ⇒ Object
-
#component ⇒ Object
-
#database_timezone ⇒ Object
-
#date1_must_be_less_than_date2 ⇒ Object
-
#date1_must_be_real ⇒ Object
-
#date2_must_be_real ⇒ Object
-
#end_of_day(day) ⇒ Object
-
#ensure_timezone ⇒ Object
-
#get_standard_tz_offset(offset_string) ⇒ Object
We should probably consider using tzinfo or some other library for this in the future.
-
#get_timezone(zone) ⇒ Object
-
#human_readable(input) ⇒ Object
-
#human_readable_value(input) ⇒ Object
-
#is_relative_clause? ⇒ Boolean
-
#modify_date_and_clause!(input) ⇒ Object
-
#relative_clauses ⇒ Object
-
#set_input_parameters(input) ⇒ Object
-
#standardize_clause(input) ⇒ Object
-
#start_of_day(day) ⇒ Object
-
#timezone_abbr ⇒ Object
Returns the string representation of the timezone localized if you don't already have a Time object to work with NOTE: It is possible for a timezone to not have an acceptable abbreviation.
-
#timezone_exists(zone) ⇒ Object
-
#user_timezone ⇒ Object
-
#with_database_timezone(timezone) ⇒ Object
-
#with_human_readable_timezone(show) ⇒ Object
-
#with_user_timezone(timezone) ⇒ Object
Methods included from HasClauses
#before_clause_validation, #boot_has_clauses, #clause_display_map, #custom_clauses, #ensure_clause, #ensure_clauses, #get_clause_by_id, #get_clauses, included, #only_clauses, #remap_clause_displays, #update_show_clauses, #with_clauses, #without_clauses
Methods inherited from Condition
#add_ensurance, #add_messages, #add_rules, #apply, #approved_clauses, #before_validate, #boot_traits, #call_proc_if_callable, #clause_display, #clause_exists?, #clause_in_approved_list?, #ensure_attribute_configured, #ensure_id, #evaluated_meta, #initialize, #messages, #recursively_evaluate_lazy_enumerable, #run_before_validate_validations, #run_ensurance_validations, #set_filter, #to_array, #update_value, #validate_user_input, #with_display
#add_pending_join, #add_pending_joins_if_needed, #apply_flat, #apply_flat_relational_condition, #condition_uses_different_database?, #get_foreign_key_from_relation, #get_through_reflection, #handle_flat_cross_database_condition, #handle_flat_relational_condition
Methods included from HasIcon
#category_icon_class, #category_icon_template, #has_icon?, #icon_class, #icon_container_class, #icon_template, #with_category_icon_class, #with_category_icon_template, #with_icon, #with_icon_class, #with_icon_container_class, #with_icon_template
#forced_index, #with_forced_index
#through_id_relationship, #with_through_id_relationship
#apply_count_refinement, #apply_date_refinement, #apply_refinements, #define_count_condition, #define_date_condition, #get_count_refinement_condition, #get_date_refinement_condition, #has_any_refinements?, #has_count_refinement?, #has_date_refinement?, #refine_by_count, #refine_by_date, #refine_by_filter, #refinements_allowed?, #refinements_to_array
#apply_relationship_attribute, #can_use_where_in_relationship_subquery?, #create_pending_has_many_through_subquery, #create_pending_wherein_subquery, #get_reflection_object, #group, #is_relationship_attribute?, #key_1, #key_2, #raw_attribute, #should_inverse_clause?, #with_attribute
Methods included from HasMeta
#meta, #with_meta
Instance Attribute Details
#date1 ⇒ Object
Returns the value of attribute date1.
10
11
12
|
# File 'app/models/refine/conditions/date_condition.rb', line 10
def date1
@date1
end
|
#date2 ⇒ Object
Returns the value of attribute date2.
10
11
12
|
# File 'app/models/refine/conditions/date_condition.rb', line 10
def date2
@date2
end
|
#days ⇒ Object
Returns the value of attribute days.
10
11
12
|
# File 'app/models/refine/conditions/date_condition.rb', line 10
def days
@days
end
|
#show_human_readable_timezone ⇒ Object
Returns the value of attribute show_human_readable_timezone.
10
11
12
|
# File 'app/models/refine/conditions/date_condition.rb', line 10
def show_human_readable_timezone
@show_human_readable_timezone
end
|
Instance Method Details
#apply_clause_between(table, first_date, second_date) ⇒ Object
424
425
426
|
# File 'app/models/refine/conditions/date_condition.rb', line 424
def apply_clause_between(table, first_date, second_date)
table.grouping(table[:"#{attribute}"].between(first_date..second_date))
end
|
#apply_clause_doesnt_equal(value, table) ⇒ Object
436
437
438
|
# File 'app/models/refine/conditions/date_condition.rb', line 436
def apply_clause_doesnt_equal(value, table)
table.grouping(table[:"#{attribute}"].not_eq(value).or(table[:"#{attribute}"].eq(nil)))
end
|
#apply_clause_equals(value, table) ⇒ Object
432
433
434
|
# File 'app/models/refine/conditions/date_condition.rb', line 432
def apply_clause_equals(value, table)
table.grouping(table[:"#{attribute}"].eq(value))
end
|
#apply_clause_greater_than(value, table) ⇒ Object
440
441
442
|
# File 'app/models/refine/conditions/date_condition.rb', line 440
def apply_clause_greater_than(value, table)
table.grouping(table[:"#{attribute}"].gt(value))
end
|
#apply_clause_greater_than_or_equal(value, table) ⇒ Object
444
445
446
|
# File 'app/models/refine/conditions/date_condition.rb', line 444
def apply_clause_greater_than_or_equal(value, table)
table.grouping(table[:"#{attribute}"].gteq(value))
end
|
#apply_clause_less_than(value, table) ⇒ Object
448
449
450
|
# File 'app/models/refine/conditions/date_condition.rb', line 448
def apply_clause_less_than(value, table)
table.grouping(table[:"#{attribute}"].lt(value))
end
|
#apply_clause_less_than_or_equal(value, table) ⇒ Object
452
453
454
|
# File 'app/models/refine/conditions/date_condition.rb', line 452
def apply_clause_less_than_or_equal(value, table)
table.grouping(table[:"#{attribute}"].lteq(value))
end
|
#apply_clause_not_between(table, first_date, second_date) ⇒ Object
428
429
430
|
# File 'app/models/refine/conditions/date_condition.rb', line 428
def apply_clause_not_between(table, first_date, second_date)
table.grouping(table[:"#{attribute}"].not_between(first_date..second_date))
end
|
#apply_clause_not_set(table) ⇒ Object
460
461
462
|
# File 'app/models/refine/conditions/date_condition.rb', line 460
def apply_clause_not_set(table)
table.grouping(table[:"#{attribute}"].eq(nil))
end
|
#apply_clause_set(table) ⇒ Object
456
457
458
|
# File 'app/models/refine/conditions/date_condition.rb', line 456
def apply_clause_set(table)
table.grouping(table[:"#{attribute}"].not_eq(nil))
end
|
#apply_condition(input, table, _inverse_clause) ⇒ Object
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
# File 'app/models/refine/conditions/date_condition.rb', line 277
def apply_condition(input, table, _inverse_clause)
if clause == CLAUSE_SET
return apply_clause_set(table)
end
if clause == CLAUSE_NOT_SET
return apply_clause_not_set(table)
end
modify_date_and_clause!(input) if is_relative_clause?
if @attribute_type == ATTRIBUTE_TYPE_DATE
apply_standardized_values(table)
else
apply_standardized_values_with_time(table)
end
end
|
#apply_standardized_values(table) ⇒ Object
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
# File 'app/models/refine/conditions/date_condition.rb', line 399
def apply_standardized_values(table)
case clause
when CLAUSE_EQUALS
apply_clause_equals(date1, table)
when CLAUSE_DOESNT_EQUAL
apply_clause_doesnt_equal(date1, table)
when CLAUSE_LESS_THAN
apply_clause_less_than(date1, table)
when CLAUSE_GREATER_THAN
apply_clause_greater_than(date1, table)
when CLAUSE_GREATER_THAN_OR_EQUAL
apply_clause_greater_than_or_equal(date1, table)
when CLAUSE_LESS_THAN_OR_EQUAL
apply_clause_less_than_or_equal(date1, table)
when CLAUSE_BETWEEN
apply_clause_between(table, date1, date2)
end
end
|
#apply_standardized_values_with_time(table) ⇒ Object
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
# File 'app/models/refine/conditions/date_condition.rb', line 362
def apply_standardized_values_with_time(table)
case clause
when CLAUSE_EQUALS
apply_clause_between(table, start_of_day(date1), end_of_day(date1))
when CLAUSE_BETWEEN
apply_clause_between(table, start_of_day(date1), end_of_day(date2))
when CLAUSE_DOESNT_EQUAL
apply_clause_not_between(table, start_of_day(date1), end_of_day(date1))
when CLAUSE_NOT_BETWEEN
apply_clause_not_between(table, start_of_day(date1), end_of_day(date2))
when CLAUSE_LESS_THAN
apply_clause_less_than(comparison_time(date1), table)
when CLAUSE_GREATER_THAN
apply_clause_greater_than(comparison_time(date1), table)
when CLAUSE_GREATER_THAN_OR_EQUAL
if Refine::Rails.configuration.date_gte_uses_bod
datetime = start_of_day(date1)
else
datetime = comparison_time(date1)
end
apply_clause_greater_than_or_equal(datetime, table)
when CLAUSE_LESS_THAN_OR_EQUAL
if Refine::Rails.configuration.date_lte_uses_eod
datetime = end_of_day(date1)
else
datetime = comparison_time(date1)
end
apply_clause_less_than_or_equal(datetime, table)
end
end
|
#attribute_is(type) ⇒ Object
197
198
199
200
|
# File 'app/models/refine/conditions/date_condition.rb', line 197
def attribute_is(type)
@attribute_type = type
self
end
|
#attribute_is_date ⇒ Object
183
184
185
186
|
# File 'app/models/refine/conditions/date_condition.rb', line 183
def attribute_is_date
attribute_is(ATTRIBUTE_TYPE_DATE)
self
end
|
#attribute_is_date_with_time ⇒ Object
188
189
190
191
|
# File 'app/models/refine/conditions/date_condition.rb', line 188
def attribute_is_date_with_time
attribute_is(ATTRIBUTE_TYPE_DATE_WITH_TIME)
self
end
|
#attribute_is_unix_timestamp ⇒ Object
193
194
195
|
# File 'app/models/refine/conditions/date_condition.rb', line 193
def attribute_is_unix_timestamp attribute_is(ATTRIBUTE_TYPE_UNIX_TIMESTAMP)
end
|
#boot ⇒ Object
64
65
66
67
|
# File 'app/models/refine/conditions/date_condition.rb', line 64
def boot
@attribute_type = @attribute_type ||= ATTRIBUTE_TYPE_DATE
add_ensurance(ensure_timezone)
end
|
#clauses ⇒ Object
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
# File 'app/models/refine/conditions/date_condition.rb', line 229
def clauses
[
Clause.new(CLAUSE_EQUALS, I18n.t("#{I18N_PREFIX}is_on"))
.requires_inputs("date1"),
Clause.new(CLAUSE_DOESNT_EQUAL, I18n.t("#{I18N_PREFIX}not_on"))
.requires_inputs("date1"),
Clause.new(CLAUSE_LESS_THAN_OR_EQUAL, I18n.t("#{I18N_PREFIX}is_on_or_before"))
.requires_inputs("date1"),
Clause.new(CLAUSE_GREATER_THAN_OR_EQUAL, I18n.t("#{I18N_PREFIX}is_on_or_after"))
.requires_inputs("date1"),
Clause.new(CLAUSE_BETWEEN, I18n.t("#{I18N_PREFIX}is_between"))
.requires_inputs(["date1", "date2"]),
Clause.new(CLAUSE_NOT_BETWEEN, I18n.t("#{I18N_PREFIX}is_not_between"))
.requires_inputs(["date1", "date2"]),
Clause.new(CLAUSE_GREATER_THAN, I18n.t("#{I18N_PREFIX}is_more_than"))
.requires_inputs(["days", "modifier"]),
Clause.new(CLAUSE_EXACTLY, I18n.t("#{I18N_PREFIX}is"))
.requires_inputs(["days", "modifier"]),
Clause.new(CLAUSE_LESS_THAN, I18n.t("#{I18N_PREFIX}is_less_than"))
.requires_inputs(["days", "modifier"]),
Clause.new(CLAUSE_SET, I18n.t("#{I18N_PREFIX}is_set")),
Clause.new(CLAUSE_NOT_SET, I18n.t("#{I18N_PREFIX}is_not_set")),
]
end
|
#comparison_date(input) ⇒ Object
296
297
298
299
300
301
302
303
304
305
306
307
|
# File 'app/models/refine/conditions/date_condition.rb', line 296
def comparison_date(input)
modified_days = days.to_i
modifier = input[:modifier]
if modifier == "ago"
modified_days *= - 1
end
(Date.current + modified_days).strftime("%Y-%m-%d")
end
|
#comparison_time(day) ⇒ Object
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
# File 'app/models/refine/conditions/date_condition.rb', line 344
def comparison_time(day)
current_time = Time.current.in_time_zone(user_timezone)
day_in_user_tz = day.to_time(:utc).in_time_zone(user_timezone)
options = {hour: current_time.hour, min: current_time.min, sec: current_time.sec}
day_time_shifted = day_in_user_tz.change(options)
database_local = day_time_shifted.in_time_zone(database_timezone)
offset = database_local.utc_offset
utc_comparison_time = database_local.in_time_zone("UTC")
utc_comparison_time + offset
end
|
#component ⇒ Object
87
88
89
|
# File 'app/models/refine/conditions/date_condition.rb', line 87
def component
"date-condition"
end
|
#database_timezone ⇒ Object
225
226
227
|
# File 'app/models/refine/conditions/date_condition.rb', line 225
def database_timezone
get_timezone(@database_timezone ||= @@default_database_timezone)
end
|
#date1_must_be_less_than_date2 ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'app/models/refine/conditions/date_condition.rb', line 54
def date1_must_be_less_than_date2
return true unless [CLAUSE_BETWEEN, CLAUSE_NOT_BETWEEN].include?(@clause) && date1 && date2
if Date.strptime(date1, "%Y-%m-%d") > Date.strptime(date2, "%Y-%m-%d")
errors.add(:base, I18n.t("#{I18N_PREFIX}date1_greater_date2_error"))
false
else
true
end
end
|
#date1_must_be_real ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'app/models/refine/conditions/date_condition.rb', line 34
def date1_must_be_real
return true unless date1
begin
Date.strptime(date1, "%Y-%m-%d")
rescue ArgumentError
errors.add(:base, I18n.t("#{I18N_PREFIX}date1_error"))
false
end
end
|
#date2_must_be_real ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'app/models/refine/conditions/date_condition.rb', line 44
def date2_must_be_real
return true unless date2
begin
Date.strptime(date2, "%Y-%m-%d")
rescue ArgumentError
errors.add(:base, I18n.t("#{I18N_PREFIX}date2_error"))
false
end
end
|
#end_of_day(day) ⇒ Object
335
336
337
338
339
340
341
342
|
# File 'app/models/refine/conditions/date_condition.rb', line 335
def end_of_day(day)
day_in_user_tz = day.in_time_zone(user_timezone)
end_of_day = day_in_user_tz.end_of_day
database_local = end_of_day.in_time_zone(database_timezone)
offset = database_local.utc_offset
utc_end = database_local.in_time_zone("UTC")
utc_end + offset
end
|
#ensure_timezone ⇒ Object
75
76
77
78
79
80
|
# File 'app/models/refine/conditions/date_condition.rb', line 75
def ensure_timezone
proc do
timezone_exists(database_timezone)
timezone_exists(user_timezone)
end
end
|
#get_standard_tz_offset(offset_string) ⇒ Object
We should probably consider using tzinfo or some other library for this in the future
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'app/models/refine/conditions/date_condition.rb', line 109
def get_standard_tz_offset(offset_string)
stripped = offset_string.strip
matches = stripped.match /^\s*\(([+-]?)(\d{1,4})\)\s*$/
unless matches.length > 1
return offset_string
end
sign = matches[1]
digits = matches[2].ljust(4, '0')
gmt_offset = " (GMT#{sign}#{digits[0..1]}:#{digits[2..3]})"
gmt_offset
end
|
#get_timezone(zone) ⇒ Object
217
218
219
|
# File 'app/models/refine/conditions/date_condition.rb', line 217
def get_timezone(zone)
call_proc_if_callable(zone)
end
|
#human_readable(input) ⇒ Object
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
|
# File 'app/models/refine/conditions/date_condition.rb', line 123
def human_readable(input)
current_clause = get_clause_by_id(input[:clause])
case input[:clause]
when *[CLAUSE_EQUALS, CLAUSE_DOESNT_EQUAL, CLAUSE_LESS_THAN_OR_EQUAL, CLAUSE_GREATER_THAN_OR_EQUAL]
formatted_date1 = I18n.l(input[:date1].to_date, format: :dmy)
"#{display} #{current_clause.display} #{formatted_date1}#{timezone_abbr}"
when *[CLAUSE_BETWEEN, CLAUSE_NOT_BETWEEN]
formatted_date1 = I18n.l(input[:date1].to_date, format: :dmy)
formatted_date2 = I18n.l(input[:date2].to_date, format: :dmy)
and_i18n = I18n.t("#{I18N_PREFIX}and")
if formatted_date1 == formatted_date2
"#{display} #{get_clause_by_id(CLAUSE_EQUALS).display} #{formatted_date1}#{timezone_abbr}"
else
"#{display} #{current_clause.display} #{formatted_date1} #{and_i18n} #{formatted_date2}#{timezone_abbr}"
end
when *[CLAUSE_GREATER_THAN, CLAUSE_LESS_THAN, CLAUSE_EXACTLY]
days_i18n = I18n.t("#{I18N_PREFIX}days")
ago_i18n = I18n.t("#{I18N_PREFIX}ago")
from_now_i18n = I18n.t("#{I18N_PREFIX}from_now")
"#{display} #{current_clause.display} #{input[:days]} #{days_i18n} #{input[:modifier] == 'ago' ? ago_i18n : from_now_i18n}#{timezone_abbr}"
when *[CLAUSE_SET, CLAUSE_NOT_SET]
"#{display} #{current_clause.display}"
else
not_supported_i18n = I18n.t("#{I18N_PREFIX}not_supported")
raise "#{input[:clause]} #{not_supported_i18n}"
end
end
|
#human_readable_value(input) ⇒ Object
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
|
# File 'app/models/refine/conditions/date_condition.rb', line 153
def human_readable_value(input)
current_clause = get_clause_by_id(input[:clause])
case input[:clause]
when *[CLAUSE_EQUALS, CLAUSE_DOESNT_EQUAL, CLAUSE_LESS_THAN_OR_EQUAL, CLAUSE_GREATER_THAN_OR_EQUAL]
formatted_date1 = I18n.l(input[:date1].to_date, format: :dmy)
"#{formatted_date1}#{timezone_abbr}"
when *[CLAUSE_BETWEEN, CLAUSE_NOT_BETWEEN]
formatted_date1 = I18n.l(input[:date1].to_date, format: :dmy)
formatted_date2 = I18n.l(input[:date2].to_date, format: :dmy)
and_i18n = I18n.t("#{I18N_PREFIX}and")
if formatted_date1 == formatted_date2
"#{formatted_date1}#{timezone_abbr}"
else
"#{formatted_date1} #{and_i18n} #{formatted_date2}#{timezone_abbr}"
end
when *[CLAUSE_GREATER_THAN, CLAUSE_LESS_THAN, CLAUSE_EXACTLY]
days_i18n = I18n.t("#{I18N_PREFIX}and")
ago_i18n = I18n.t("#{I18N_PREFIX}days")
from_now_i18n = I18n.t("#{I18N_PREFIX}ago")
"#{input[:days]} #{days_i18n} #{input[:modifier] == 'ago' ? ago_i18n : from_now_i18n}#{timezone_abbr}"
when *[CLAUSE_SET, CLAUSE_NOT_SET]
""
else
not_supported_i18n = I18n.t("#{I18N_PREFIX}not_supported")
raise "#{input[:clause]} #{not_supported_i18n}"
end
end
|
#is_relative_clause? ⇒ Boolean
268
269
270
|
# File 'app/models/refine/conditions/date_condition.rb', line 268
def is_relative_clause?
relative_clauses.include? clause
end
|
#modify_date_and_clause!(input) ⇒ Object
272
273
274
275
|
# File 'app/models/refine/conditions/date_condition.rb', line 272
def modify_date_and_clause!(input)
@date1 = comparison_date(input)
@clause = standardize_clause(input)
end
|
#relative_clauses ⇒ Object
69
70
71
72
73
|
# File 'app/models/refine/conditions/date_condition.rb', line 69
def set_input_parameters(input)
@date1 = input[:date1]
@date2 = input[:date2]
@days = input[:days]
end
|
#standardize_clause(input) ⇒ Object
#start_of_day(day) ⇒ Object
321
322
323
324
325
326
327
328
329
330
331
332
333
|
# File 'app/models/refine/conditions/date_condition.rb', line 321
def start_of_day(day)
day_in_user_tz = day.in_time_zone(user_timezone).beginning_of_day
database_local = day_in_user_tz.in_time_zone(database_timezone)
offset = database_local.utc_offset
utc_start = database_local.in_time_zone("UTC")
utc_start + offset
end
|
#timezone_abbr ⇒ Object
Returns the string representation of the timezone localized if you don't already have a Time object to work with
NOTE: It is possible for a timezone to not have an acceptable abbreviation. In those cases the Time library outputs unhelpful shortened offsets.
EG: "International Date Line West" outputs "-12"
So parse the string to see if it's one of these shortened forms and if it is, restructure to a fully formed GMT offset EG "GMT-12:00"
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'app/models/refine/conditions/date_condition.rb', line 95
def timezone_abbr
if @show_human_readable_timezone
tz_string = " (#{I18n.l(Time.now.in_time_zone(user_timezone), format: :z)})"
match = tz_string =~ /^ \([-+]?\d+\)$/
if !((tz_string =~ /^ \([-+]?\d+\)$/).nil?)
tz_string = get_standard_tz_offset(tz_string)
end
tz_string
else
""
end
end
|
#timezone_exists(zone) ⇒ Object
82
83
84
85
|
# File 'app/models/refine/conditions/date_condition.rb', line 82
def timezone_exists(zone)
return if ActiveSupport::TimeZone[zone].present?
errors.add(:base, I18n.t("#{I18N_PREFIX}timezone_error", zone: zone))
end
|
#user_timezone ⇒ Object
221
222
223
|
# File 'app/models/refine/conditions/date_condition.rb', line 221
def user_timezone
get_timezone(@user_timezone ||= @@default_user_timezone)
end
|
#with_database_timezone(timezone) ⇒ Object
207
208
209
210
|
# File 'app/models/refine/conditions/date_condition.rb', line 207
def with_database_timezone(timezone)
@database_timezone = timezone
self
end
|
#with_human_readable_timezone(show) ⇒ Object
202
203
204
205
|
# File 'app/models/refine/conditions/date_condition.rb', line 202
def with_human_readable_timezone(show)
@show_human_readable_timezone = show
self
end
|
#with_user_timezone(timezone) ⇒ Object
212
213
214
215
|
# File 'app/models/refine/conditions/date_condition.rb', line 212
def with_user_timezone(timezone)
@user_timezone = timezone
self
end
|