CalendarDateSelect is semi-light-weight (about ~20k of javascript/css) and easy to use (but gets even lighter with bundle-fu)! It takes full advantage of the prototype.js library, resulting in less code, but maintaining a great deal of functionality.
Some of it's capabilities:
can pick a date, or a date-time, or a date with an optional time, as a popup selector or an embedded calendar!
speaks several different formats
is easy to localize
is extensible. Calendar Date Select doesn't do everything under the sun (which is a good thing), but you can build on top of it.
Installation / Usage
Install the calendar_date_select gem
sudo gem install calendar_date_select
Add a gem dependency to your rails project (in environment.rb)
config.gem "calendar_date_select"
Then, restart/start your rails project. All necessary files will be copied to your public folder.
Now include this at the top of your layout: (you'll also need to include prototype, if you haven't already!)
<%= calendar_date_select_includes "red" # or "blue", or "silver", or nil for the default! %>
# (if you want more control, you can get a list of stylesheets / javascripts via calendar_date_select_javascripts and calendar_date_select_stylesheets)
See the Demo for various uses of CalendarDateSelect.
About ruby on rails, hackintosh, iphone3g and etc.
Thursday, April 30, 2009
Wednesday, April 29, 2009
Date Calculation in Rails
>> Date.new( 2008, 1, 1 ).to_time.advance( :months => 1 )
=> Fri Feb 01 00:00:00 +0000 2008
>> Date.new( 2008, 2, 1 ).to_time.advance( :months => 1 )
=> Sat Mar 01 00:00:00 +0000 2008
=> Fri Feb 01 00:00:00 +0000 2008
>> Date.new( 2008, 2, 1 ).to_time.advance( :months => 1 )
=> Sat Mar 01 00:00:00 +0000 2008
>> Date.new( 2008, 1, 1 ).to_time + 1.month
=> Thu Jan 31 00:00:00 +0000 2008
=> Thu Jan 31 00:00:00 +0000 2008
Extracted from here:
http://roninonrails.blogspot.com/2008/01/beware-of-rails-date-arithmetic.html
Tuesday, April 28, 2009
Get Month Name in Rails
To get month name as constants, do the following
require 'date'
for i in (1..12)
@month = Date::MONTHNAMES[i]
end
Date Format in strftime
Format | Meaning |
---|---|
%a | The abbreviated weekday name (“Sun'’) |
%A | The full weekday name (“Sunday'’) |
%b | The abbreviated month name (“Jan'’) |
%B | The full month name (“January'’) |
%c | The preferred local date and time representation |
%d | Day of the month (01..31) |
%H | Hour of the day, 24-hour clock (00..23) |
%I | Hour of the day, 12-hour clock (01..12) |
%j | Day of the year (001..366) |
%m | Month of the year (01..12) |
%M | Minute of the hour (00..59) |
%p | Meridian indicator (“AM'’ or “PM'’) |
%S | Second of the minute (00..60) |
%U | Week number of the current year, starting with the first Sunday as the first day of the first week (00..53) |
%W | Week number of the current year, starting with the first Monday as the first day of the first week (00..53) |
%w | Day of the week (Sunday is 0, 0..6) |
%x | Preferred representation for the date alone, no time |
%X | Preferred representation for the time alone, no date |
%y | Year without a century (00..99) |
%Y | Year with century |
%Z | Time zone name |
%% | Literal “%'’ character |
Subscribe to:
Posts (Atom)