
    !g                     ,   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j)                   e eg de                   dZdZdZd ZddZddZd ZddZy)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                 P    t        |       } | dz  dk(  xr | dz  dk7  xs | dz  dk(  S )N   r   d   i  )int)years    [/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/statsmodels/tsa/base/datetools.py_is_leapr(   ;   s3    t9D!8q=AdSjAo@qA    c                    t         j                  t         j                  z  }t        j                  t        | |      rX| j                  dd      j                         j                  d      \  }}t        |j                            \  }}t        |      }nt        j                  t        | |      rm| j                  dd      j                         j                  d      \  }}	t        |	j                            \  }}t        |      }t        |      rC|dk(  r>|dz  }n8t        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    MMBJJ&E	yyWe,ooc"%++-33C8!$QWWY/
s1v	:w	.ooc"%++-33C8!"1779-
s1vA;5A:1HC	:w	.
s7|7-f--T5#..r)   c                 Z   t         j                  t         j                  z  }| j                         } t        j                  t
        | |      rd}d}nZt        j                  t        | |      rd}d}n:t        j                  t        | |      rd}| dz  } |r|dz  }d}nt        d| z        t        t        | j                  d	d
      j                  |            \  }}|C|j                         }t        t        |j                  d	d
      j                  |            \  }}	n |st        d      |||z  z   }||z  |dz
  z   }	t        j                  t        |dz   |      |      D 
cg c]  }
t!        |
       }}
t!        |      g|dz   |z
  z  |z   }|t!        |      g|	z  z   }|dk7  rt        j"                  t        j$                  d|dz         ||z
  dz
        j'                  d      }t        j(                  t        j$                  ||dz         j'                  d      |f   }t        j(                  |t        j$                  d|	dz         j'                  d      f   }t+        ||      D cg c]"  \  }}d
j-                  ||t/        |      g      $ }}}|S |}|S c c}
w c c}}w )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,   z&length must be provided if end is NoneS2)r0   r1   r2   r6   r3   r:   r4   r<   
ValueErrorr   r%   r5   r7   nprepeatr   strtilearangeastyper_zipjoinr   )startendlengthrA   annual_freqr7   yr1offset1yr2offset2yryearsoffsetijdate_arr_ranges                   r'   date_range_strrb   [   sq   $ MMBJJ&EKKME	yyUE*	:ue	,	:ue	,4KC1E9::U]]3r288?@LC
iikCS!4!:!:5!ABWEFFFk));&'A+6!yya)={KLSWLEL#hLK!Og56>Ec#hL7**E|1kAo6c	AFMMdSryy+/:AA$GOPvryyGaK8??EEF&)%&8:"a ''1eU1X"67 : :   M:s   (J"2'J'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_strre      s      U##r)   c                 2    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.
    )rb   re   )rT   rU   rV   rd   s       r'   dates_from_rangerg      s    4 5#v.E%  r)   )N)NN)__doc__statsmodels.compat.pythonr   r   r   r   r=   r0   numpyrK   pandasr   r8   _mdays_months_with_daysdictrR   maprM   r;   updater<   r4   r:   r(   rE   rb   re   rg    r)   r'   <module>rr      s    @ ?  	   	
 
:"v. SS".0ABC   T# F02 3 4
 
	


B
/69x$&!r)   