Skip to content

Fix user timezone preference handling #91

Description

@nyetwurk

Description

The current timezone preference system uses a mix of short codes and IANA timezone identifiers, with manual conversion between them. This should be modernized to use standard IANA timezone identifiers throughout.

Current state

  • Timezone preferences stored in u_users.timezone column
  • Uses a mix of short codes (e.g., "US/Pa") and full IANA identifiers
  • Manual conversion between short codes and full identifiers
  • No validation of timezone identifiers
  • No handling of historical timezone changes

Impact

  • Inconsistent timezone storage format
  • Manual maintenance of timezone code mappings
  • Potential for invalid timezone identifiers
  • No handling of historical timezone changes
  • DST transitions may be handled incorrectly

Required changes

  1. Database schema changes:

    -- Add validation constraint to ensure valid IANA timezone identifiers
    ALTER TABLE u_users 
    ADD CONSTRAINT valid_timezone 
    CHECK (timezone ~ '^[A-Za-z0-9_+-/]+$');
  2. Migration steps:

    -- Create temporary column for new timezone format
    ALTER TABLE u_users ADD COLUMN timezone_new VARCHAR(50);
    
    -- Migrate existing timezone values
    UPDATE u_users 
    SET timezone_new = CASE 
      WHEN timezone = 'US/Pa' THEN 'America/Los_Angeles'
      WHEN timezone = 'US/Ne' THEN 'America/New_York'
      -- Add other mappings
      ELSE timezone 
    END;
    
    -- Verify migration
    SELECT timezone, timezone_new 
    FROM u_users 
    WHERE timezone != timezone_new;
    
    -- Drop old column and rename new one
    ALTER TABLE u_users DROP COLUMN timezone;
    ALTER TABLE u_users RENAME COLUMN timezone_new TO timezone;
  3. Code changes:

    • Remove $tz_to_name mapping array
    • Update timezone selection UI to use standard IANA identifiers
    • Add timezone validation using DateTimeZone::listIdentifiers()
    • Update timezone offset calculation to handle historical changes
  4. UI improvements:

    • Group timezones by region
    • Show current offset and DST status
    • Add search/filter functionality
    • Display friendly names (e.g., "Pacific Time (US & Canada)")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions