Keep source, config, and deploy files. Leave runtime data, uploads, and logs out of git. Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
import re
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
from kamidso.assistant.system_clock import format_system_clock_line, gregorian_to_jalali
|
|
|
|
|
|
def test_gregorian_to_jalali_known_dates():
|
|
assert gregorian_to_jalali(2024, 3, 20) == (1403, 1, 1)
|
|
assert gregorian_to_jalali(2025, 3, 21) == (1404, 1, 1)
|
|
assert gregorian_to_jalali(2026, 3, 21) == (1405, 1, 1)
|
|
assert gregorian_to_jalali(2026, 10, 4) == (1405, 7, 12)
|
|
|
|
|
|
def test_system_clock_line_includes_gregorian_and_jalali():
|
|
now = datetime(2026, 10, 4, 17, 43, 11, tzinfo=timezone(timedelta(hours=3, minutes=30)))
|
|
line = format_system_clock_line(now)
|
|
assert "Current system time: 2026-10-04 17:43:11 +03:30 (IRST)." in line or (
|
|
"Current system time: 2026-10-04 17:43:11 +03:30" in line
|
|
)
|
|
assert "Gregorian weekday: Sunday" in line
|
|
assert "Jalali (Solar Hijri): 1405/07/12" in line
|
|
assert "یکشنبه" in line
|
|
assert "مهر" in line
|
|
assert "۱۴۰۵" in line
|
|
assert "Do not convert calendars yourself" in line
|
|
|
|
|
|
def test_system_clock_line_matches_local_clock():
|
|
before = datetime.now().astimezone()
|
|
line = format_system_clock_line()
|
|
after = datetime.now().astimezone()
|
|
|
|
match = re.search(
|
|
r"Current system time: (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) "
|
|
r"([+-]\d{2}:\d{2}) \((.+)\)\.",
|
|
line,
|
|
)
|
|
assert match, line
|
|
stamp = datetime.strptime(match.group(1), "%Y-%m-%d %H:%M:%S")
|
|
offset = match.group(2)
|
|
sign = 1 if offset[0] == "+" else -1
|
|
hours, minutes = int(offset[1:3]), int(offset[4:6])
|
|
parsed = stamp.replace(tzinfo=timezone(sign * timedelta(hours=hours, minutes=minutes)))
|
|
assert before - timedelta(seconds=2) <= parsed <= after + timedelta(seconds=2)
|
|
jy, jm, jd = gregorian_to_jalali(parsed.year, parsed.month, parsed.day)
|
|
assert f"{jy:04d}/{jm:02d}/{jd:02d}" in line
|
|
assert "relative dates" in line
|