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 )
def test_search_file_events(self, connection): start_date = datetime.utcnow() - timedelta(1) end_date = datetime.utcnow() start_timestamp = convert_datetime_to_epoch(start_date) end_timestamp = convert_datetime_to_epoch(end_date) date_query = EventTimestamp.in_range(start_timestamp, end_timestamp) query = FileEventQuery.all(date_query) response = connection.securitydata.search_file_events(query) assert_successful_response(response)
def timestamp(): return convert_datetime_to_epoch(datetime.utcnow())