Date Format Ruby Gem

Design for the Ruby On Rails (RoR) to access formatted datetime.


Project maintained by Rahul Patil This project is released under the terms of the MIT license.

Welcome

Date Format is the gem used to access formatted datetime. The library take raw date as input and adds a method to give formatted date. By using same gem, user can find the date difference from start date to end date in different format like seconds, minutes, hours, days, months and years.

Installation

Add this line to your application's Gemfile:

$ gem 'date_format'

And then execute:

$ bundle

Or install it yourself as:

$ gem install date_format

Usage

Try this snippet of code on ruby irb

require 'date_format'
today_time = Time.now
puts DateFormat.change_to(today_time, "GENERAL_DATE")                       # => 10/11/14 05:12:26 PM
puts DateFormat.change_to(today_time, "LONG_DATE")                          # => Saturday, October 11, 2014
puts DateFormat.change_to(today_time, "ISO_8601_FORMAT")                    # => 2014-10-11
puts DateFormat.change_to(today_time, "MEDIUM_DATE")                        # => 11-Oct-2014
puts DateFormat.change_to(today_time, "SHORT_DATE")                         # => 10/11/14 (mm/dd/yy)
puts DateFormat.change_to(today_time, "LONG_TIME")                          # => 05:12:26 PM
puts DateFormat.change_to(today_time, "MEDIUM_TIME")                        # => 17:12 PM
puts DateFormat.change_to(today_time, "SHORT_TIME")                         # => 17:12
puts DateFormat.change_to(today_time, "WEEK_OF_YEAR")                       # => 40
puts DateFormat.change_to(today_time, "DAY_IN_MONTH")                       # => 11
puts DateFormat.change_to(today_time, "JULIAN_DAY")                         # => 2014
puts DateFormat.change_to(today_time, "ONLY_HOUR_IN_24HOUR_FORMAT")         # => 17
puts DateFormat.change_to(today_time, "HOURS_IN_24HOUR_FORMAT")             # => 17:12
puts DateFormat.change_to(today_time, "MINUTE_IN_HOUR")                     # => 12
puts DateFormat.change_to(today_time, "ONLY_DATE")                          # => October 11, 2014
puts DateFormat.change_to(today_time, "LONG_DATE_SHORT")                    # => Sat, October 11, 2014
puts DateFormat.change_to(today_time, "ONLY_DATE_DEFAULT")                  # => 11/10/2014 (dd/mm/yy)
puts DateFormat.change_to(today_time, "ONLY_DATE_SHORT")                    # => Oct 11, 2014
puts DateFormat.change_to(today_time, "ONLY_DATE_SHORTEST")                 # => Sat, Oct 11, 2014
puts DateFormat.change_to(today_time, "")                                   # => 11.10.14
puts DateFormat.change_to(today_time, "ONLY_CURRENT_DATE_NUMBER")           # => 11
puts DateFormat.change_to(today_time, "ONLY_CURRENT_DATE_ALPHABET")         # => Sat
puts DateFormat.change_to(today_time, "ONLY_CURRENT_MONTH_NUMBER")          # => 10
puts DateFormat.change_to(today_time, "ONLY_CURRENT_MONTH_ALPHABET")        # => Oct
puts DateFormat.change_to(today_time, "ONLY_CURRENT_YEAR_MONTH")            # => 201410
puts DateFormat.change_to("", "")                                           # => NA

# For Time Difference
start_date = Time.parse('2014-05-25 18:37:11')
DateFormat.time_difference(start_date, "PRESENT_DAY", "DAY_ONLY")
DateFormat.time_difference(start_date, "PRESENT_DAY", "HOUR_ONLY")
DateFormat.time_difference(start_date, "PRESENT_DAY", "MINUTE_ONLY")
DateFormat.time_difference(start_date, "PRESENT_DAY", "SECOND_ONLY")
DateFormat.time_difference(start_date, "", "DAY_ONLY")
DateFormat.time_difference(start_date, "", "HOUR_ONLY")
DateFormat.time_difference(start_date, "", "MINUTE_ONLY")
DateFormat.time_difference(start_date, "", "SECOND_ONLY")
DateFormat.time_difference(start_date, "AA", "HOUR_ONLY")
DateFormat.time_difference(start_date, "XX", "MINUTE_ONLY")
DateFormat.time_difference(start_date, "DD", "SECOND_ONLY")

For more info on GitHub Pages, check out pages.github.com. For help, check the GitHub Pages documentation.

Versions

Contributing


Who's this Rahul Patil?

He's a RubyOnRails / frontend dev, who would like to think his code is worked through and thought through well. He can be found on Facebook, and GitHub

profile for Rubyist on Stack Exchange, a network of free, community-driven Q&A sites