<s> import datetime <EOL> import re <EOL> class TimezoneInfo ( datetime . tzinfo ) : <EOL> def __init__ ( self , <EOL> offset ) : <EOL> self . offset = offset <EOL> def utcoffset ( self , <EOL> dt ) : <EOL> return datetime . timedelta ( minutes = self . offset ) <EOL> def dst ( self , <EOL> dt ) : <EOL> return None <EOL> def tzname ( self , <EOL> dt ) : <EOL> return None <EOL> def from_iso_format ( <EOL> string ) : <EOL> """<STR_LIT>""" <EOL> patterns = [ <EOL> ( <EOL> r"<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ) , <EOL> ( <EOL> r"<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ) <EOL> ] <EOL> result = None <EOL> for regex_pattern , strptime_pattern in patterns : <EOL> match = re . match ( regex_pattern , string ) <EOL> if match : <EOL> result = datetime . datetime . strptime ( string , strptime_pattern ) <EOL> break <EOL> elif len ( string ) >= <NUM_LIT:6> : <EOL> timezone = string [ - <NUM_LIT:6> : ] <EOL> if re . match ( r"<STR_LIT>" , timezone ) : <EOL> match = re . match ( regex_pattern , string [ : - <NUM_LIT:6> ] ) <EOL> if match : <EOL> result = datetime . datetime . strptime ( string [ : - <NUM_LIT:6> ] , <EOL> strptime_pattern ) <EOL> offset_hours = int ( timezone [ <NUM_LIT:0> : <NUM_LIT:3> ] ) <EOL> offset_minutes = int ( timezone [ <NUM_LIT:4> : <NUM_LIT:6> ] ) <EOL> if offset_hours < <NUM_LIT:0> : <EOL> offset_minutes *= - <NUM_LIT:1> <EOL> offset_minutes += offset_hours * <NUM_LIT> <EOL> result = result . replace ( tzinfo = TimezoneInfo ( offset_minutes ) ) <EOL> break <EOL> if not result : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> assert result , string <EOL> return result <EOL> def to_iso_format ( <EOL> date_time ) : <EOL> """<STR_LIT>""" <EOL> return date_time . isoformat ( sep = "<STR_LIT:U+0020>" ) </s>
