# Path: proto/datetime_helpers.py
# _UTC_EPOCH = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc)
# _RFC3339_MICROS = "%Y-%m-%dT%H:%M:%S.%fZ"
# _RFC3339_NO_FRACTION = "%Y-%m-%dT%H:%M:%S"
# _RFC3339_NANOS = re.compile(
#     r"""
#     (?P<no_fraction>
#         \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}  # YYYY-MM-DDTHH:MM:SS
#     )
#     (                                        # Optional decimal part
#      \.                                      # decimal point
#      (?P<nanos>\d{1,9})                      # nanoseconds, maybe truncated
#     )?
#     Z                                        # Zulu
# """,
#     re.VERBOSE,
# )
# def _from_microseconds(value):
# def _to_rfc3339(value, ignore_zone=True):
#     def __new__(cls, *args, **kw):
#     def replace(self, *args, **kw):
#     def nanosecond(self):
#     def rfc3339(self):
#     def from_rfc3339(cls, stamp):
#     def timestamp_pb(self):
#     def from_timestamp_pb(cls, stamp):
# class DatetimeWithNanoseconds(datetime.datetime):
# 
# Path: proto/utils.py
# def cached_property(fx):
#     def inner(self):


from datetime import datetime
from datetime import timedelta
from datetime import timezone
from google.protobuf import duration_pb2
from google.protobuf import timestamp_pb2
from proto import datetime_helpers, utils
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




class TimestampRule:
    """A marshal between Python datetimes and protobuf timestamps.

    Note: Python datetimes are less precise than protobuf datetimes
    (microsecond vs. nanosecond level precision). If nanosecond-level
    precision matters, it is recommended to interact with the internal
    proto directly.
    """

    def to_python(
        self, value, *, absent: bool = None
    ) -> datetime_helpers.DatetimeWithNanoseconds:
        if isinstance(value, timestamp_pb2.Timestamp):
            if absent:
                return None

# Path: proto/datetime_helpers.py
# _UTC_EPOCH = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc)
# _RFC3339_MICROS = "%Y-%m-%dT%H:%M:%S.%fZ"
# _RFC3339_NO_FRACTION = "%Y-%m-%dT%H:%M:%S"
# _RFC3339_NANOS = re.compile(
#     r"""
#     (?P<no_fraction>
#         \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}  # YYYY-MM-DDTHH:MM:SS
#     )
#     (                                        # Optional decimal part
#      \.                                      # decimal point
#      (?P<nanos>\d{1,9})                      # nanoseconds, maybe truncated
#     )?
#     Z                                        # Zulu
# """,
#     re.VERBOSE,
# )
# def _from_microseconds(value):
# def _to_rfc3339(value, ignore_zone=True):
#     def __new__(cls, *args, **kw):
#     def replace(self, *args, **kw):
#     def nanosecond(self):
#     def rfc3339(self):
#     def from_rfc3339(cls, stamp):
#     def timestamp_pb(self):
#     def from_timestamp_pb(cls, stamp):
# class DatetimeWithNanoseconds(datetime.datetime):
# 
# Path: proto/utils.py
# def cached_property(fx):
#     def inner(self):


# Path: proto/marshal/rules/dates.py
from datetime import datetime
from datetime import timedelta
from datetime import timezone
from google.protobuf import duration_pb2
from google.protobuf import timestamp_pb2
from proto import datetime_helpers, utils

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




class TimestampRule:
    """A marshal between Python datetimes and protobuf timestamps.

    Note: Python datetimes are less precise than protobuf datetimes
    (microsecond vs. nanosecond level precision). If nanosecond-level
    precision matters, it is recommended to interact with the internal
    proto directly.
    """

    def to_python(
        self, value, *, absent: bool = None
    ) -> datetime_helpers.DatetimeWithNanoseconds:
        if isinstance(value, timestamp_pb2.Timestamp):
            if absent:
                return None

            return datetime_helpers.DatetimeWithNanoseconds.from_timestamp_pb(value)