Changeset 1264

Show
Ignore:
Timestamp:
07/27/08 18:01:23 (5 months ago)
Author:
alban
Message:

Fixe l'affichage des dates de prettydate

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/config/initializers/date_in_french.rb

    r1246 r1264  
    33 
    44silence_warnings do 
     5  Date.const_set "MONTHNAMES_EN", Date::MONTHNAMES 
    56  Date.const_set "MONTHNAMES", [nil] + %w(Janvier Février Mars Avril Mai Juin Juillet Août Septembre Octobre Novembre Décembre) 
    67  Date.const_set "DAYNAMES", %w(Dimanche Lundi Mardi Mercredi Jeudi Vendredi Samedi) 
     
    1415  :time => '%Hh%M' # 18h11 
    1516) 
     17 
     18class Time 
     19 
     20  def strftime_local(format) 
     21    formatted = strftime(format) 
     22 
     23    if format.include? '%B' 
     24      Date::MONTHNAMES_EN.each_with_index do |month_en, index| 
     25        formatted = formatted.gsub(month_en, Date::MONTHNAMES[index]) unless month_en.nil? 
     26      end 
     27    end 
     28 
     29    formatted 
     30  end 
     31 
     32end 
  • trunk/config/initializers/liquid_filters.rb

    r1247 r1264  
    1010 
    1111  def prettydate(input, format = nil) 
    12       date = case input 
     12    date = case input 
    1313      when String 
    1414        Time.parse(input) 
     
    1717      else 
    1818        return input 
     19    end 
     20 
     21    if format.blank? 
     22      if date.today? 
     23        format = 'aujourd\'hui à %Hh%M' 
     24      elsif date.yesterday? 
     25        format = 'hier à %Hh%M' 
     26      else 
     27        format = 'le %d %B %Y à %Hh%M' 
    1928      end 
     29    end 
    2030 
    21       if format.blank? 
    22         if date.today? 
    23           format = "aujourd'hui à %Hh%M" 
    24         end 
    25         if date.yesterday? 
    26           format = 'hier à %Hh%M' 
    27         end 
    28       end 
    29  
    30       date.strftime(format.to_s) 
    31     rescue => e 
    32       input 
    33     end 
     31    # use a fixed strftime (with french month) 
     32    date.strftime_local(format.to_s) 
     33  rescue => e 
     34    input 
     35  end 
    3436 
    3537