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
-
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_+-/]+$');
-
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;
-
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
-
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)")
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
u_users.timezonecolumnImpact
Required changes
Database schema changes:
Migration steps:
Code changes:
$tz_to_namemapping arrayDateTimeZone::listIdentifiers()UI improvements: