Module: OpencBot::Helpers::Dates
Constant Summary collapse
- AMERICAN_DATE_RE =
%r_\A\s*(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})_.freeze
Instance Method Summary collapse
Instance Method Details
#normalise_uk_date(raw_date) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/openc_bot/helpers/dates.rb', line 9 def normalise_uk_date(raw_date) return if raw_date.nil? or raw_date.to_s.strip.empty? if raw_date.is_a?(String) cleaned_up_date = raw_date.gsub(/\s+/,'').match(/^\d+\/[\d\w]+\/\d+$/) ? raw_date.gsub('/','-') : raw_date raw_date = to_date(cleaned_up_date.sub(/^(\d{1,2}-)([\w\d]+-)([01]\d)$/,'\1\220\3').sub(/^(\d{1,2}-)([\w\d]+-)([9]\d)$/,'\1\219\3')) end raw_date.to_s end |
#normalise_us_date(raw_date) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/openc_bot/helpers/dates.rb', line 18 def normalise_us_date(raw_date) return if raw_date.nil? or raw_date.to_s.strip.empty? # we want to set century to 19 if there's none set and the years are in the 20s or later raw_date = raw_date.to_s.sub(/^(\s*\d{1,2}[\/-]\d{1,2}[\/-])([2-9]\d)$/,'\119\2') iso_date = raw_date.to_s.sub(AMERICAN_DATE_RE) { |m| "#$3-#$1-#$2" } to_date(iso_date, true).to_s end |