<s> from datetime import datetime , date , time <EOL> import decimal <EOL> import six <EOL> try : <EOL> import numpy as np <EOL> HAS_NUMPY = True <EOL> except : <EOL> HAS_NUMPY = False <EOL> class DataTypes ( object ) : <EOL> BOOLEAN = <NUM_LIT:0> <EOL> DATE = <NUM_LIT:1> <EOL> ERROR = <NUM_LIT:2> <EOL> INLINE_STRING = <NUM_LIT:3> <EOL> NUMBER = <NUM_LIT:4> <EOL> SHARED_STRING = <NUM_LIT:5> <EOL> STRING = <NUM_LIT:6> <EOL> FORMULA = <NUM_LIT:7> <EOL> EXCEL_BASE_DATE = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> _numberTypes = six . integer_types + ( float , complex , decimal . Decimal ) <EOL> @ staticmethod <EOL> def get_type ( value ) : <EOL> if value . __class__ in six . string_types : <EOL> if len ( value ) > <NUM_LIT:0> and value [ <NUM_LIT:0> ] == '<STR_LIT:=>' : <EOL> return DataTypes . FORMULA <EOL> else : <EOL> return DataTypes . INLINE_STRING <EOL> elif value . __class__ == bool : <EOL> return DataTypes . BOOLEAN <EOL> elif value . __class__ in DataTypes . _numberTypes : <EOL> return DataTypes . NUMBER <EOL> elif isinstance ( value , six . string_types ) : <EOL> if len ( value ) > <NUM_LIT:0> and value [ <NUM_LIT:0> ] == '<STR_LIT:=>' : <EOL> return DataTypes . FORMULA <EOL> else : <EOL> return DataTypes . INLINE_STRING <EOL> elif isinstance ( value , bool ) : <EOL> return DataTypes . BOOLEAN <EOL> elif isinstance ( value , DataTypes . _numberTypes ) : <EOL> return DataTypes . NUMBER <EOL> elif HAS_NUMPY and isinstance ( value , ( np . floating , np . integer , np . complexfloating , np . unsignedinteger ) ) : <EOL> return DataTypes . NUMBER <EOL> elif isinstance ( value , ( datetime , date , time ) ) : <EOL> return DataTypes . DATE <EOL> else : <EOL> return DataTypes . ERROR <EOL> @ staticmethod <EOL> def to_excel_date ( d ) : <EOL> if isinstance ( d , datetime ) : <EOL> delta = d - DataTypes . EXCEL_BASE_DATE <EOL> excel_date = delta . days + ( float ( delta . seconds ) + float ( delta . microseconds ) / <NUM_LIT> ) / ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) + <NUM_LIT:1> <EOL> return excel_date + ( excel_date > <NUM_LIT> ) <EOL> elif isinstance ( d , date ) : <EOL> return DataTypes . to_excel_date ( datetime ( * ( d . timetuple ( ) [ : <NUM_LIT:6> ] ) ) ) <EOL> elif isinstance ( d , time ) : <EOL> return DataTypes . to_excel_date ( datetime ( * ( DataTypes . EXCEL_BASE_DATE . timetuple ( ) [ : <NUM_LIT:3> ] ) , hour = d . hour , minute = d . minute , second = d . second , microsecond = d . microsecond ) ) - <NUM_LIT:1> </s>
