🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

multiparameter_date_time

Package Overview
Dependencies
Maintainers
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiparameter_date_time

bundlerRubyGems.org
Version
0.5.0
Version published
Maintainers
5
Created
Source

MultiparameterDateTime

Set a DateTime via two accessors, one for the date, one for the time

Build Status Code Climate Gem Version Dependency Status

Installation

Add this line to your application's Gemfile:

gem 'multiparameter_date_time'

And then execute:

$ bundle

Or install it yourself as:

$ gem install multiparameter_date_time

Note that Ruby 2.x is required.

Usage

class Article < ActiveRecord::Base
  include MultiparameterDateTime

  multiparameter_date_time :publish_at
end

record = Article.new(
  :publish_at_date_part => '01/01/2001',
  :publish_at_time_part => '4:30 pm'
)

record.publish_at #=> Mon, 01 Jan 2001 16:30:00 +0000

record.publish_at_date_part = '2/3/2004'
record.publish_at #=> Tue, 03 Feb 2004 16:30:00 +0000

record = Article.new(
  :publish_at_date_part => '01/01/2001',
)

record.publish_at #=> :incomplete
record.publish_at_date_part #=> '01/01/2001'
record.publish_at_time_part #=> nil

record = Article.new(
  :publish_at_time_part => '09:30 am',
)

record.publish_at #=> :incomplete
record.publish_at_date_part #=> nil
record.publish_at_time_part #=> '09:30 am'

Configuring the date and time formats

In config/initializers/multiparameter_date_time.rb:

MultiparameterDateTime.date_format = '%-m/%-d/%0Y'
MultiparameterDateTime.time_format = '%-I:%0M %P'

Validating the multipart date time data

validates :published_at, presence: true, is_valid_multiparameter_date_time: true

Accessing the datetime error message used

IsValidMultiparameterDateTimeValidator.invalid_format_error_message

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Added some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Customizing the error message via I18n

This gem supports custom error messages using the I18n gem. There is one message key for a missing date part and another for a missing time part. Default messages are provided if you choose not to supply your own.

en:
  activerecord:
    errors:
      models:
        <your_model>:
          attributes:
            ended_at_time_part:
              blank: '<your message>'
            ended_at_date_part:
              blank: '<your message>'

License

Copyright © 2012–2016 Case Commons, LLC. License is available in the LICENSE file.

FAQs

Package last updated on 15 Aug 2017

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