Module: TranslationCms::Utils
- Defined in:
- lib/translation_cms/utils.rb
Defined Under Namespace
Classes: RemoteFile
Class Method Summary collapse
- .filter_dates(params = {}, format = '%m/%d/%Y') ⇒ Object
- .friendly_token(limit = 16) ⇒ Object
- .normalize_array(value) ⇒ Object
- .normalize_date(date, hour) ⇒ Object
- .normalize_date2(date) ⇒ Object
Class Method Details
.filter_dates(params = {}, format = '%m/%d/%Y') ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/translation_cms/utils.rb', line 27 def filter_dates(params = {}, format = '%m/%d/%Y') begin start_date = DateTime.strptime(params.fetch(:start_date), format) if params[:start_date].present? end_date = DateTime.strptime(params.fetch(:end_date), format) if params[:end_date].present? if (start_date && start_date.year > 9999) || (end_date && end_date.year > 9999) start_date = end_date = nil end rescue StandardError start_date = end_date = nil end params[:start_date] = start_date ? start_date.strftime(format) : '' params[:end_date] = end_date ? end_date.strftime(format) : '' params end |
.friendly_token(limit = 16) ⇒ Object
23 24 25 |
# File 'lib/translation_cms/utils.rb', line 23 def friendly_token(limit = 16) ::SecureRandom.base64(16).tr('+/=lIO0', 'pqrsxyz').slice(0, limit) end |
.normalize_array(value) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/translation_cms/utils.rb', line 68 def normalize_array(value) case value when Hash then value.values when ActionController::Parameters then value.values else Array.wrap(value) end end |
.normalize_date(date, hour) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/translation_cms/utils.rb', line 42 def normalize_date(date, hour) return nil if date.blank? begin DateTime.strptime("#{date} #{hour}", '%m/%d/%Y %I %p').in_time_zone(Time.zone).utc.iso8601 rescue Exception => e nil end end |
.normalize_date2(date) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/translation_cms/utils.rb', line 52 def normalize_date2(date) return nil if date.blank? date += Time.zone.now.zone.to_s begin DateTime.strptime(date, '%m/%d/%Y %H:%M%z').utc.iso8601 rescue Exception => e begin DateTime.strptime(date).utc.iso8601 # 2013-08-23T00:00:00+00:00 rescue Exception => e nil end end end |