Module: DateAsString
- Defined in:
- lib/date_as_string.rb,
lib/date_as_string/formats.rb,
lib/date_as_string/version.rb
Defined Under Namespace
Modules: ClassMethods, Formats, VERSION
Class Method Summary
collapse
Class Method Details
.guess_century(year, cutoff = 20) ⇒ Object
6
7
8
9
10
|
# File 'lib/date_as_string.rb', line 6
def self.guess_century(year, cutoff=20)
century = get_century_from_year_range(year, cutoff)
century.present? ? century : raise_century_error
end
|
.included(base) ⇒ Object
12
13
14
|
# File 'lib/date_as_string.rb', line 12
def self.included(base)
base.send(:extend, DateAsString::ClassMethods)
end
|
.parse_date(date) ⇒ Object
16
17
18
|
# File 'lib/date_as_string.rb', line 16
def self.parse_date(date)
date.respond_to?(:strftime) ? date.strftime('%m/%d/%Y') : nil
end
|
.parse_string(date_string) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/date_as_string.rb', line 20
def self.parse_string(date_string)
begin
case
when t_regex.match(date_string)
date_for_t_match(date_string)
when mmddyy_regex.match(date_string)
date_for_mmddyy_match(date_string)
when mmddyy_regex(with_slashes: true).match(date_string)
date_for_mmddyy_match(date_string, with_slashes: true)
when mmddyyyy_regex.match(date_string)
date_for_mmddyyyy_match(date_string)
when mmddyyyy_regex(with_slashes: true).match(date_string)
date_for_mmddyyyy_match(date_string, with_slashes: true)
else
nil
end
rescue
nil
end
end
|