<commit_before><?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

class Search_Formatter_ValueFormatter_Datetime extends Search_Formatter_ValueFormatter_Abstract
{
	protected $format;

	function __construct($arguments)
	{
		if( isset($arguments['dateFormat']) ) {
			$this->format = $arguments['dateFormat'];
		} else {
			$tikilib = TikiLib::lib('tiki');
			$this->format = $tikilib->get_short_datetime_format();
		}
	}

	function render($name, $value, array $entry)
	{
		$tikilib = TikiLib::lib('tiki');
		$time = $this->timestamp($value);

		if (is_numeric($value)) {	// expects a unix timestamp but might be getting the default value
			return $tikilib->date_format($this->format, $value);
		} elseif (false !== $time) {
			return $tikilib->date_format($this->format, $time);
		} else {
			return $value;
		}
	}

	public function timestamp($value) {
		if (preg_match('/^\d{14}$/', $value)) {
			// Facing a date formated as YYYYMMDDHHIISS as indexed in lucene
			// Always stored as UTC
			$value = date_create_from_format('YmdHise', $value . 'UTC')->getTimestamp();
		}

		// indexed datetime value is always UTC, so use correct timezone when converting back to timestamp
		$old_tz = date_default_timezone_get();
		date_default_timezone_set('UTC');
		$time = strtotime($value);
		date_default_timezone_set($old_tz);

		return $time;
	}
}

<commit_msg>[FIX] php71: Allow Search_Formatter_ValueFormatter_Datetime constructor to be used without arguments<commit_after><?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

class Search_Formatter_ValueFormatter_Datetime extends Search_Formatter_ValueFormatter_Abstract
{
	protected $format;

	function __construct(array $arguments = [])
	{
		if( isset($arguments['dateFormat']) ) {
			$this->format = $arguments['dateFormat'];
		} else {
			$tikilib = TikiLib::lib('tiki');
			$this->format = $tikilib->get_short_datetime_format();
		}
	}

	function render($name, $value, array $entry)
	{
		$tikilib = TikiLib::lib('tiki');
		$time = $this->timestamp($value);

		if (is_numeric($value)) {	// expects a unix timestamp but might be getting the default value
			return $tikilib->date_format($this->format, $value);
		} elseif (false !== $time) {
			return $tikilib->date_format($this->format, $time);
		} else {
			return $value;
		}
	}

	public function timestamp($value) {
		if (preg_match('/^\d{14}$/', $value)) {
			// Facing a date formated as YYYYMMDDHHIISS as indexed in lucene
			// Always stored as UTC
			$value = date_create_from_format('YmdHise', $value . 'UTC')->getTimestamp();
		}

		// indexed datetime value is always UTC, so use correct timezone when converting back to timestamp
		$old_tz = date_default_timezone_get();
		date_default_timezone_set('UTC');
		$time = strtotime($value);
		date_default_timezone_set($old_tz);

		return $time;
	}
}


{'fraction_non_alphanumeric': 0.1337854500616523, 'fraction_numerical': 0.006781750924784217, 'mean_word_length': 4.3993344425956735, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1558557', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1023, 'n_words': 284}