Skip to content

Support obtaining the system timezone on old Debian-based distributions #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 82 commits into from
Mar 31, 2025

Conversation

DmitryNekrasov
Copy link
Contributor

@DmitryNekrasov DmitryNekrasov commented Mar 20, 2025

Issue Background

On older Debian-based distributions (between Etch 4.0 and Jessie 8.0), the system timezone configuration is stored differently than on most modern Linux distributions. Instead of using a symbolic link for /etc/localtime, these Debian versions used a regular file copied from the zoneinfo directory.

The current implementation in kotlinx-datetime only supports finding the timezone via the symlink method, which fails on these systems. Even though these Debian versions are past their support date, they remain in use in various environments, making this fix valuable for broader compatibility.

Solution

I've modified the currentSystemDefaultZone() method to implement a fallback mechanism when the symlink approach fails:

  1. First, attempt to determine the timezone via the symbolic link path (existing method)
  2. If that fails, read the contents of the Debian-specific /etc/timezone file
  3. Verify that the timezone is valid by comparing the contents of /etc/localtime with the corresponding zoneinfo file
  4. If all attempts fail, throw an appropriate exception with a detailed message

This implementation gracefully handles all possible configurations while maintaining robust validation to prevent silent failures and incorrect timezone reporting.

Testing Approach

To thoroughly test this fix, I created a comprehensive test suite using testcontainers that verifies correct behavior across different system configurations:

Modern Systems (Ubuntu Noble)

  • Correctly identifies timezone when properly configured
  • Falls back to UTC when no timezone is configured
  • Throws appropriate exception when symlinks are incorrect

Legacy Systems (Debian Jessie)

  • Reads timezone from /etc/timezone when configured correctly
  • Falls back to "Universal" in default configuration
  • Falls back to UTC when /etc/localtime is missing
  • Throws appropriate exceptions for inconsistent or incorrect configurations

The testcontainers approach provides several advantages:

  • Enables testing against real Linux distributions without modifying the developer's environment
  • Creates isolated, reproducible test environments for each configuration scenario
  • Allows validation against both legacy and modern systems
  • Ensures the fix works correctly in real-world environments, not just simulated ones

Additionally, all standard timezone tests from the common package also pass in the correctly configured containers, confirming that core functionality remains intact.

Summary

This fix significantly improves the robustness of the kotlinx-datetime library by extending timezone detection support to older Debian-based systems while maintaining strict validation. The comprehensive test suite ensures reliability across diverse system configurations.

@DmitryNekrasov DmitryNekrasov marked this pull request as ready for review March 27, 2025 11:43
@dkhalanskyjb dkhalanskyjb self-requested a review March 27, 2025 12:01
@dkhalanskyjb dkhalanskyjb added this to the 0.7.0 milestone Mar 31, 2025
Copy link
Collaborator

@dkhalanskyjb dkhalanskyjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! I believe it's good to go. I've checked this on a Jessie VM, and the problem is both 1) real and 2) solved by this PR.

@fzhinkin fzhinkin requested review from fzhinkin and removed request for fzhinkin March 31, 2025 14:12
@DmitryNekrasov DmitryNekrasov merged commit 7d2764a into master Mar 31, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants