
    M/Ph                     f   d Z ddlmZmZmZmZ ddlZddlZddlZ	ddl
mZ ddddddddd	Zg d
Z e edd          e          Z e e ee edd                    e                    Ze                     e eg de                               dZdZdZd ZddZddZd ZddZdS )z
Tools for working with dates
    )asstrlmaplrangelzipN)to_datetime)      )      )	   r      r	   )1234IIIIIIIV)r	      r	   r   r	   r   r	   r	   r   r	   r   r	         )r   r   r   r   VVIVIIVIIIIXXXIXIIz^\d?\d?\d?\d$z
^               # beginning of string
\d?\d?\d?\d     # match any number 1-9999, includes leading zeros

(:?q)           # use q or a : as a separator

([1-4]|(I{1,3}V?)) # match 1-4 or I-IV roman numerals

$               # end of string
a=  
^               # beginning of string
\d?\d?\d?\d     # match any number 1-9999, includes leading zeros

(:?m)           # use m or a : as a separator

(([1-9][0-2]?)|(I?XI{0,2}|I?VI{0,3}|I{1,3}))  # match 1-12 or
                                              # I-XII roman numerals

$               # end of string
c                 V    t          |           } | dz  dk    o| dz  dk    p| dz  dk    S )N   r   d   i  )int)years    ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tsa/base/datetools.py_is_leapr(   ;   s5    t99D!8q=AdSjAo@qA    c                 :   t           j        t           j        z  }t          j        t          | |          rp|                     dd                                                              d          \  }}t          |	                                         \  }}t          |          }nt          j        t          | |          r|                     dd                                                              d          \  }}	t          |		                                         \  }}t          |          }t          |          r|dk    r|dz  }n=t          j        t          | |          rd\  }}t          |           }nt          | fi |S t!          j        |||          S )a$  
    Uses dateutil.parser.parse, but also handles monthly dates of the form
    1999m4, 1999:m4, 1999:mIV, 1999mIV and the same for quarterly data
    with q instead of m. It is not case sensitive. The default for annual
    data is the end of the year, which also differs from dateutil.
    : qm   r   r   )re
IGNORECASEVERBOSEsearch
_q_patternreplacelowersplit_quarter_to_dayupperr%   
_m_pattern_month_to_dayr(   
_y_patternr   datetime)
timestr
parserinfokwargsflagsyr-   monthdayr&   r.   s
             r'   date_parserrE   @   s[    MBJ&E	yWe,, .ooc"%%++--33C88!$QWWYY/
s1vv	:w	.	. 
.ooc"%%++--33C88!"17799-
s1vvA;; 	5A::1HC	:w	.	. .
s7||7--f---T5#...r)   c                 Z   t           j        t           j        z  }|                                 } t          j        t
          | |          rd}dn^t          j        t          | |          rd}dn>t          j        t          | |          rd}| dz  } |r|dz  }dnt          d| z            t          t          |                     d	d
                                                  \  }}|T|                                }t          t          |                    d	d
                                                  \  }}n$|st          d          |||z  z   }||z  |dz
  z   }d t          j        t          |dz   |          |          D             }	t!          |          g|dz   |z
  z  |	z   }	|	t!          |          g|z  z   }	dk    rt          j        t          j        d|dz             ||z
  dz
                                d          }
t          j        t          j        ||dz                                 d          |
f         }
t          j        |
t          j        d|dz                                 d          f         }
fdt+          |	|
          D             }n|	}|S )a  
    Returns a list of abbreviated date strings.

    Parameters
    ----------
    start : str
        The first abbreviated date, for instance, '1965q1' or '1965m1'
    end : str, optional
        The last abbreviated date if length is None.
    length : int, optional
        The length of the returned array of end is None.

    Returns
    -------
    date_range : list
        List of strings
    r   r.   r#   r-   r   a1azDate %s not understoodr+   r,   Nz&length must be provided if end is Nonec                 ,    g | ]}t          |          S  )str).0yrs     r'   
<listcomp>z"date_range_str.<locals>.<listcomp>   s    LLLSWWLLLr)   S2c           	      `    g | ]*\  }}d                      |t          |          g          +S )r,   )joinr   )rL   ijr7   s      r'   rN   z"date_range_str.<locals>.<listcomp>   sF     : : :"a ''1eU1XX"677 : : :r)   )r0   r1   r2   r6   r3   r:   r4   r<   
ValueErrorr   r%   r5   r7   nprepeatr   rK   tilearangeastyper_zip)startendlengthrA   annual_freqyr1offset1yr2offset2yearsoffsetdate_arr_ranger7   s               @r'   date_range_strrg   [   s   $ MBJ&EKKMME	yUE** ;	:ue	,	, 
;	:ue	,	, ; 	4KC1E9:::U]]3r2288??@@LC
iikkCS!4!4!:!:5!A!ABBWW 	GEFFFFk));&'A+6LLrya)=)={KKLLLE#hhLK!Og56>Ec#hhL7**E||1kAo66c	AFFMMdSSry+/::AA$GGOPvryGaK88??EEEF: : : :&)%&8&8: : : r)   c                 ,    t          t          |           S )ak  
    Turns a sequence of date strings and returns a list of datetime.

    Parameters
    ----------
    dates : array_like
        A sequence of abbreviated dates as string. For instance,
        '1996m1' or '1996Q1'. The datetime dates are at the end of the
        period.

    Returns
    -------
    date_list : ndarray
        A list of datetime types.
    )r   rE   )datess    r'   dates_from_strrj      s      U###r)   c                 B    t          | ||          }t          |          S )aX  
    Turns a sequence of date strings and returns a list of datetime.

    Parameters
    ----------
    start : str
        The first abbreviated date, for instance, '1965q1' or '1965m1'
    end : str, optional
        The last abbreviated date if length is None.
    length : int, optional
        The length of the returned array of end is None.

    Examples
    --------
    >>> import statsmodels.api as sm
    >>> import pandas as pd
    >>> nobs = 50
    >>> dates = pd.date_range('1960m1', length=nobs)


    Returns
    -------
    date_list : ndarray
        A list of datetime types.
    )rg   rj   )r\   r]   r^   ri   s       r'   dates_from_rangerl      s#    4 5#v..E%   r)   )N)NN)__doc__statsmodels.compat.pythonr   r   r   r   r=   r0   numpyrU   pandasr   r8   _mdays_months_with_daysdictr[   maprK   r;   updater<   r4   r:   r(   rE   rg   rj   rl   rJ   r)   r'   <module>rv      s    @ ? ? ? ? ? ? ? ? ? ? ?  				           	
 	
 
:	9	9D"v.. SSS"..0ABBCC   TT## F F F02 2 3 3 4 4 4
 
	


B B B
/ / / /69 9 9 9x$ $ $&! ! ! ! ! !r)   