diff options
| author | Craig Jennings <c@cjennings.net> | 2025-11-16 18:16:38 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-11-16 18:16:38 -0600 |
| commit | 94b4241d6cd4e38cab9581a30fffa23b616aa469 (patch) | |
| tree | e81e7ea360f2ff7f9be0399e3b45984e9c4669c1 | |
| parent | da0bd6883a4032054aef4b59c338f60796a0fd99 (diff) | |
test(calendar-sync): Add unit tests for UTC conversion function
Added 5 dedicated unit tests for calendar-sync--convert-utc-to-local
function that was extracted during refactoring:
- test-calendar-sync--convert-utc-to-local-basic-conversion
Tests standard UTC to local time conversion
- test-calendar-sync--convert-utc-to-local-midnight-boundary
Tests day boundary handling (UTC midnight → previous day in some timezones)
- test-calendar-sync--convert-utc-to-local-preserves-minutes
Verifies minute component preservation during conversion
- test-calendar-sync--convert-utc-to-local-returns-five-elements
Validates return format and element types
- test-calendar-sync--convert-utc-to-local-end-of-day
Tests near end-of-day conversion (potential rollover to next day)
Test coverage increased from 51 to 56 tests, all passing.
The extracted function now has both direct unit tests (isolation)
and indirect integration tests (via calendar-sync--parse-timestamp).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
| -rw-r--r-- | tests/test-calendar-sync.el | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/test-calendar-sync.el b/tests/test-calendar-sync.el index 17a17176..2de306b1 100644 --- a/tests/test-calendar-sync.el +++ b/tests/test-calendar-sync.el @@ -179,6 +179,78 @@ Local times should pass through unchanged." (should (= expected-day (nth 2 parsed))) (should (= expected-hour (nth 3 parsed))))) +;;; Tests: UTC to Local Conversion + +(ert-deftest test-calendar-sync--convert-utc-to-local-basic-conversion () + "Test basic UTC to local time conversion." + (let* ((result (calendar-sync--convert-utc-to-local 2025 11 16 14 30 0)) + ;; Compute expected local time + (utc-time (encode-time 0 30 14 16 11 2025 0)) + (local-time (decode-time utc-time)) + (expected-year (nth 5 local-time)) + (expected-month (nth 4 local-time)) + (expected-day (nth 3 local-time)) + (expected-hour (nth 2 local-time)) + (expected-minute (nth 1 local-time))) + ;; Verify conversion happened correctly + (should (= expected-year (nth 0 result))) + (should (= expected-month (nth 1 result))) + (should (= expected-day (nth 2 result))) + (should (= expected-hour (nth 3 result))) + (should (= expected-minute (nth 4 result))))) + +(ert-deftest test-calendar-sync--convert-utc-to-local-midnight-boundary () + "Test UTC midnight conversion handles day boundary correctly." + (let* ((result (calendar-sync--convert-utc-to-local 2025 11 16 0 0 0)) + ;; Compute expected local time + (utc-time (encode-time 0 0 0 16 11 2025 0)) + (local-time (decode-time utc-time)) + (expected-year (nth 5 local-time)) + (expected-month (nth 4 local-time)) + (expected-day (nth 3 local-time)) + (expected-hour (nth 2 local-time))) + ;; In timezones west of UTC, midnight UTC becomes previous day + (should (= expected-year (nth 0 result))) + (should (= expected-month (nth 1 result))) + (should (= expected-day (nth 2 result))) + (should (= expected-hour (nth 3 result))))) + +(ert-deftest test-calendar-sync--convert-utc-to-local-preserves-minutes () + "Test that minute component is preserved during conversion." + (let* ((result (calendar-sync--convert-utc-to-local 2025 11 16 20 45 0)) + (expected-minute 45)) + ;; Minutes should always be preserved (timezone offsets are in hours) + (should (= expected-minute (nth 4 result))))) + +(ert-deftest test-calendar-sync--convert-utc-to-local-returns-five-elements () + "Test that conversion returns exactly 5 elements (year month day hour minute)." + (let ((result (calendar-sync--convert-utc-to-local 2025 11 16 14 30 0))) + (should (= 5 (length result))) + ;; All elements should be numbers + (should (numberp (nth 0 result))) ; year + (should (numberp (nth 1 result))) ; month + (should (numberp (nth 2 result))) ; day + (should (numberp (nth 3 result))) ; hour + (should (numberp (nth 4 result))))) ; minute + +(ert-deftest test-calendar-sync--convert-utc-to-local-end-of-day () + "Test conversion near end of day (23:59 UTC)." + (let* ((result (calendar-sync--convert-utc-to-local 2025 11 16 23 59 0)) + ;; Compute expected local time + (utc-time (encode-time 0 59 23 16 11 2025 0)) + (local-time (decode-time utc-time)) + (expected-year (nth 5 local-time)) + (expected-month (nth 4 local-time)) + (expected-day (nth 3 local-time)) + (expected-hour (nth 2 local-time)) + (expected-minute (nth 1 local-time))) + ;; In timezones east of UTC, this might roll to next day + (should (= expected-year (nth 0 result))) + (should (= expected-month (nth 1 result))) + (should (= expected-day (nth 2 result))) + (should (= expected-hour (nth 3 result))) + (should (= expected-minute (nth 4 result))))) + ;;; Tests: Chronological Sorting (ert-deftest test-calendar-sync--event-start-time-extracts-comparable-time () |
