Module: Noventius::Extension::DateQuery::InstanceMethods
- Defined in:
- lib/noventius/extensions/date_query.rb
Constant Summary collapse
- SQL_FUNCTIONS =
{ 'month' => "DATE_TRUNC('month', <%column%>::timestamptz AT TIME ZONE {time_zone})", 'day' => "DATE_TRUNC('day', <%column%>::timestamptz AT TIME ZONE {time_zone})", 'dow' => 'EXTRACT(DOW from <%column%>::timestamptz AT TIME ZONE {time_zone})::integer', 'hour' => 'EXTRACT(HOUR from <%column%>::timestamptz AT TIME ZONE {time_zone})::integer', 'moy' => 'EXTRACT(MONTH from <%column%>::timestamptz AT TIME ZONE {time_zone})::integer' }
Instance Method Summary collapse
-
#date_extract(component:, column:, time_zone: 'America/Montevideo') ⇒ String
SQL function for the extraction of the desired timestamp component.
-
#date_extract_options ⇒ Hash
The different component that can be extracted from a timestamp.
Instance Method Details
#date_extract(component:, column:, time_zone: 'America/Montevideo') ⇒ String
SQL function for the extraction of the desired timestamp component
48 49 50 51 52 53 54 |
# File 'lib/noventius/extensions/date_query.rb', line 48 def date_extract(component:, column:, time_zone: 'America/Montevideo') sql_function = SQL_FUNCTIONS[component].dup Class.new(OpenStruct) { include Noventius::Report::Interpolator }.new(column: column, time_zone: time_zone).interpolate(sql_function) end |
#date_extract_options ⇒ Hash
The different component that can be extracted from a timestamp
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/noventius/extensions/date_query.rb', line 29 def [ { 'Day' => 'day', 'Month' => 'month', 'Day of week' => 'dow', 'Hour of day' => 'hour', 'Month of year' => 'moy' } ] end |