Module: FormatTime
- Included in:
- ActiveSupport::TimeWithZone, DateTimeExt
- Defined in:
- lib/formatted_times/format_time.rb
Constant Summary collapse
- FORMATTING_OPTIONS =
{ # Date related options 'YY' => '%Y', 'CC' => '%C', 'yy' => '%y', 'mm' => '%m', 'BB' => '%B', 'bb' => '%b', 'hh' => '%h', 'dd' => '%d', 'ee' => '%e', 'jj' => '%j', # Time related options 'HH' => '%H', 'kk' => '%k', 'II' => '%I', 'll' => '%l', 'PP' => '%P', 'pp' => '%p', 'MM' => '%M', 'SS' => '%S', 'LL' => '%L', 'NN' => '%N', '3N' => '%3N', '6N' => '%6N', '9N' => '%9N', '12N' => '%12N', # Time zone related Options 'zz' => '%z', '1z' => '%:z', '2z' => '%::z', '3z' => '%:::z', 'ZZ' => '%Z', # Weekday related options 'AA' => '%A', 'aa' => '%a', 'uu' => '%u', 'ww' => '%w', 'GG' => '%G', 'gg' => '%g', 'VV' => '%V', 'UU' => '%U', 'WW' => '%W', # Seconds related opions 'ss' => '%s', 'QQ' => '%Q', # Literal string related options 'nn' => '%n', 'tt' => '%t', # Combination Options 'cc' => '%c', 'DD' => '%D', 'FF' => '%F', 'vv' => '%v', 'xx' => '%x', 'XX' => '%X', 'rr' => '%r', 'RR' => '%R', 'TT' => '%T' }
Instance Method Summary collapse
Instance Method Details
#get_strftime_string(name, *args) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/formatted_times/format_time.rb', line 78 def get_strftime_string(name, *args) separator = args[0] || '/' multiple_separator= args[1] || false = name.split('_') .shift = - FORMATTING_OPTIONS.keys raise ::ArgumentError, "Options #{.join(', ')} are invalid." unless .empty? = .collect{ |option| FORMATTING_OPTIONS[option] } multiple_separator ? .zip(separator.chars).flatten.compact.join : .join(separator) end |