-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
32 lines (25 loc) · 800 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from datetime import datetime
def formatar_data(data, padrao='%d/%m'):
return datetime.strptime(data, '%d/%m/%Y %H:%M').strftime(padrao)
def validar_data(data):
try:
return datetime.strptime(data, '%Y%m%d')
except ValueError:
raise ValueError('Formato da data incorreto, deve ser YYYYMMDD.')
def formatar_numeral(numero, separador='.'):
def reverse(string):
string = "".join(reversed(string))
return string
s = reverse(str(numero))
count = 0
result = ''
for char in s:
count = count + 1
if count % 3 == 0:
if len(s) == count:
result = char + result
else:
result = separador + char + result
else:
result = char + result
return result