
    xh                         S SK r S SKJrJr  S SKJr  S SKJr  S SKJrJ	r	  \\
\	" SSS94   r\ R                  " S	5      rS
\
S\4S jr\\\" \5      4   rg)    N)datetime	timedelta)	Annotated)timezone)BeforeValidatorFieldz^[-a-zA-Z0-9_]+$2   )pattern
max_lengthznow\s*\-\s*\d+\s*(m|h|d)\s*$valuereturnc                    U S:X  a  [         R                  " 5       $ [        R                  U 5      nU(       a  [         R                  " 5       nU R	                  SS5      nSU;   a  SOSn[        [        R                  " SU5      S   5      nS	U;   a  X$[        US
9-  -   $ SU;   a  X$[        US9-  -   $ SU;   a  X$[        US9-  -   $ U $ )z
Allow relative terms like now or now-1h. Only 0 or 1 math operation is permitted.

Accepts
- now
- + (addition)
- - (subtraction)
- m (minutes)
- h (hours)
- d (days)
now  +   z\d+r   m)minutesh)hoursd)days)	r   r   RELATIVE_TIME_REGEXmatchreplaceintrefindallr   )r   r   r   stripped_valuesignnumbers         "/code/apps/shared/schema/fields.pyparse_relative_datetimer%      s     ~||~%%e,EllnsB/>)qrRZZ7:;. 	& 9999N"	 7777N"	v 6666L    )r   r   r   typingr   django.utilsr   pydanticr   r   strSlugStrcompiler   r%   RelativeDateTime r&   r$   <module>r/      si    	 (  ! +
C':rJJ
K jj!@A 3 8 @ X7N'OOP r&   