# Time 9, Exercise 2: zone numbers, zone offsets and a meeting across the world from datetime import datetime, timedelta, timezone # Part 1: the ideal zone for a longitude is the nearest multiple of 15 degrees. def ideal_zone(longitude_east): return round(longitude_east / 15) # whole hours from Greenwich def sun_gap_minutes(longitude_east, zone_hours): # Sun time at this longitude minus the zone's clock time, in minutes return longitude_east * 4 - zone_hours * 60 places = {"Edinburgh": -3.19, "New York": -74.0, "Delhi": 77.2, "Tokyo": 139.7} for name, lon in places.items(): z = ideal_zone(lon) print(name, "ideal zone", z, "hours; sun-time gap", round(sun_gap_minutes(lon, z), 1), "min") # Part 2: the real zone can differ from the ideal one. India uses a single zone at +5:30. print("Delhi on the real zone (+5.5 h): sun-time gap", round(sun_gap_minutes(77.2, 5.5), 1), "min") # Part 3: a meeting at 15:00 London time on 14 January, shown in other zones (January offsets; Sydney is on its summer time, +11). meeting = datetime(2027, 1, 14, 15, 0, tzinfo=timezone.utc) offsets = {"London": 0, "New York": -5, "Delhi": 5.5, "Tokyo": 9, "Sydney": 11} for name, h in offsets.items(): local = meeting.astimezone(timezone(timedelta(hours=h))) print(name, local.strftime("%a %d %b %H:%M")) # Output when run: # Edinburgh ideal zone 0 hours; sun-time gap -12.8 min # New York ideal zone -5 hours; sun-time gap 4.0 min # Delhi ideal zone 5 hours; sun-time gap 8.8 min # Tokyo ideal zone 9 hours; sun-time gap 18.8 min # Delhi on the real zone (+5.5 h): sun-time gap -21.2 min # London Thu 14 Jan 15:00 # New York Thu 14 Jan 10:00 # Delhi Thu 14 Jan 20:30 # Tokyo Fri 15 Jan 00:00 # Sydney Fri 15 Jan 02:00 # Reading the output: Edinburgh is 3.19 degrees west, so its sun time is 12.8 minutes behind # the Greenwich zone it uses. Delhi at 77.2 degrees east has sun time 77.2 x 4 = 308.8 minutes # ahead of Greenwich; the nearest ideal zone (5 h = 300 min) leaves 8.8 minutes, but India's # real zone of +5:30 is 330 min, so the clock runs 21.2 minutes ahead of the sun. The same # 15:00 meeting falls at midnight in Tokyo, which is already the next date.