File size: 1,111 Bytes
e656014
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
from datetime import datetime


def format_pkr(amount: int) -> str:
    """Format an integer amount as Pakistani Rupees."""
    return f"Rs. {amount:,}"


def format_usd(amount: float) -> str:
    """Format a float amount as US Dollars."""
    return f"${amount:,.2f}"


def format_price_display(amount: float, currency: str = "USD") -> str:
    """Format price for display with the given currency code."""
    if currency == "PKR":
        return format_pkr(int(amount))
    if currency == "USD":
        return format_usd(amount)
    return f"{currency} {amount:,.2f}"


def format_date(dt: datetime) -> str:
    """Format a datetime to a human-readable string."""
    return dt.strftime("%B %d, %Y at %I:%M %p")


def format_date_short(dt: datetime) -> str:
    """Format a datetime to a short date string."""
    return dt.strftime("%b %d, %Y")


def truncate_text(text: str, max_length: int = 100) -> str:
    """Truncate text to max_length and append ellipsis if needed."""
    if len(text) <= max_length:
        return text
    return text[: max_length - 3] + "..."