U
    ‰d/  ã                   @   s^   d Z ddlZddlZddlmZ e d¡Ze dej¡Ze d¡Z	dd„ Z
d	d
„ Zdd„ ZdS )z
Type inference functions
é    N)Únumbersz%^(?P<number>\-?[0-9]*\.?[0-9]*\s?)\%$z´
^(?: # HH:MM and HH:MM:SS
(?P<hour>[0-1]{0,1}[0-9]{2}):
(?P<minute>[0-5][0-9]):?
(?P<second>[0-5][0-9])?$)
|
^(?: # MM:SS.
([0-5][0-9]):
([0-5][0-9])?\.
(?P<microsecond>\d{1,6}))
zD^-?([\d]|[\d]+\.[\d]*|\.[\d]+|[1-9][\d]+\.?[\d]*)((E|e)[-+]?[\d]+)?$c                 C   s6   t  | ¡r2z
t| ƒW S  tk
r0   t| ƒ Y S X dS )z.Explicitly convert a string to a numeric valueN)ÚNUMBER_REGEXÚmatchÚintÚ
ValueErrorÚfloat)Úvalue© r	   ú</tmp/pip-unpacked-wheel-rwywncvq/openpyxl/utils/inference.pyÚcast_numeric   s
    

r   c                 C   s$   t  | ¡}|r t| d¡ƒd S dS )zKExplicitly convert a string to numeric value and format as a
    percentageÚnumberéd   N)ÚPERCENT_REGEXr   r   Úgroup)r   r   r	   r	   r
   Úcast_percentage#   s    
r   c                 C   s`   t  | ¡}|r\| d¡dk	r.| dd… } d}n| d¡dkrBd}nd}tj | |¡} |  ¡ S dS )zJExplicitly convert a string to a number and format as datetime or
    timeÚmicrosecondNé   z%M:%S.%fÚsecondz%H:%Mz%H:%M:%S)Ú
TIME_REGEXr   r   ÚdatetimeÚstrptimeÚtime)r   r   Úpatternr	   r	   r
   Ú	cast_time,   s    
r   )Ú__doc__r   ÚreZopenpyxl.stylesr   Úcompiler   ÚVERBOSEr   r   r   r   r   r	   r	   r	   r
   Ú<module>   s   

ö
		