feat: 事件异常按工作日累计已过小时数

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-21 18:14:19 +08:00
co-authored by Cursor
parent 4381966c4e
commit ef0424a28f
2 changed files with 42 additions and 0 deletions
+17
View File
@@ -14,6 +14,7 @@ from agent.policy.deal_followup import (
leader_matches,
next_followup_at,
shift_workdays,
workday_elapsed_hours,
)
@@ -37,6 +38,22 @@ class TestWorkdays(unittest.TestCase):
self.assertEqual(when.tzinfo, SHANGHAI)
self.assertEqual(when.date(), date(2026, 9, 24))
def test_skip_weekend_keep_weekday_night(self) -> None:
start = datetime(2026, 9, 18, 17, 0, tzinfo=SHANGHAI) # 周五
now = datetime(2026, 9, 21, 17, 0, tzinfo=SHANGHAI) # 周一
# 周五 17–24 = 7h,周末不算,周一 0–17 = 17h
self.assertAlmostEqual(workday_elapsed_hours(start, now), 24.0, places=4)
def test_rest_day_start_counts_from_next_workday(self) -> None:
start = datetime(2026, 9, 19, 10, 0, tzinfo=SHANGHAI) # 周六
now = datetime(2026, 9, 21, 10, 0, tzinfo=SHANGHAI) # 周一
self.assertAlmostEqual(workday_elapsed_hours(start, now), 10.0, places=4)
def test_fractional_quarter_hour(self) -> None:
start = datetime(2026, 9, 18, 9, 0, tzinfo=SHANGHAI)
now = datetime(2026, 9, 18, 9, 15, tzinfo=SHANGHAI)
self.assertAlmostEqual(workday_elapsed_hours(start, now), 0.25, places=4)
class TestAirRouteKeys(unittest.TestCase):
def test_pair_and_dest(self) -> None: