tz algorithm ============ Function: Get UTC offset at a specified UTC time (for converting from UTC to local time) Input: Requested UTC time (UTC date/time to determine the effective UTC offset for) Input: Time zone Output: Base UTC offset and save offset in effect at the requested time Data: All time zones with their rule sets with their rules, as stored in the tz database text files Select first rule set of the time zone Set base UTC offset from the rule set Set save offset = 0 Set active year = Year(End date of the rule set) - 1 Set date pointer to Jan 1st of the active year For each rule set of the time zone: Set base UTC offset from the rule set If the rule set specifies rules: Loop with all rules specified in the rule set: While the date pointer is in the active year: Select the rule with the first transition month/day/time on or after the date pointer from all rules valid in the active year |< Break if no such rule was found Compute the UTC transition time from the its relative date, its time type and the active base UTC/save offset Recompute the rule set's UTC end time from its time type and the active base UTC/save offset If the UTC transition time is greater than or equal to the rule set's UTC end time: Set date pointer = rule set's UTC end time |< - - - - Continue with the next rule set If the requested UTC time is smaller than the UTC transition time: Return with the current base UTC/save offset Set save offset from the selected rule Set date pointer to the rule's UTC transition time + 1 day Increase active year by 1 If the rule set does not specifiy rules: Recompute the rule set's UTC end time from its time type and the active base UTC/save offset If the UTC transition time is greater than or equal to the rule set's UTC end time: Set date pointer = rule set's UTC end time |< - - Continue with the next rule set If the requested UTC time is smaller than the rule set's UTC end time: Return with the current base UTC/save offset