<commit_before><?php

class DbDatetimeTest extends FunctionalTest {
	static $fixture_file = 'sqlite3/tests/DbDatetimeTest.yml';
	
	/**
	 * Check if dates match more or less. This takes into the account the db query
	 * can overflow to the next second giving offset readings.
	 */
	private function matchesRoughly($date1, $date2, $comment = '') {
		$allowedDifference = 5; // seconds
		
		$time1 = is_numeric($date1) ? $date1 : strtotime($date1);
		$time2 = is_numeric($date2) ? $date2 : strtotime($date2);
		
		$this->assertTrue(abs($time1-$time2)<$allowedDifference, $comment . " ($date1, $date2)");
	}
	
	private function getDbNow() {
		$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('now', '%U');
		return DB::query($query)->value();
	}
	
	function setUp() {
		parent::setUp();
		$this->adapter = DB::getConn();
		$this->supportDbDatetime = method_exists($this->adapter, 'datetimeIntervalClause');
	}

	function testCorrectNow() {
		if($this->supportDbDatetime) {
			$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('now', '%U');
			$result = DB::query($query)->value();
			$this->assertRegExp('/^\d*$/', $result);
			$this->assertTrue($result>0);
		}
	}

	function testDbDatetimeFormat() {
		if($this->supportDbDatetime) {
			$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('1973-10-14 10:30:00', '%H:%i, %d/%m/%Y');
			$result = DB::query($query)->value();
			$this->matchesRoughly($result, date('H:i, d/m/Y', strtotime('1973-10-14 10:30:00')), 'nice literal time');

			$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('now', '%d');
			$result = DB::query($query)->value();
			$this->matchesRoughly($result, date('d', $this->getDbNow()), 'todays day');

			$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('"Created"', '%U') . ' AS test FROM "SiteTree" WHERE "URLSegment" = \'home\'';
			$result = DB::query($query)->value();
			$this->matchesRoughly($result, strtotime(Dataobject::get_one('SiteTree',"\"URLSegment\" = 'home'")->Created), 'SiteTree[home]->Created as timestamp');
		}
	}
	<commit_msg>MINOR Correction of "Dataobject" to "DataObject" correct class case<commit_after><?php

class DbDatetimeTest extends FunctionalTest {
	static $fixture_file = 'sqlite3/tests/DbDatetimeTest.yml';
	
	/**
	 * Check if dates match more or less. This takes into the account the db query
	 * can overflow to the next second giving offset readings.
	 */
	private function matchesRoughly($date1, $date2, $comment = '') {
		$allowedDifference = 5; // seconds
		
		$time1 = is_numeric($date1) ? $date1 : strtotime($date1);
		$time2 = is_numeric($date2) ? $date2 : strtotime($date2);
		
		$this->assertTrue(abs($time1-$time2)<$allowedDifference, $comment . " ($date1, $date2)");
	}
	
	private function getDbNow() {
		$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('now', '%U');
		return DB::query($query)->value();
	}
	
	function setUp() {
		parent::setUp();
		$this->adapter = DB::getConn();
		$this->supportDbDatetime = method_exists($this->adapter, 'datetimeIntervalClause');
	}

	function testCorrectNow() {
		if($this->supportDbDatetime) {
			$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('now', '%U');
			$result = DB::query($query)->value();
			$this->assertRegExp('/^\d*$/', $result);
			$this->assertTrue($result>0);
		}
	}

	function testDbDatetimeFormat() {
		if($this->supportDbDatetime) {
			$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('1973-10-14 10:30:00', '%H:%i, %d/%m/%Y');
			$result = DB::query($query)->value();
			$this->matchesRoughly($result, date('H:i, d/m/Y', strtotime('1973-10-14 10:30:00')), 'nice literal time');

			$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('now', '%d');
			$result = DB::query($query)->value();
			$this->matchesRoughly($result, date('d', $this->getDbNow()), 'todays day');

			$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('"Created"', '%U') . ' AS test FROM "SiteTree" WHERE "URLSegment" = \'home\'';
			$result = DB::query($query)->value();

			$this->matchesRoughly($result, strtotime(DataObject::get_one('SiteTree',"\"URLSegment\" = 'home'")->Created), 'SiteTree[home]->Created as timestamp');
		}
	}
	
{'fraction_non_alphanumeric': 0.2065347006916289, 'fraction_numerical': 0.021464345337467206, 'mean_word_length': 4.923728813559322, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 63, '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': '780537', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1428, 'n_words': 268}