Fix #15: Unify duplicate time functions into _get_time_data() #21

Closed
shoko wants to merge 0 commits from fix/issue-15-unify-time-functions into master
Owner

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 string
  • get_start_time_wib(e) — returned (abs_wib_str, rel_str)

New Unified Helper

def _get_time_data(e, tz=None):
    # Returns: {"time_status": str, "time_urgency": int, "abs_time": str}
    # tz defaults to WIB (UTC+7, Indonesia)

All call sites updated:

  • format_event() — uses time_status + time_urgency
  • format_detail_event() — uses time_status + abs_time
  • print_browse() — uses abs_time + time_status
  • send_to_telegram() — uses abs_time + time_status
  • print_detail() — uses time_status

Also removed dead code in print_detail() that called get_match_time_str() but never used the result.

Key Changes

  • Relative time strings now unified: get_match_time_str format is the canonical one (e.g. "LIVE", "In 6h", "12h ago")
  • time_urgency (0-3) preserved for callers that need it
  • abs_time format: "Mar 25, 19:00 WIB" for default WIB timezone
  • WIB = timezone(timedelta(hours=7)) added as module constant

Tests

9 new tests for _get_time_data() covering:

  • TBD (no startTime)
  • Future: 30m, 6h, 2d
  • Past: LIVE, LIVE 2h, 12h ago, 2d ago
  • abs_time formatting in WIB

19 tests total, all passing.

Fixes

Ref: #15

## 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 string - `get_start_time_wib(e)` — returned `(abs_wib_str, rel_str)` ## New Unified Helper ```python def _get_time_data(e, tz=None): # Returns: {"time_status": str, "time_urgency": int, "abs_time": str} # tz defaults to WIB (UTC+7, Indonesia) ``` All call sites updated: - `format_event()` — uses `time_status` + `time_urgency` - `format_detail_event()` — uses `time_status` + `abs_time` - `print_browse()` — uses `abs_time` + `time_status` - `send_to_telegram()` — uses `abs_time` + `time_status` - `print_detail()` — uses `time_status` Also removed dead code in `print_detail()` that called `get_match_time_str()` but never used the result. ## Key Changes - Relative time strings now unified: `get_match_time_str` format is the canonical one (e.g. `"LIVE"`, `"In 6h"`, `"12h ago"`) - `time_urgency` (0-3) preserved for callers that need it - `abs_time` format: `"Mar 25, 19:00 WIB"` for default WIB timezone - `WIB = timezone(timedelta(hours=7))` added as module constant ## Tests 9 new tests for `_get_time_data()` covering: - TBD (no startTime) - Future: 30m, 6h, 2d - Past: LIVE, LIVE 2h, 12h ago, 2d ago - abs_time formatting in WIB 19 tests total, all passing. ## Fixes Ref: #15
shoko added 1 commit 2026-03-25 15:00:39 +01:00
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: #15
han approved these changes 2026-03-25 15:31:14 +01:00
shoko closed this pull request 2026-03-25 15:36:50 +01:00
shoko deleted branch fix/issue-15-unify-time-functions 2026-03-25 15:36:51 +01:00

Pull request closed

Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shoko/jujutsu-skills#21