� <��g+��L�dZddlmZddlmZmZd�Zd�ZGd�d��ZdS) z� This module defines a Duration class. The class Duration allows to define durations in years and months and can be used as limited replacement for timedelta objects. �)� timedelta)� ROUND_FLOOR�Decimalc��||z ||z }}||z �t��}|||zz }||z }t|��|fS)z- A divmod function with boundaries. )� to_integralr�int)�val�low�high�a�b�div�mods �`/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/isodate/duration.py�fquotmodr sT�� ��9�d�S�j�q�A� �q�5� � �k� *� *�C� �c�A�g�+�C��3�J�C� �s�8�8�S�=��c�X�|dvrdS|dvrdS|dzdks|dzdkr |dzdkrd Sd S) zO Determines the number of days of a specific month in a specific year. )������ � �)��� � �i�r�dr���)�year�months r�max_days_in_monthr'sX�� �'�'�'��r� � ����r� �������s� �q�0�0��q��Q����r� �2rc��eZdZdZ dd�Zd�Zd�Zd�Zd�Zd�Z d �Z d �Z d �Z e Z d �ZeZd �Zd�Zd�Zd�Zdd�ZdS)�DurationaY A class which represents a duration. The difference to datetime.timedelta is, that this class handles also differences given in years and months. A Duration treats differences given in year, months separately from all other components. A Duration can be used almost like any timedelta object, however there are some restrictions: * It is not really possible to compare Durations, because it is unclear, whether a duration of 1 year is bigger than 365 days or not. * Equality is only tested between the two (year, month vs. timedelta) basic components. A Duration can also be converted into a datetime object, but this requires a start date or an end date. The algorithm to add a duration to a date is defined at http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes rc ��t|t��stt|����}t| t��stt| ����} ||_| |_t |||||||��|_dS)zN Initialise this Duration instance with the given parameters. N)� isinstancer�str�months�yearsr�tdelta) �self�days�seconds� microseconds� milliseconds�minutes�hours�weeksr-r.s r�__init__zDuration.__init__As����&�'�*�*� *��S��[�[�)�)�F��%��)�)� (��C��J�J�'�'�E��� ��� �� �'�<��w��u� � �� � � rc��|jS�N)�__dict__�r0s r� __getstate__zDuration.__getstate__Zs ���}�rc�:�|j�|��dSr:)r;�update)r0�states r� __setstate__zDuration.__setstate__]s�� � ���U�#�#�#�#�#rc�,�t|j|��S)zU Provide direct access to attributes of included timedelta instance. )�getattrr/)r0�names r� __getattr__zDuration.__getattr__`s���t�{�D�)�)�)rc�,�g}|jr|�d|jz��|jr,d}|jdkrd}|�||jz��|�t|j����d�|��S)zW Return a string representation of this duration similar to timedelta. z%d yearsz %d monthsrz%d monthz, )r.�appendr-r,r/�join)r0�params�fmts r�__str__zDuration.__str__fs����� �:� 3� �M�M�*�t�z�1� 2� 2� 2� �;� -��C��{�a��� �� �M�M�#�� �+� ,� ,� ,�� � �c�$�+�&�&�'�'�'��y�y�� � � rc��d|jj|jj|jj|jj|jj|j|jfzS)z= Return a string suitable for repr(x) calls. z&%s.%s(%d, %d, %d, years=%d, months=%d)) � __class__� __module__�__name__r/r1r2r3r.r-r<s r�__repr__zDuration.__repr__usH��8� �N� %� �N� #� �K� � �K� � �K� $� �J� �K�; � � rc�D�t|j|j|jf��S)zp Return a hash of this instance so that it can be used in, for example, dicts and sets. )�hashr/r-r.r<s r�__hash__zDuration.__hash__�s�� �T�[�$�+�t�z�:�;�;�;rc�Z�t|j |j ���}|j |_|S)zg A simple unary minus. Returns a new Duration instance with all it's negated. �r.r-)r)r.r-r/)r0� negdurations r�__neg__zDuration.__neg__�s0�� �d�j�[�$�+��F�F�F� �"�k�\� ���rc�T�t|t��rAt|j|jz|j|jz���}|j|jz|_|S t |j�����r&t |j�����std���|j|jz}t|dd��\}}|j |jz|z}t||��}|j |kr|}n|j }|� t|��t|��t|�����}|j|zS#t$rYnwxYw t|j|j���}|j|z|_|S#t$rYnwxYwt S)ze Durations can be added with Duration, timedelta, date and datetime objects. rU�>fractional years or months not supported for date calculationsr� �r%r&�day)r+r)r.r-r/�float� is_integer� ValueErrorr&rr%r'r\�replacer�AttributeError�NotImplemented) r0�other� newduration�newmonth�carry�newyear�maxdays�newday�newdts r�__add__zDuration.__add__�s��� �e�X� &� &� �"��j�5�;�.�t�{�U�\�7Q����K�"&��u�|�!;�K� �� � ��$�*�%�%�0�0�2�2� �u�T�[�7I�7I�7T�7T�7V�7V� � �W�����{�T�[�0�H�&�x��B�7�7�O�E�8��j�4�:�-��5�G�'���:�:�G��y�7�"�"� �������M�M���\�\��X���C��K�K�"���E��;��&� &��� � � � �D� ���� �#���D�K�H�H�H�K�!%��u�!4�K� �� ��� � � � �D� �����s%�C=E� E#�"E#�'+F� F �F c��t|t��r2t|j|z|j|z���}|j|z|_|St S)NrU)r+rr)r.r-r/rb�r0rcrds r�__mul__zDuration.__mul__�sP�� �e�S� !� !� �"���e�);�D�K�RW�DW�X�X�X�K�!%��u�!4�K� �� ��rc�6�t|t��rAt|j|jz |j|jz ���}|j|jz |_|S t|j|j���}|j|z |_|S#t $rYnwxYwt S)zj It is possible to subtract Duration and timedelta objects from Duration objects. rU)r+r)r.r-r/� TypeErrorrbrms r�__sub__zDuration.__sub__�s��� �e�X� &� &� �"��j�5�;�.�t�{�U�\�7Q����K�"&��u�|�!;�K� �� � �"���D�K�H�H�H�K�!%��u�!4�K� �� ��� � � � �D� �����s�+B� B�Bc��t|t��rt��}||_||z S t |j�����r&t |j�����std���|j |jz }t|dd��\}}|j |jz |z}t||��}|j |kr|}n|j }|�t|��t|��t|�����}||jz S#t $rYnwxYwt"S)a@ It is possible to subtract Duration objects from date, datetime and timedelta objects. TODO: there is some weird behaviour in date - timedelta ... if timedelta has seconds or microseconds set, then date - timedelta != date + (-timedelta) for now we follow this behaviour to avoid surprises when mixing timedeltas with Durations, but in case this ever changes in the stdlib we can just do: return -self + other instead of all the current code rYrrZr[)r+rr)r/r]r.r^r-r_r&rr%r'r\r`rrarb) r0rc�tmpdurrerfrgrhrirjs r�__rsub__zDuration.__rsub__�sQ�� �e�Y� '� '� !��Z�Z�F�!�F�M��D�=� � ��$�*�%�%�0�0�2�2� �u�T�[�7I�7I�7T�7T�7V�7V� � �W�����{�T�[�0�H�&�x��B�7�7�O�E�8��j�4�:�-��5�G�'���:�:�G��y�7�"�"� �������M�M���\�\��X���C��K�K�"���E��4�;�&� &��� � � � �D� �����s�C=D/�/ D<�;D<c���t|t��r:|jdz|jz|jdz|jzkr|j|jkrdSdS|jdkr|jdkr |j|kSdS)z� If the years, month part and the timedelta part are both equal, then the two Durations are considered equal. rTFr�r+r)r.r-r/�r0rcs r�__eq__zDuration.__eq__ s��� �e�X� &� &� �� �R��$�+�-�� �b� �5�<�/����+���-�-��t��5� �:��?�?�t�{�a�/�/��;�%�'� '��urc���t|t��r:|jdz|jz|jdz|jzks|j|jkrdSdS|jdkr|jdkr |j|kSdS)z� If the years, month part or the timedelta part is not equal, then the two Durations are considered not equal. rTFrrvrws r�__ne__zDuration.__ne__s��� �e�X� &� &� �� �R��$�+�-�� �b� �5�<�/������ �,�,��t��5� �:��?�?�t�{�a�/�/��;�%�'� '��trNc�r�|�|�td���|�|�td���|�||z|z S|||z z S)z� Convert this duration into a timedelta object. This method requires a start datetime or end datetimem, but raises an exception if both are given. Nzstart or end requiredzonly start or end allowed)r_)r0�start�ends r� totimedeltazDuration.totimedelta/sY�� �=�S�[��4�5�5� 5� � ����8�9�9� 9� � ��D�L�E�)� )��c�D�j�!�!r) rrrrrrrrr)NN)rOrN� __qualname__�__doc__r8r=rArErKrPrSrWrk�__radd__rn�__rmul__rqrtrxrzr~r$rrr)r)*s6��������0��������� � � � �2���$�$�$�*�*�*� !� !� !�  �  �  �<�<�<����-�-�-�^�H�����H����*(�(�(�T���"���" "� "� "� "� "� "rr)N) r��datetimer�decimalrrrr'r)r$rr�<module>r�s�����������(�(�(�(�(�(�(�(����" � � �R"�R"�R"�R"�R"�R"�R"�R"�R"�R"r
Memory