Some of the available date formats
| Name | Format |
| :natural | January 2, 2007 5:30 pm |
| :hyphen_ampm | 2007-01-31 5:30 pm |
| :iso_date | 2008-31-01 17:30 |
| :finnish | 31.1.2008 17:30 |
| :american | 1/31/2008 5:30 pm |
... for more formats, look at the top of lib/calendar_date_select.rb
( note - this only works when you are using using <%= calendar_date_select_includes %> in your layout )
Implementing your own date formats
ChangingDateFormatCustom
Does it works in 24 hour ssytem?
You can create your own format to do so. If you feel nice, feel free to submit it for inclusion in the calendar_date_select code base!
Can anyone tell me what I am doing wrong when trying to do the above changes to the bottom of environment.rb and getting:
dependencies.rb:266:in `load_missing_constant': uninitialized constant CalendarDateSelect (NameError?)
/ iso format for CalendarDateSelect / Date.prototype.toFormattedString = function(include_time) {
if (include_time) { hour=this.getHours(); str += " " + this.getHours() + ":" + this.getPaddedMinutes() } return str; }
Date.parseFormattedString = function (string) {
}}
fuck!
FYI, if you're geting the error rolf.guescini points out:
load_missing_constant': uninitialized constant CalendarDateSelect (NameError?)
Make sure you add the CalendarDateSelect.format line at the very end of your environments.rb and not inside the Rails::Initializer.run method
There are more current formats like:
CalendarDateSelect.format = :finnish
Hi there,
i got problems with saving values in the database as datetime. Every time i load the calendar with a standard value and save it without any changes it will be broke. The Datetime in the database will be return to zero.
So i start search an found sth. in the calendar_date_select.rb. If i change the function date_format_string to: def date_format_string(time=false)
endIt will works fine. As u can see i just enter a space between the date and the time.
Is there any reason why there isn't any space?
Realy good calendar, realy good work
Hey guys, I'm using the plugin, it works great on dates in the default 10 years range, but when I try and save a date in 1960 (year_range => 50) the date is passed back ok, but gets set to NULL on the DB insert. I'm sure I'm missing something simple but I've no idea what.
Sometimes there is an issue with old dates < 1970. I suggest using DateTime? to parse the value before you run the insert.
Hi All,
Please use the mailing list for questions like this
How would I get the difference in days between two dates? Could you please point me to an example of how this is done?
Thanks!
Nevermind, I figured it out. I just put the calendar_select format into the hyphen_ampm format and subtracted the two dates.
Thanks for the cool plugin!
Cheri
Great plugin, but the documentation is poor. I have to read all the comments to just change the format... Thanks to all!
How does one change the date format? :format => :iso_date? :date_format => :iso_date? :iso_date => true?
The text above does not seem to answer the question.
Thanks
found the answer in the comments:
CalendarDateSelect.format = :iso_date
Thanks for the plugin!
This should be in the documentation, you can do it in the layout - when you include the calendar. <%= calendar_date_select_includes :style=>"default", :format =>"iso_date", :locale=>"fi" %>
sowwy, only works for locale and style -
needs to go in environment.rbStill doesn't work. Can someone just lay it out like I'm a 5 year old?
In the calendar_date_select.rb scroll down to the @@format and change it from :natural to your desired format.
The problem here is that if you set
CalendarDateSelect.format = :euro_24hr
it works for the popup-result/the result string, but not inside the actual pop. Inside the popup, it still shows AM/PM.. Why is this.
So I to am a 5 year old. How do I set this up to have a dynamic date format?
I am apparently a little older, maybe 6, but I finally it working. This is what works: <% CalendarDateSelect.format=(:hyphen_ampm )%> <%= calendar_date_select_includes %> <%= calendar_date_select_tag opts[:field], '' ,:popup => 'force' %>
Is it possible to change the format at runtime?
I tried with
<% if current_language.downcase == "de" %> <% CalendarDateSelect.format=(:finnish )%> <%= calendar_date_select_includes %> <% else %> <% CalendarDateSelect.format=(:natural )%> <%= calendar_date_select_includes %> <% end %>Yes, it would be. You would have to execute that before you include the calendar_date_select javascript includes, however.
where do I put the format code ? "CalendarDateSelect.format = :finnish "
i have been trying to use my Prototype knowledge to enforce changing the date format but with no success. is it possible to change the format using javascript call?
i am not using RoR and need to change the format please.
trying.. new CalendarDateSelect( $('Birthdate'), {year_range:40, format:'iso_date'} );
no clue what do to next other than changing the toFormattedString() function..
any help will really be appreciated.
That's exactly what you need to do: change the toFormattedString() function. Each date format implementation takes code.
The date format is set depending on which date format you include, it's as simple as that.
I have a ugly solution but it works
var CustomCalendarDateSelect = Class.create(CalendarDateSelect, { updateValue: function($super) { $super(); var d = this.selected_date; var day = d.getDate() < 10 ? ("0" + d.getDate()) : d.getDate(); var month = d.getMonth() < 10 ? ("0" + parseInt(d.getMonth() + 1)) : parseInt(d.getMonth() + 1); var str = day + "/" + month + "/" + d.getFullYear(); this.target_element.value = str; }, parseDate: function($super) { var value = $F(this.target_element).strip(); $super(); if (this.selection_made) { this.selected_date.setFullYear(value.split('/')[2],parseInt(value.split('/')[1]) - 1,parseInt(value.split('/')[0])); this.date = this.selected_date; } } });what the hell...!!! Document is baaaaaaaaaaaaaaad.
KEY WORD you can edit calendar_date_select.rb and set @@format=:iso_date