value = $value; } else { if (! is_int($value)) { throw new Exception\InvalidArgumentException(sprintf( 'Value must be either DateTime instance or integer; received "%s"', gettype($value) )); } if (! is_string($dateFormatChar)) { throw new Exception\InvalidArgumentException(sprintf( 'Date format character must be supplied as string; received "%s"', gettype($dateFormatChar) )); } $this->value = $value; $this->dateFormatChar = $dateFormatChar; } if ($operator === null) { $operator = '<='; } elseif ( ! in_array( $operator, ['<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>'] ) ) { throw new Exception\InvalidArgumentException( "Unsupported comparison operator: '$operator'" ); } $this->operator = $operator; } /** * Returns TRUE if timestamp is accepted, otherwise FALSE is returned. * * @param array $event event data * @return bool */ public function filter(array $event) { if (! isset($event['timestamp'])) { return false; } $datetime = $event['timestamp']; if (! ($datetime instanceof DateTime || is_int($datetime) || is_string($datetime))) { return false; } $timestamp = $datetime instanceof DateTime ? $datetime->getTimestamp() : (int) $datetime; if ($this->value instanceof DateTime) { return version_compare((string) $timestamp, (string) $this->value->getTimestamp(), $this->operator); } return version_compare( (string) idate($this->dateFormatChar, $timestamp), (string) $this->value, $this->operator ); } }