defaultFormat = $options['defaultFormat'] ?? 'ConvertibleTimestamp'; $this->stringifyFormat = $options['stringifyFormat'] ?? TS_ISO_8601; } public function validate( $name, $value, array $settings, array $options ) { // Confusing synonyms for the current time accepted by ConvertibleTimestamp if ( !$value ) { $this->callbacks->recordCondition( new ValidationException( $name, $value, $settings, 'unclearnowtimestamp', [] ), $options ); $value = 'now'; } try { $timestamp = new ConvertibleTimestamp( $value === 'now' ? false : $value ); } catch ( TimestampException $ex ) { throw new ValidationException( $name, $value, $settings, 'badtimestamp', [], $ex ); } $format = $settings[self::PARAM_TIMESTAMP_FORMAT] ?? $this->defaultFormat; switch ( $format ) { case 'ConvertibleTimestamp': return $timestamp; case 'DateTime': // Eew, no getter. return $timestamp->timestamp; default: return $timestamp->getTimestamp( $format ); } } public function stringifyValue( $name, $value, array $settings, array $options ) { if ( !$value instanceof ConvertibleTimestamp ) { $value = new ConvertibleTimestamp( $value ); } return $value->getTimestamp( $this->stringifyFormat ); } }