<commit_before><?php
/**
 * sfDateFormat class file.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the BSD License.
 *
 * Copyright(c) 2004 by <NAME>. All rights reserved.
 *
 * To contact the author write to {@link mailto:<EMAIL> Q<NAME>ue}
 * The latest version of PRADO can be obtained from:
 * {@link http://prado.sourceforge.net/}
 *
 * @author     <NAME> <weizhuo[at]gmail[dot]com>
 * @version    $Id$
 * @package    symfony
 * @subpackage i18n
 */

/**
 * Get the encoding utilities
 */
require_once(dirname(__FILE__).'/util.php');

/**
 * sfDateFormat class.
 * 
 * The sfDateFormat class allows you to format dates and times with 
 * predefined styles in a locale-sensitive manner. Formatting times 
 * with the sfDateFormat class is similar to formatting dates.
 *
 * Formatting dates with the sfDateFormat class is a two-step process. 
 * First, you create a formatter with the getDateInstance method. 
 * Second, you invoke the format method, which returns a string containing 
 * the formatted date. 
 *
 * DateTime values are formatted using standard or custom patterns stored 
 * in the properties of a DateTimeFormatInfo.
 *
 * @author <NAME> <weizhuo[at]gmail[dot]com>
 * @version v1.0, last update on Sat Dec 04 14:10:49 EST 2004
 * @package System.I18N.core
 */
class sfDateFormat
{
  /**
   * A list of tokens and their function call.
   * @var array 
   */
  protected $tokens = array(
    'G'=>'Era',
    'y'=>'year',
    'M'=>'mon',
    'd'=>'mday',
    'h'=>'Hour12',
    'H'=>'hours',
    'm'=>'minutes',
    's'=>'seconds',
    'E'=>'wday',
    'D'=>'yday',
    'F'=>'DayInMonth',
    'w'=>'WeekInYear',
    'W'=>'WeekInMonth',
    'a'=>'AMPM',
    'k'=>'HourInDay',
    'K'=>'HourInAMPM',
    'z'=>'TimeZone'
  );

  /**
   * A list of methods, to be used by the token function calls.
   * @var array 
   */
  protected $methods = array();

  /**
   * The sfDateTimeFormatInfo, containing culture specific patterns and names.
   * @var sfDateTimeFormatInfo   
   */
  protected $formatInfo;

  /**
   * Initialize a new sfDateFormat.
   *
   * @param mixed either, null, a sfCultureInfo instance, a DateTimeFormatInfo instance, or a locale.
   * @return sfDateFormat instance
   */
  function __construct($formatInfo = null)
  {
    if (is_null($formatInfo))
    {
      $this->formatInfo = sfDateTimeFormatInfo::getInvariantInfo();
    }
    else if ($formatInfo instanceof sfCultureInfo)
    {
      $this->formatInfo = $formatInfo->DateTimeFormat;
    }
    else if ($formatInfo instanceof sfDateTimeFormatInfo)
    {
      $this->formatInfo = $formatInfo;
    }
    else
    {
      $this->formatInfo = sfDateTimeFormatInfo::getInstance($formatInfo);
    }

    $this->methods = get_class_methods($this);
  }

  /**
   * Guesses a date without calling strtotime.
   *
   * @author <NAME> <<EMAIL>>
   * @param mixed the time as integer or string in strtotime format.
   * @param string the input pattern; default is sql date or timestamp
   * @return array same array as the getdate function
   */
  public function getDate($time, $pattern = null)
  {
    // if the type is not a php timestamp
    $isString = (string) $time !== (string) (int) $time;

    if ($isString)
    {
      if (!$pattern)
      {
        if (strlen($time) == 10)
        {
          $pattern = 'i';
        }
        else   // otherwise, default:
        {
          $pattern = 'I';
        }
      }

      $pattern = $this->getPattern($pattern);
      $tokens = $this->getTokens($pattern);
      $pregPattern = '';
      $matchNames = array();
      foreach ($tokens as $token)
      {
        if ($matchName = $this->getFunctionName($token))<commit_msg>fixed sfException - Impossible to parse date "" with format "yyyy-MM-dd HH:mm:ss" (closes #1420 - patch from skr68)<commit_after><?php
/**
 * sfDateFormat class file.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the BSD License.
 *
 * Copyright(c) 2004 by <NAME>. All rights reserved.
 *
 * To contact the author write to {@link mailto:<EMAIL> Q<NAME>ue}
 * The latest version of PRADO can be obtained from:
 * {@link http://prado.sourceforge.net/}
 *
 * @author     <NAME> <weizhuo[at]gmail[dot]com>
 * @version    $Id$
 * @package    symfony
 * @subpackage i18n
 */

/**
 * Get the encoding utilities
 */
require_once(dirname(__FILE__).'/util.php');

/**
 * sfDateFormat class.
 * 
 * The sfDateFormat class allows you to format dates and times with 
 * predefined styles in a locale-sensitive manner. Formatting times 
 * with the sfDateFormat class is similar to formatting dates.
 *
 * Formatting dates with the sfDateFormat class is a two-step process. 
 * First, you create a formatter with the getDateInstance method. 
 * Second, you invoke the format method, which returns a string containing 
 * the formatted date. 
 *
 * DateTime values are formatted using standard or custom patterns stored 
 * in the properties of a DateTimeFormatInfo.
 *
 * @author <NAME> <weizhuo[at]gmail[dot]com>
 * @version v1.0, last update on Sat Dec 04 14:10:49 EST 2004
 * @package System.I18N.core
 */
class sfDateFormat
{
  /**
   * A list of tokens and their function call.
   * @var array 
   */
  protected $tokens = array(
    'G'=>'Era',
    'y'=>'year',
    'M'=>'mon',
    'd'=>'mday',
    'h'=>'Hour12',
    'H'=>'hours',
    'm'=>'minutes',
    's'=>'seconds',
    'E'=>'wday',
    'D'=>'yday',
    'F'=>'DayInMonth',
    'w'=>'WeekInYear',
    'W'=>'WeekInMonth',
    'a'=>'AMPM',
    'k'=>'HourInDay',
    'K'=>'HourInAMPM',
    'z'=>'TimeZone'
  );

  /**
   * A list of methods, to be used by the token function calls.
   * @var array 
   */
  protected $methods = array();

  /**
   * The sfDateTimeFormatInfo, containing culture specific patterns and names.
   * @var sfDateTimeFormatInfo   
   */
  protected $formatInfo;

  /**
   * Initialize a new sfDateFormat.
   *
   * @param mixed either, null, a sfCultureInfo instance, a DateTimeFormatInfo instance, or a locale.
   * @return sfDateFormat instance
   */
  function __construct($formatInfo = null)
  {
    if (is_null($formatInfo))
    {
      $this->formatInfo = sfDateTimeFormatInfo::getInvariantInfo();
    }
    else if ($formatInfo instanceof sfCultureInfo)
    {
      $this->formatInfo = $formatInfo->DateTimeFormat;
    }
    else if ($formatInfo instanceof sfDateTimeFormatInfo)
    {
      $this->formatInfo = $formatInfo;
    }
    else
    {
      $this->formatInfo = sfDateTimeFormatInfo::getInstance($formatInfo);
    }

    $this->methods = get_class_methods($this);
  }

  /**
   * Guesses a date without calling strtotime.
   *
   * @author <NAME> <<EMAIL>>
   * @param mixed the time as integer or string in strtotime format.
   * @param string the input pattern; default is sql date or timestamp
   * @return array same array as the getdate function
   */
  public function getDate($time, $pattern = null)
  {
    if (is_null($time))
    {
      return null;
    }

    // if the type is not a php timestamp
    $isString = (string) $time !== (string) (int) $time;

    if ($isString)
    {
      if (!$pattern)
      {
        if (strlen($time) == 10)
        {
          $pattern = 'i';
        }
        else   // otherwise, default:
        {
          $pattern = 'I';
        }
      }

      $pattern = $this->getPattern($pattern);
      $tokens = $this->getTokens($pattern);
      $pregPattern = '';
      $matchNames = array();
      foreach ($tokens as $token)
      {
        if ($matchName = $this->getFunctionName($token))
{'fraction_non_alphanumeric': 0.13501053740779767, 'fraction_numerical': 0.007639620653319284, 'mean_word_length': 2.8174962292609353, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 75, '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': '3494246', 'n_tokens_mistral': 2420, 'n_tokens_neox': 2350, 'n_words': 721}