From 3ce3f6369269d442ba40f97f42a5071571b2ca95 Mon Sep 17 00:00:00 2001 From: 732642856 <732642856@qq.com> Date: Thu, 23 Jul 2026 20:35:14 +0800 Subject: [PATCH] sync: add timing freeze and gulika fix --- scripts/gulika.py | 9 ++++++--- tests/test_gulika.py | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/gulika.py b/scripts/gulika.py index 0ca827ea..eb008c33 100644 --- a/scripts/gulika.py +++ b/scripts/gulika.py @@ -60,13 +60,15 @@ def calculate_gulika( end_jd = daynight["sunset_jd_ut"] if is_day else daynight["sunrise_jd_ut"] + 1.0 if end_jd <= start_jd: end_jd += 1.0 + start_year, start_month, start_day, _ = swe.revjul(start_jd + float(tz) / 24.0) + period_weekday = datetime(int(start_year), int(start_month), int(start_day)).weekday() if method == "saturn_part_start": - part_index = SATURN_PART_START[moment.weekday()][period] + part_index = SATURN_PART_START[period_weekday][period] segment_fraction = part_index / 8.0 ghatika_end = None elif method == "legacy_ghatika_end": part_index = None - ghatika_end = GHATIKA_END[moment.weekday()][period] + ghatika_end = GHATIKA_END[period_weekday][period] segment_fraction = ghatika_end / 30.0 else: raise ValueError("method must be saturn_part_start or legacy_ghatika_end") @@ -79,7 +81,8 @@ def calculate_gulika( "sign_idx": int(longitude / 30) % 12, "degree_in_sign": round(longitude % 30, 6), "period": period, - "weekday": moment.weekday(), + "weekday": period_weekday, + "moment_weekday": moment.weekday(), "method": method, "part_index": part_index, "segment_fraction": segment_fraction, diff --git a/tests/test_gulika.py b/tests/test_gulika.py index a03a56d2..1a76ff8d 100644 --- a/tests/test_gulika.py +++ b/tests/test_gulika.py @@ -32,3 +32,10 @@ def test_gulika_matches_public_pyjhora_smoke_oracle() -> None: assert result["method"] == "saturn_part_start" assert result["sign_idx"] == expected["sign_index"] assert abs(result["degree_in_sign"] - expected["degree_in_sign"]) <= 0.5 + + +def test_gulika_night_uses_weekday_of_preceding_sunset() -> None: + result = calculate_gulika(datetime(2023, 1, 27, 2, 30, 15), lat=23.0225, lon=72.5714, tz=5.5) + assert result["period"] == "night" + assert result["weekday"] == 3 + assert result["sign_idx"] == 7