Fix #15: Unify duplicate time functions into _get_time_data() #21
Reference in New Issue
Block a user
Delete Branch "fix/issue-15-unify-time-functions"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Replace three duplicated time parsing functions with a single
_get_time_data(e, tz=None)helper.Deleted Functions
get_match_time_status(e)— returned(status_str, urgency)get_match_time_str(e)— returned just the status stringget_start_time_wib(e)— returned(abs_wib_str, rel_str)New Unified Helper
All call sites updated:
format_event()— usestime_status+time_urgencyformat_detail_event()— usestime_status+abs_timeprint_browse()— usesabs_time+time_statussend_to_telegram()— usesabs_time+time_statusprint_detail()— usestime_statusAlso removed dead code in
print_detail()that calledget_match_time_str()but never used the result.Key Changes
get_match_time_strformat is the canonical one (e.g."LIVE","In 6h","12h ago")time_urgency(0-3) preserved for callers that need itabs_timeformat:"Mar 25, 19:00 WIB"for default WIB timezoneWIB = timezone(timedelta(hours=7))added as module constantTests
9 new tests for
_get_time_data()covering:19 tests total, all passing.
Fixes
Ref: #15
Replace three duplicated time parsing functions with a single _get_time_data(e, tz) helper returning {time_status, time_urgency, abs_time}. Deleted functions: - get_match_time_status(e) — urgency + status string - get_match_time_str(e) — status string only - get_start_time_wib(e) — (abs_time, rel_str) tuple New unified helper: - _get_time_data(e, tz=None) returns {time_status, time_urgency, abs_time} - tz defaults to WIB (UTC+7, Indonesia) - canonical rel_str format: 'LIVE', 'In 6h', '12h ago', etc. - time_urgency: 0-3 (higher=livelier) All call sites updated to use _get_time_data(): - format_event(), format_detail_event() - print_browse(), print_detail() - send_to_telegram() Also: removed dead code in print_detail() that called get_match_time_str() but never used the result. Tests: 9 new tests for _get_time_data() covering TBD, future, live, and past event scenarios. 19 tests total, all passing. Fixes: #15Pull request closed