Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/brdata/date_portuguese.rb,
lib/brdata/time_portuguese.rb

Instance Method Summary collapse

Instance Method Details

#_original_to_dateObject

Cria a data no padrao brasileiro e permanece aceitando no formato tradicional.

Exemplo: “27/09/2007”.to_date



6
# File 'lib/brdata/date_portuguese.rb', line 6

alias_method :_original_to_date, :to_date

#_original_to_timeObject

Cria a data com horário no padrao brasileiro e permanece aceitando no formato tradicional.

Exemplo: “27/09/2007 01:23”.to_date



6
# File 'lib/brdata/time_portuguese.rb', line 6

alias_method :_original_to_time, :to_time

#to_dateObject



8
9
10
11
12
13
14
# File 'lib/brdata/date_portuguese.rb', line 8

def to_date
  if /^(0[1-9]|[12]\d|3[01])\W(0[1-9]|1[012])\W(\d{4})$/ =~ self
    ::Date.new($3.to_i, $2.to_i, $1.to_i)
  else
    _original_to_date
  end
end

#to_timeObject



8
9
10
11
12
13
14
# File 'lib/brdata/time_portuguese.rb', line 8

def to_time
  if /^(0?[1-9]|[12]\d|3[01])\W(0?[1-9]|1[012])\W(\d{4})(\W([01]?\d|2[0123])\W([0-5]?\d)\W?([0-5]\d)?)?$/ =~ self
    ::Time.mktime($3.to_i, $2.to_i, $1.to_i, $5.to_i, $6.to_i, $7.to_i)
  else
    _original_to_time
  end
end