Hi Adam,

Ich hab mal versucht ein eigenes Format für das Plugin zu schreiben. Dabei bin ich nach der Anleitung aus der Doku (http://code.google.com/p/calendardateselect/wiki/ChangingDateFormatCustom ) vorgegangen. Da ich derzeit leider kein Projekt zur Hand habe mit dem ich das testen kann, kann ich dir auch nicht sagen, ob sich nicht doch ein Fehler eingeschlichen hat. Probiers mal aus und sag bitte Bescheid, wenn's klappt oder auch nicht klappt ;-)


# Schritt 1: Das hier in die environment.rb
CalendarDateSelect::FORMATS[:german_custom] = {
# Here's the code to pass to Date#strftime
  :date => "%d.%m.%Y",
:time => " %H:%M", # notice the space before time. If you want date and time to be seperated with a space, put the leading space here.

  :javascript_include => "german_custom"
}



# Schritt 2: das hier in eine neue js-datei: /public/javascripts/ calendar_date_select/german_custom.js
Date.prototype.toFormattedString = function(include_time)
{
str = Date.padded2(this.getDate()) + "." + Date.padded2(this.getMonth() + 1) + "." + this.getFullYear();

if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes() }
  return str;
}

Date.parseFormattedString = function(string)
{
var regexp = '([0-9]{1,2}).(([0-9]{1,2}).(([0-9]{4})( ([0-9] {1,2}):([0-9]{2})? *)?)?)?';
    var d = string.match(new RegExp(regexp, "i"));
if (d==null) return Date.parse(string); // at least give javascript a crack at it.
    var offset = 0;
    var date = new Date(d[5], 0, 1);
    if (d[3]) { date.setMonth(d[3] - 1); }
    if (d[5]) { date.setDate(d[1]); }
    if (d[7]) {
      date.setHours(parseInt(d[7], 10));
    }
    if (d[8]) { date.setMinutes(d[8]); }
    if (d[10]) { date.setSeconds(d[10]); }
    return date;
}


# Schritt 3: dann das plugin in der environment.rb so konfigurieren (muss unterhalb des Codes von Schritt eins stehen)
CalendarDateSelect.format = :german_custom

# WICHTIG: <%= calendar_date_select_includes %> muss in deinem layout- template im header auftauchen! Sonst funzt der Spaß nicht.

Schöne Grüße,
Benjamin

Am 16.02.2009 um 23:01 schrieb Adam Meyer:

Hi Benjamin,

also ich bin mit Rails 2.2.2 unterwegs, und habe mir die aktuellste
Version des Plugins von code.google runtergeladen.

Habe es jetzt in einer momentan so gelöst, dass es im Format

2009-02-16

läuft. Ist zwar nicht ganz das was ich wollte, aber am ehesten dem
europäischem Format.


Benjamin Behr | mindmatters wrote:
Hallo Adam,

welche Version des Plugins nutzt du denn? Und mit welcher Rails-
Version m�chtest du es einsetzen?

Sch�ne Gr��e,Benjamin

Am 16.02.2009 um 19:35 schrieb Adam Meyer:

--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/listinfo/rubyonrails-ug

_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/listinfo/rubyonrails-ug

Antwort per Email an