Module: Zena::Use::Dates::ViewMethods

Includes:
Common, FormTags
Defined in:
lib/zena/use/dates.rb

Instance Method Summary collapse

Methods included from FormTags

#date_box

Methods included from Common

#format_date

Instance Method Details

#main_date(tz = visitor.tz) ⇒ Object

default date used to filter events in templates



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/zena/use/dates.rb', line 162

def main_date(tz = visitor.tz)
  @main_dates ||= {}
  @main_dates[tz] ||= begin
    if params[:date]
      if date = params[:date].to_utc(ISO_DATE_FORMAT, tz)
        date
      else
        # FIXME: when date parsing fails: show an error, not a 500...
        Node.logger.warn "Could not parse 'date' parameter: #{params[:date].inspect}."
        # malformed url... 404 ?
        Time.now.utc
      end
    else
      # no 'date' parameter
      Time.now.utc
    end
  end
end

#parse_date(string, format = nil, tz = nil) ⇒ Object



181
182
183
184
185
186
# File 'lib/zena/use/dates.rb', line 181

def parse_date(string, format = nil, tz = nil)
  return nil unless string
  format = _('datetime') if format.blank?
  tz     = visitor.tz if tz.blank?
  string.to_utc(format, visitor.tz)
end