http://www.ruby-doc.org/stdlib/libdoc/date/rdoc/classes/Date.html#M000370
Looking at the Date class there are two constants, a hash DAYS and an
array ABBR_DAYNAMES.
DAYS = { ‘sunday’ => 0, ‘monday’ => 1, ‘tuesday’ => 2, ‘wednesday’=> 3,
‘thursday’ => 4, ‘friday’ => 5, ‘saturday’ => 6 }
ABBR_DAYNAMES = %w(Sun Mon Tue Wed Thu Fri Sat)
I can get the integer for the day ‘number’ (0 to 6) from a date using
the wday method, ie. Date.today.wday
But how do I use the array or hash from Date.rb, it does not appear to
be initialized at the time of use.
Ultimately what I wish to create is a select box (monday-sunday) with
today’s day pre-selected.
I’ve looked for a Rails helper to this but there does not appear to be
one.
Many thanks. AFM.
Kris L. wrote:
http://www.ruby-doc.org/stdlib/libdoc/date/rdoc/classes/Date.html#M000370
Looking at the Date class there are two constants, a hash DAYS and an
array ABBR_DAYNAMES.
DAYS = { ‘sunday’ => 0, ‘monday’ => 1, ‘tuesday’ => 2, ‘wednesday’=> 3,
‘thursday’ => 4, ‘friday’ => 5, ‘saturday’ => 6 }
ABBR_DAYNAMES = %w(Sun Mon Tue Wed Thu Fri Sat)
I can get the integer for the day ‘number’ (0 to 6) from a date using
the wday method, ie. Date.today.wday
But how do I use the array or hash from Date.rb, it does not appear to
be initialized at the time of use.
Ultimately what I wish to create is a select box (monday-sunday) with
today’s day pre-selected.
I’ve looked for a Rails helper to this but there does not appear to be
one.
Many thanks. AFM.
irb(main):003:0> Date::ABBR_DAYNAMES[Date.today.wday]
=> “Tue”
irb(main):004:0> Date::DAYS.index Date.today.wday
=> “tuesday”
HTH
On Jun 20, 2006, at 9:10 AM, Kris L. wrote:
I can get the integer for the day ‘number’ (0 to 6) from a date
Many thanks. AFM.
Hey, I just ran into this yesterday.
require ‘date’
require ‘date/format’
Date.today.strftime("%a") => “Tues”
Although the code in date/format doesn’t look great. It appears to
be a duplicate of Time# functions. There might be a better way.
-Mat