8000 Add standard format · cedk/python-stdnum@b585182 · GitHub
[go: up one dir, main page]

Skip to content

Commit b585182

Browse files
committed
Add standard format
1 parent ef18b21 commit b585182

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

stdnum/be/nn.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
Traceback (most recent call last):
3434
...
3535
InvalidChecksum: ...
36+
>>> format('85 07 30 033 28')
37+
'85.07.30-033.28'
3638
"""
3739
import datetime as dt
3840

@@ -76,3 +78,11 @@ def is_valid(number):
7678
return bool(validate(number))
7779
except ValidationError:
7880
return False
81+
82+
83+
def format(number):
84+
"""Reformat the number to the standard presentation format."""
85+
number = compact(number)
86+
return (
87+
'.'.join(number[i:i + 2] for i in range(0, 6, 2)) +
88+
'-' + '.'.join([number[6:9], number[9:11]]))

0 commit comments

Comments
 (0)
0