Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/date_parity/core_ext/date.rb

Class Method Summary collapse

Class Method Details

._parse_with_date_parity_format(string, comp = false) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/date_parity/core_ext/date.rb', line 10

def _parse_with_date_parity_format(string, comp=false)
  return _parse_without_date_parity_format(string, comp) if string.blank? or Date.format.blank?
  # Normalize date by first respecting custom date_parity Date.format, 
  # then formatting back to iso/db string so normal ::Date._parse call can succeed.
  _parse_without_date_parity_format(Date.strptime(string, Date.format).to_s(:db), comp)
rescue
  _parse_without_date_parity_format(string, comp)
end

.formatObject



3
4
5
# File 'lib/date_parity/core_ext/date.rb', line 3

def format
  Thread.current[:date_format] || Date::DATE_FORMATS[:db]  || "%Y-%m-%d"
end

.format=(format) ⇒ Object



6
7
8
# File 'lib/date_parity/core_ext/date.rb', line 6

def format=(format)
  Thread.current[:date_format] = format
end

.parse_with_date_parity_format(string, comp = false) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/date_parity/core_ext/date.rb', line 19

def parse_with_date_parity_format(string, comp=false)
  return parse_without_date_parity_format(string, comp) if string.blank? or Date.format.blank?
  # Normalize date by first respecting custom date_parity Date.format, 
  # then formatting back to iso/db string so normal ::Date.parse call can succeed.
  parse_without_date_parity_format(Date.strptime(string, Date.format).to_s(:db), comp)
rescue
  parse_without_date_parity_format(string, comp)
end