Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

date_params

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date_params

  • 2.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

DateParams

Build Status

Dates and times passed in as strings date-pickers or time-pickers need to be converted from their string format to a ruby Date or DateTime to be able to be saved and manipulated. This gem provides two simple controller add-ons to facilitate the conversion.

Installation

Rails 3.x and Ruby 1.9.3 or 2.x required.

Add this line to your application's Gemfile:

gem 'date_params'

And then execute:

$ bundle

Or install it yourself as:

$ gem install date_params

Usage

date_params

Specify the dates to be parsed:

class UsersController < ApplicationController
  # e.g. parameters come in as: { sign_up_on: '01/05/2013' }
  date_params :sign_up_on
  # and now params[:sign_up_on] is a Date object
end

Any options that a before_filter accepts can be passed in:

date_params :sign_up_on, only: [:index]

If date fields are namespaced in a model that can be specified with the namespace option:

# will parse parameters in the format of: { user: { searched_on: '01/04/2013', sign_up_on: '04/03/2013' } }
date_params :searched_on, :sign_up_on, namespace: :user

Date format can be passed as an option (default is %m/%d/%Y):

date_params :search_on, :sign_up_on, date_format: '%d-%m-%Y'

datetime_params

Specify the datetime fields that need to be parsed:

class UsersController < ApplicationController
  # e.g. parameters come in as: { sign_up_at_date: '01/05/2013', sign_up_at_time: '7:30 pm' }
  datetime_params :sign_up_at
  # and now params[:sign_up_at] is a timezone-aware DateTime object
end

In addition to the :namespace and :date_format options, the time format can be specified (default is %I:%M %p):

date_params :sign_up_at, time_format: '%H:%M:%S'

To specify exactly which fields should be parsed:

date_params { date: :sign_up_on, time: :sign_up_time, field: :sign_up_at }, only: :create

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

FAQs

Package last updated on 06 May 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc