o
    Td                     @   s   d Z ddlZdddddddd	d
ddddddZedejZdd Zdd Z	ddddddddddd d!Z
d"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ ZdS )0z
Helper functions for np.timedelta64 and np.datetime64.
For now, multiples-of-units (for example timedeltas expressed in tens
of seconds) are not supported.
    N                     	   
               )YMWDhmsmsusnspsfsas natc                 C   s   t |  dk t | dk kS )zB
    Whether the *src* and *dest* units are of the same kind.
    r   DATETIME_UNITSsrcdest r#   n/home/ncw/WWW/www-new/content/articles/pi-bbp/venv/lib/python3.10/site-packages/numba/np/npdatetime_helpers.py	same_kind(   s   r%   c                 C   sX   t |  } t | }| |krdS | dkrdS | |krdS |dkr dS | dkr*|dkr*dS dS )NTr   Fr   r   r    r#   r#   r$   can_cast_timedelta_units/   s   r&   )r   r   )r   r   )r      )r   <   )r   r(   )r     )r	   r)   )r
   r)   )r   r)   )r   r)   )r   r)   )r   r   r   r   r   r   r   r	   r
   r   r   c                 C   sb   | dkrdS | }d}||k r)zt | \}}W n
 ty    Y dS w ||9 }||k s||kr/|S dS )z
    Return an integer multiplier allowing to convert from *big_unit_code*
    to *small_unit_code*.
    None is returned if the conversion is not possible through a
    simple integer multiplication.
    r   r   N)_factorsKeyError)big_unit_codesmall_unit_codecfactormultr#   r#   r$   _get_conversion_multiplierU   s   	r1   c                 C   s   t t|  t| S )zl
    Return an integer multiplier allowing to convert from timedeltas
    of *src_unit* to *dest_unit*.
    )r1   r   )src_unit	dest_unitr#   r#   r$   get_timedelta_conversion_factoro   s   r4   c                 C   s  t |  }t | }|dks|dkr| ddfS |dk r%|dkr%td| |f d\}}|dkrC|dkr8d}d	}d}n$|dkrBd}d
}d}n|dkr\|dkrRd}d}d}n
|dkr\d}d}d}||krvt||}|dusoJ ||f||| |fS t||}|dusJ ||f| ||| fS )a  
    Compute a possible conversion for combining *datetime_unit* and
    *timedelta_unit* (presumably for adding or subtracting).
    Return (result unit, integer datetime multiplier, integer timedelta
    multiplier). RuntimeError is raised if the combination is impossible.
    r   r   r   z1cannot combine datetime64(%r) and timedelta64(%r))r   r   r   r   i: i  i
  i  i@  N)r   RuntimeErrorr1   )datetime_unittimedelta_unitdt_unit_codetd_unit_code	dt_factor	td_factorr/   r#   r#   r$   !get_datetime_timedelta_conversionx   sF   


r<   c                 C   sL   t |  }t | }|dkr|S |dkr| S |dk r|dkrdS ||kr$| S |S )z
    Return the unit result of combining *datetime_unit* with *timedelta_unit*
    (e.g. by adding or subtracting).  None is returned if combining
    those units is forbidden.
    r   r   Nr   )r6   r7   r8   r9   r#   r#   r$    combine_datetime_timedelta_units   s   r=   c                 C   s8   t |  }t | }|dkr|S |dkr| S ||kr|S | S )z9
    Get the best (i.e. finer-grained) of two units.
    r   r   )unit_aunit_babr#   r#   r$   get_best_unit   s   rB   c                 C      d S Nr#   r@   rA   r#   r#   r$   datetime_minimum      rF   c                 C   rC   rD   r#   rE   r#   r#   r$   datetime_maximum   rG   rH   )__doc__numpynpr   timedelta64astypeint64NATr%   r&   r*   r1   r4   r<   r=   rB   rF   rH   r#   r#   r#   r$   <module>   sN    	4