lib/br_danfe/helper.rb in br_danfe-0.15.1 vs lib/br_danfe/helper.rb in br_danfe-0.16.0
- old
+ new
@@ -21,23 +21,21 @@
decimal_part += '0' if decimal_part.size < 2
integer_part + ',' + decimal_part
end
- def self.format_datetime(xml_datetime)
- formated = ''
-
- unless xml_datetime.empty?
- date = DateTime.strptime(xml_datetime, '%Y-%m-%dT%H:%M:%S')
- formated = date.strftime('%d/%m/%Y %H:%M:%S')
- end
-
- formated
+ def self.format_datetime(xml_datetime, with_time_zone: false)
+ formated = with_time_zone ? '%d/%m/%Y %H:%M:%S%:z' : '%d/%m/%Y %H:%M:%S'
+ xml_datetime.present? ? Time.parse(xml_datetime).strftime(formated) : ''
end
def self.nfe?(xml)
nfe_code = '55'
xml['ide > mod'] == nfe_code
+ end
+
+ def self.format_cep(cep)
+ cep.sub(/(\d{2})(\d{3})(\d{3})/, '\\1.\\2-\\3')
end
end
end