Sha256: 19260baea50ef94185ff3eedf2894c7d9349863c323881c93d2a9a10e829192e

Contents?: true

Size: 700 Bytes

Versions: 1

Compression:

Stored size: 700 Bytes

Contents

module DOF
  module DateFormatter
    DATE_FORMAT = '^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$'
    
    def self.format(date)
      formatted_date = ''

      if ((date.is_a? String) && date.match(DATE_FORMAT)) || (date.is_a? Date)
        formatted_date = Date.parse(date.to_s).strftime("%d-%m-%Y")
      else
        raise Errors::PreconditionFailed.new("The date has incorrect format")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dof-1.0.0 lib/DOF/date_formatter.rb