<s> """<STR_LIT>""" <EOL> import pytz <EOL> import datetime <EOL> def hour_dist ( h1 , h2 ) : <EOL> abs_dist = abs ( ( h1 % <NUM_LIT> ) - ( h2 % <NUM_LIT> ) ) <EOL> if abs_dist > <NUM_LIT:12> : <EOL> return <NUM_LIT> - abs_dist <EOL> else : <EOL> return abs_dist <EOL> def hour_avg ( h1 , h2 ) : <EOL> h1 = h1 % <NUM_LIT> <EOL> h2 = h2 % <NUM_LIT> <EOL> diff = abs ( h1 - h2 ) <EOL> if diff <= <NUM_LIT:12> : <EOL> return ( h1 + h2 ) / <NUM_LIT> <EOL> else : <EOL> ( ( <NUM_LIT> - diff ) / <NUM_LIT> + max ( h1 , h2 ) ) % <NUM_LIT> <EOL> def show_tran ( dist , tz_name , tran , inf ) : <EOL> tzinfo = pytz . timezone ( tz_name ) <EOL> closest_tran_utc = pytz . utc . localize ( tran ) <EOL> before = closest_tran_utc + datetime . timedelta ( seconds = - <NUM_LIT:1> ) <EOL> after = closest_tran_utc + datetime . timedelta ( seconds = <NUM_LIT:1> ) <EOL> print "<STR_LIT>" % ( dist , before . astimezone ( tzinfo ) , <EOL> after . astimezone ( tzinfo ) , tz_name ) <EOL> from_noon = [ ] <EOL> from_midnight = [ ] <EOL> for tz_name in pytz . common_timezones : <EOL> tzinfo = pytz . timezone ( tz_name ) <EOL> if isinstance ( tzinfo , ( pytz . tzinfo . StaticTzInfo , pytz . UTC . __class__ ) ) : <EOL> continue <EOL> for tran , inf in zip ( tzinfo . _utc_transition_times , tzinfo . _transition_info ) : <EOL> if tran < datetime . datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:1> ) or tran > datetime . datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:1> ) : <EOL> continue <EOL> try : <EOL> closest_tran_utc = pytz . utc . localize ( tran ) <EOL> before = closest_tran_utc + datetime . timedelta ( seconds = - <NUM_LIT:1> ) <EOL> after = closest_tran_utc + datetime . timedelta ( seconds = <NUM_LIT:1> ) <EOL> tran_beforelocal = before . astimezone ( tzinfo ) + datetime . timedelta ( seconds = <NUM_LIT:1> ) <EOL> tran_afterlocal = after . astimezone ( tzinfo ) + datetime . timedelta ( seconds = - <NUM_LIT:1> ) <EOL> average = hour_avg ( tran_beforelocal . hour , tran_afterlocal . hour ) <EOL> distance_from_noon = hour_dist ( average , <NUM_LIT:12> ) <EOL> from_noon . append ( ( distance_from_noon , tz_name , tran , inf ) ) <EOL> distance_from_midnight = hour_dist ( average , <NUM_LIT:0> ) <EOL> from_midnight . append ( ( distance_from_midnight , tz_name , tran , inf ) ) <EOL> except Exception , e : <EOL> print "<STR_LIT>" % ( tz_name , tran , inf , e ) <EOL> print "<STR_LIT>" <EOL> from_noon . sort ( ) <EOL> for t in from_noon [ <NUM_LIT:0> : <NUM_LIT:10> ] : <EOL> show_tran ( * t ) <EOL> print "<STR_LIT>" <EOL> from_midnight . sort ( ) <EOL> for t in from_midnight [ <NUM_LIT:0> : <NUM_LIT:30> ] : <EOL> show_tran ( * t ) </s>
