File size: 2,344 Bytes
a43aaf6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""Formatting utilities for the frontend."""

from datetime import datetime, timedelta


def format_relative_timestamp(iso_timestamp: str) -> str:
    """
    Format an ISO timestamp into a human-readable relative string.

    Args:
        iso_timestamp: ISO format timestamp string from Supabase

    Returns:
        Formatted string like:
        - "Today, 9:00 AM"
        - "Yesterday, 10:00 PM"
        - "Nov. 12, 2:50 PM"
    """
    try:
        # Parse ISO timestamp
        if iso_timestamp.endswith('Z'):
            dt = datetime.fromisoformat(iso_timestamp.replace('Z', '+00:00'))
        else:
            dt = datetime.fromisoformat(iso_timestamp)

        # Convert to local time if timezone-aware
        if dt.tzinfo is not None:
            dt = dt.astimezone()
            dt = dt.replace(tzinfo=None)

        now = datetime.now()
        today = now.date()
        yesterday = today - timedelta(days=1)

        # Format time portion (cross-platform: use %I and strip leading zero)
        time_str = dt.strftime("%I:%M %p").lstrip('0')

        # Determine date portion
        if dt.date() == today:
            return f"Today, {time_str}"
        elif dt.date() == yesterday:
            return f"Yesterday, {time_str}"
        else:
            # Format as "Nov. 12, 2:50 PM"
            month_abbr = dt.strftime("%b")
            day = dt.day
            return f"{month_abbr}. {day}, {time_str}"

    except Exception as e:
        print(f"Error formatting timestamp: {e}")
        return iso_timestamp[:16] if len(iso_timestamp) > 16 else iso_timestamp


def format_standards_for_llm(standards: list) -> str:
    """
    Format standards array for LLM consumption.

    Args:
        standards: List of dicts with 'code' and 'text' keys

    Returns:
        Formatted string: "code: text\ncode: text"
    """
    if not standards:
        return ""

    lines = []
    for standard in standards:
        code = standard.get('code', '')
        text = standard.get('text', '')
        lines.append(f"{code}: {text}")

    return "\n".join(lines)


def format_standards_list(standards: list) -> list:
    """
    Validate and return standards list.

    Args:
        standards: List of dicts with 'code' and 'text' keys

    Returns:
        The standards list (pass-through for now)
    """
    return standards