Class: Date

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

Constant Summary collapse

FERIADOS =

end

feriados
FERIADOS_METODOS =
metodos

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.valid?(date) ⇒ Boolean

Valida se uma string eh uma data valida

Exemplo:

Date.valid?('01/01/2007') ==> true
Date.valid?('32/01/2007') ==> false

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
# File 'lib/brdata/date_portuguese.rb', line 31

def self.valid?(date)
  begin
    date = date.to_date
    Date.valid_civil?(date.year, date.month, date.day)        
  rescue
    return false
  end
  true
end

Instance Method Details

#corpus_christiObject

Retorna a corpus_christi no ano da data atual

Exemplo:

data = Date.new(2007, 12, 25)
data.corpus_christi ==> "2007-06-07"


84
85
86
# File 'lib/brdata/feriado.rb', line 84

def corpus_christi
  Date.parse((pascoa.to_time + 60.days).to_date.to_s)
end

#feriado?Boolean

Retorna a true se a data for um feriado

Exemplo:

data = Date.new(2007, 12, 25)
data.feriado? ==> true

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# File 'lib/brdata/feriado.rb', line 53

def feriado?
  return true if FERIADOS.include?(Feriado.new("novo_feriado", self.day, self.month))
  FERIADOS_METODOS.each do |metodo|
    return true if self == send(metodo)
  end
  false
end

#pascoaObject

Retorna a pascoa no ano da data atual

Exemplo:

data = Date.new(2007, 12, 25)
data.pascoa ==> "2007-4-8"


66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/brdata/feriado.rb', line 66

def pascoa
  g = self.year % 19
  c = (self.year / 100).floor
  h = (c - ( c / 4 ).floor - ((8 * c) / 25).floor + 19 * g + 15) % 30
  i = h - (h / 28).floor * (1 - (h / 28).floor * (29 / (h + 1)).floor * ((21 - g) / 11).floor)
  j = (self.year + (self.year/ 4).floor + i + 2 - c + (c / 4).floor) % 7
  l = i - j

  month = 3 + ((l + 40) / 44).floor
  day   = l + 28 - (31 * (month / 4 ).floor)
  Date.parse("#{self.year}-#{month}-#{day}")
end

#to_s_brObject

Retorna a data no padrao brasileiro

Exemplo:

data = Date.new(2007, 9, 27)
data.to_s_br ==> "27/09/2007"


22
23
24
# File 'lib/brdata/date_portuguese.rb', line 22

def to_s_br
  strftime("%d/%m/%Y")
end