Пример #1
0
    def on_same_day(cls, value):
        """Returns a :class:`~py42.sdk.queries.query_filter.FilterGroup` that is useful
        for finding results where the value with key ``self._term`` is within the same
        calendar day as the provided ``value``.

        Args:
            value (str or int or float or datetime): The value used to filter results.

        Returns:
            :class:`~py42.sdk.queries.query_filter.FilterGroup`
        """
        if isinstance(value, str):
            value = convert_datetime_to_epoch(datetime.strptime(value, DATE_STR_FORMAT))
        elif isinstance(value, datetime):
            value = convert_datetime_to_epoch(value)
        date_from_value = datetime.utcfromtimestamp(value)
        start_time = datetime(
            date_from_value.year, date_from_value.month, date_from_value.day, 0, 0, 0
        )
        end_time = datetime(
            date_from_value.year, date_from_value.month, date_from_value.day, 23, 59, 59
        )
        formatted_start_time = convert_datetime_to_timestamp_str(start_time)
        formatted_end_time = convert_datetime_to_timestamp_str(end_time)
        return create_in_range_filter_group(
            cls._term, formatted_start_time, formatted_end_time
        )
Пример #2
0
def test_convert_datetime_to_timestamp_str_returns_expected_str():
    d = datetime(2020, 4, 19, 13, 3, 2, 3)
    assert util.convert_datetime_to_timestamp_str(d) == "2020-04-19T13:03:02.000Z"