<commit_before><?php
// (c) Copyright 2002-2015 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$

namespace Tracker\Tabular\Schema;

class DateHelper
{
	private $label;
	private $prior = [];

	function __construct($label)
	{
		$this->label = $label;
	}

	function setupUnix(Column $column)
	{
		$permName = $column->getField();
		$this->setupCallbacks(
			$column,
			function ($value, array $extra) {
				if (empty($value)) {
					return '';
				}

				return $this->convertToUnix($value);
			},
			function (& $info, $value) use ($permName) {
				$info['fields'][$permName] = $value;
			}
		);
	}
	
	function setupFormat($format, Column $column)
	{
		$permName = $column->getField();
		$this->setupCallbacks(
			$column,
			function ($value, array $extra) use ($format) {
				if (empty($value)) {
					return '';
				}

				$unix = $this->convertToUnix($value);
				return date($format, $unix);
			},
			function (& $info, $value) use ($permName, $format) {
				$date = date_create_from_format($format, $value);<commit_msg>[FIX] trackers: Prevent empty dates being rendered as '0000-00-00 00:00:00'<commit_after><?php
// (c) Copyright 2002-2015 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$

namespace Tracker\Tabular\Schema;

class DateHelper
{
	private $label;
	private $prior = [];

	function __construct($label)
	{
		$this->label = $label;
	}

	function setupUnix(Column $column)
	{
		$permName = $column->getField();
		$this->setupCallbacks(
			$column,
			function ($value, array $extra) {
				if (empty($value)) {
					return '';
				}

				return $this->convertToUnix($value);
			},
			function (& $info, $value) use ($permName) {
				$info['fields'][$permName] = $value;
			}
		);
	}
	
	function setupFormat($format, Column $column)
	{
		$permName = $column->getField();
		$this->setupCallbacks(
			$column,
			function ($value, array $extra) use ($format) {
				if (empty($value) || $value === '0000-00-00 00:00:00') {	// empty dates are indexed as '0000-00-00 00:00:00'
					return '';
				}

				$unix = $this->convertToUnix($value);
				return date($format, $unix);
			},
			function (& $info, $value) use ($permName, $format) {
				$date = date_create_from_format($format, $value);
{'fraction_non_alphanumeric': 0.16082554517133957, 'fraction_numerical': 0.022585669781931463, 'mean_word_length': 3.5308641975308643, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '405893', 'n_tokens_mistral': 1030, 'n_tokens_neox': 845, 'n_words': 228}