<commit_before><?php
namespace WebBook\Utility;

/**
 * Handles all of the time and date functions.
 *
 * @copyright 2012 <NAME> <<EMAIL>>
 * @author    <NAME> <<EMAIL>>
 *
 * @todo This should use PHP's DateTime.
 */
class Date
{
	/**
	 * Return a date string from a timestamp
	 *
	 * @access public
	 * @param  int    $timestamp The UNIX timestamp.
	 * @param  string $dateRep   How we want the date represented.
	 * @return string
	 * @static
	 */
	public static function getDate($timestamp, $dateRep = 'jS F Y') {
		// Has the user even entered a timestamp?
		if ($timestamp == '' || $timestamp == 0) {
			return '&mdash;';
		}

		// Is the date representation a custom format?
		else if ($dateRep != 'jS F Y') {
			return date($dateRep, $timestamp);
		}

		// Is the timestamp a time today?
		else if (date('j/n/Y', $timestamp) == date('j/n/Y', time())) {
			return 'Today, ' . date('g:ia', $timestamp);
		}

		// Is the timestamp from yesterday?
		else if (date('j/n/Y', $timestamp) == date('j/n/Y', time() - 86400)) {
			return 'Yesterday';
		}

		// Just return the default timestamp
		return date($dateRep, $timestamp);
	}

	/**
	 * Return the hours/minutes between two timestamps.
	 *
	 * @access public
	 * @param  int    $timestampStart
	 * @param  int    $timestampEnd
	 * @return string
	 * @static
	 */
	public static function getDifference($timestampStart, $timestampEnd) {
		// First, is the late date later than the early date?
		if ($timestampStart > $timestampEnd) {
			return 'In the future..';
		}

		// Work out the difference
		$difference = $timestampEnd - $timestampStart;

		// Is this more than one day?
		if ($difference >= 86400) {
			// We are dealing with at least 1 day ago
			$days = $difference / 86400;

			// Work out the seconds
			$week = 86400 * 7;
			$month = $week * 4;
			$year = $week * 52;

			// More than a year?
			if ($difference > $year) {
				// How many years
				$period = floor($difference / $year);
				return $period . ($period >= 2 ? ' years' : ' year');
			}

			// More than a month?
			if ($difference > $month) {
				// How many months
				$period = floor($difference / $month);
				return $period . ($period >= 2 ? ' months' : ' month');
			}

			// More than a week?
			if ($difference > $week) {
				// How many months
				$period = floor($difference / $week);
				return $period . ($period >= 2 ? ' weeks' : ' week');
			}

			// How many days?
			$period = floor($difference / $week);
			return date('l, g:ia', $period);
		}

		// We are dealing with something within the past 24 hours
		// Within the past minute?
		if ($difference < 60) {
			return $difference . ($difference >= 2 ? ' seconds' : ' second');
		}

		// Within the past hour?
		if ($difference < 3600) {
			// How many minutes
			$period = floor($difference / 60);
			return $period . ($period >= 2 ? ' minutes' : ' minute');
		}

		// More than an hour ago
		$period = floor($difference / 3600);
		return $period . ($period >= 2 ? ' hours' : ' hours');
	}
}<commit_msg>Improvements to the Date class logic.<commit_after><?php
namespace WebBook\Utility;
use Core;

/**
 * Handles all of the time and date functions.
 *
 * @copyright 2012 <NAME> <<EMAIL>>
 * @author    <NAME> <<EMAIL>>
 */
class Date
{
	/**
	 * Return a date string from a timestamp.
	 *
	 * @access public
	 * @param  int    $timestamp The Unix timestamp.
	 * @param  string $dateRep   How we want the date represented.
	 * @return string
	 * @static
	 */
	public static function getDate($timestamp, $dateRep = 'jS F Y') {
		// Has the user even entered a timestamp?
		if (empty($timestamp)) {
			return '&mdash;';
		}

		// Create the DateTime object for some further manipulations
		$date = new \DateTime();
		$date->setTimestamp($timestamp);
		return $date->format($dateRep);
	}

	/**
	 * Return the difference between two timestamps.
	 *
	 * @access public
	 * @param  int    $timestampStart
	 * @param  int    $timestampEnd
	 * @return string
	 * @static
	 */
	public static function getDifference($timestampStart, $timestampEnd) {
		// Start and end dates
		$start = new \DateTime();
		$start->setTimestamp($timestampStart);

		$end = new \DateTime();
		$end->setTimestamp($timestampEnd);

		// Working out the differents
		$diff    = $start->diff($end);
		$years   = $diff->format('%y');
		$months  = $diff->format('%m');
		$days    = $diff->format('%d');
		$hours   = $diff->format('%G');
		$minutes = $diff->format('%i');
		$seconds = $diff->format('%s');

		// And return
		if ($years > 0) {
			return $years   . ' year'   . ($years   > 1 ? 's' : '') . ' ago';
		} else if ($months  > 0) {
			return $years   . ' month'  . ($months  > 1 ? 's' : '') . ' ago';
		} else if ($days    > 0) {
			return $days    . ' day'    . ($days    > 1 ? 's' : '') . ' ago';
		} else if ($hours   > 0) {
			return $hours   . ' hour'   . ($hours   > 1 ? 's' : '') . ' ago';
		} else if ($minutes > 0) {
			return $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ago';
		} else if ($seconds > 0) {
			return $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ago';
		}

		return 'just now';
	}
}
{'fraction_non_alphanumeric': 0.16951483009231977, 'fraction_numerical': 0.01296405421331762, 'mean_word_length': 2.642346208869814, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 49, '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': '1544369', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1636, 'n_words': 540}