<s> """<STR_LIT>""" <EOL> import datetime <EOL> import time <EOL> ISO_FORMAT = "<STR_LIT>" <EOL> """<STR_LIT>""" <EOL> DT_INPUT_FORMATS = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> """<STR_LIT>""" <EOL> def now ( ) : <EOL> return datetime . datetime . utcnow ( ) <EOL> def now_local ( ) : <EOL> return datetime . datetime . now ( ) <EOL> def now_iso ( ) : <EOL> """<STR_LIT>""" <EOL> return to_iso ( now ( ) ) <EOL> def to_iso ( dt ) : <EOL> """<STR_LIT>""" <EOL> return dt . strftime ( ISO_FORMAT ) <EOL> def from_iso ( dt_str ) : <EOL> """<STR_LIT>""" <EOL> return datetime . datetime . strptime ( dt_str , ISO_FORMAT ) <EOL> def to_utc ( dt ) : <EOL> """<STR_LIT>""" <EOL> time_tuple = time . gmtime ( time . mktime ( dt . timetuple ( ) ) ) <EOL> return datetime . datetime ( * time_tuple [ <NUM_LIT:0> : <NUM_LIT:6> ] ) <EOL> def parse_date_input ( input , formats = DT_INPUT_FORMATS ) : <EOL> """<STR_LIT>""" <EOL> for fmt in formats : <EOL> try : <EOL> return datetime . datetime . strptime ( input , fmt ) <EOL> except ( ValueError ) : <EOL> pass <EOL> raise ValueError ( "<STR_LIT>" % vars ( ) ) </s>
