This commit is contained in:
20
backend/core/utils.py
Normal file
20
backend/core/utils.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# backend/core/utils.py
|
||||
|
||||
from datetime import datetime
|
||||
from decimal import Decimal, InvalidOperation
|
||||
|
||||
def format_currency(value: str) -> Decimal:
|
||||
"""Standardizirano pretvaranje valuta iz stringa u Decimal."""
|
||||
try:
|
||||
# Čišćenje stringa (npr. uklanjanje 'kn' ili '.' separatora)
|
||||
clean_value = value.replace(',', '.').replace(' ', '')
|
||||
return Decimal(clean_value)
|
||||
except (InvalidOperation, ValueError):
|
||||
return Decimal('0.00')
|
||||
|
||||
def parse_iso_date(date_str: str):
|
||||
"""Standardizirano parsiranje datuma za cijeli sustav."""
|
||||
try:
|
||||
return datetime.fromisoformat(date_str.replace('Z', '+00:00'))
|
||||
except (ValueError, TypeError):
|
||||
return None
|
||||
Reference in New Issue
Block a user