本文整理汇总了PHP中Zend_Locale_Format::getDateFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Format::getDateFormat方法的具体用法?PHP Zend_Locale_Format::getDateFormat怎么用?PHP Zend_Locale_Format::getDateFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale_Format
的用法示例。
在下文中一共展示了Zend_Locale_Format::getDateFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getForm
protected function getForm()
{
// Create object Snep_Form
$form = new Snep_Form();
// Set form action
$form->setAction($this->getFrontController()->getBaseUrl() . '/services-report/index');
$form_xml = new Zend_Config_Xml('./modules/default/forms/services_report.xml');
$config = Zend_Registry::get('config');
$period = new Snep_Form_SubForm($this->view->translate("Period"), $form_xml->period);
$validatorDate = new Zend_Validate_Date(Zend_Locale_Format::getDateFormat(Zend_Registry::get('Zend_Locale')));
$locale = Snep_Locale::getInstance()->getLocale();
$now = Zend_Date::now();
if ($locale == 'en_US') {
$now = $now->toString('YYYY-MM-dd HH:mm');
} else {
$now = $now->toString('dd/MM/YYYY HH:mm');
}
$yesterday = Zend_Date::now()->subDate(1);
$initDay = $period->getElement('init_day');
$initDay->setValue($now);
//$initDay->addValidator($validatorDate);
$tillDay = $period->getElement('till_day');
$tillDay->setValue($now);
//$tillDay->addValidator($validatorDate);
$form->addSubForm($period, "period");
$exten = new Snep_Form_SubForm($this->view->translate("Extensions"), $form_xml->exten);
$groupLib = new Snep_GruposRamais();
$groupsTmp = $groupLib->getAll();
$groupsData = array();
foreach ($groupsTmp as $key => $group) {
switch ($group['name']) {
case 'administrator':
$groupsData[$this->view->translate('Administrators')] = $group['name'];
break;
case 'users':
$groupsData[$this->view->translate('Users')] = $group['name'];
break;
case 'all':
$groupsData[$this->view->translate('All')] = $group['name'];
break;
default:
$groupsData[$group['name']] = $group['name'];
}
}
$selectGroup = $exten->getElement('group_select');
$selectGroup->addMultiOption(null, '----');
foreach ($groupsData as $key => $value) {
$selectGroup->addMultiOption($value, $key);
}
$selectGroup->setAttrib('onSelect', "enableField('exten-group_select', 'exten-exten_select');");
$form->addSubForm($exten, "exten");
$service = new Snep_Form_SubForm($this->view->translate("Services"), $form_xml->service);
$form->addSubForm($service, "service");
$form->getElement('submit')->setLabel($this->view->translate("Show Report"));
$form->removeElement("cancel");
return $form;
}
示例2: getDateFormat
public function getDateFormat()
{
if (!$this->_dateFormat) {
if ($locale = $this->getLocale()) {
$this->setDateFormat(\Zend_Locale_Format::getDateFormat($locale));
} else {
$this->setDateFormat(\Zend_Date::DATE_SHORT);
}
}
return $this->_dateFormat;
}
示例3: _addHeader
/**
* add header
*/
protected function _addHeader()
{
$patterns = array('/\\{date\\}/', '/\\{user\\}/');
$replacements = array(Zend_Date::now()->toString(Zend_Locale_Format::getDateFormat($this->_locale), $this->_locale), Tinebase_Core::getUser()->accountDisplayName);
$this->_currentRowIndex = 1;
$columnId = 0;
if ($this->_config->headers) {
foreach ($this->_config->headers->header as $headerCell) {
// replace data
$value = preg_replace($patterns, $replacements, $headerCell);
$this->_excelObject->getActiveSheet()->setCellValueByColumnAndRow(0, $this->_currentRowIndex, $value);
$this->_currentRowIndex++;
}
$this->_currentRowIndex++;
}
if (isset($this->_config->header) && $this->_config->header) {
$this->_addHead();
}
}
示例4: indexAction
public function indexAction()
{
// Title
$this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Reports"), $this->view->translate("Call Ranking")));
$config = Zend_Registry::get('config');
$form = $this->getForm();
if ($this->_request->getPost()) {
$formIsValid = $form->isValid($_POST);
$formData = $this->_request->getParams();
$locale = Snep_Locale::getInstance()->getLocale();
if ($locale == 'en_US') {
$format = 'yyyy-MM-dd';
} else {
$format = Zend_Locale_Format::getDateFormat($locale);
}
$ini_date = explode(" ", $formData['period']['init_day']);
$final_date = explode(" ", $formData['period']['till_day']);
$ini_date_valid = Zend_Date::isDate($ini_date[0], $format);
$final_date_valid = Zend_Date::isDate($final_date[0], $format);
if (!$ini_date_valid) {
$iniDateElem = $form->getSubForm('period')->getElement('init_day');
$iniDateElem->addError($this->view->translate('Invalid Date'));
$formIsValid = false;
}
if (!$final_date_valid) {
$finalDateElem = $form->getSubForm('period')->getElement('till_day');
$finalDateElem->addError($this->view->translate('Invalid Date'));
$formIsValid = false;
}
$reportType = $formData['rank']['out_type'];
if ($formIsValid) {
if ($reportType == 'csv') {
$this->csvAction();
} else {
$this->viewAction();
}
}
}
$this->view->form = $form;
}
示例5: resolveZendLocaleToDatePickerFormat
/**
* A Check for Zend_Locale existance has already been done in {@link datePicker()}
* this function only resolves the default format from Zend Locale to
* a jQuery Date Picker readable format. This function can be potentially buggy
* because of its easy nature and is therefore stripped from the core functionality
* to be easily overriden.
*
* @return string
*/
public static function resolveZendLocaleToDatePickerFormat($format = null)
{
if ($format == null) {
$locale = Zend_Registry::get('Zend_Locale');
if (!$locale instanceof Zend_Locale) {
require_once "ZendX/JQuery/Exception.php";
throw new ZendX_JQuery_Exception("Cannot resolve Zend Locale format by default, no application wide locale is set.");
}
/**
* @see Zend_Locale_Format
*/
require_once "Zend/Locale/Format.php";
$format = Zend_Locale_Format::getDateFormat($locale);
}
$dateFormat = array('EEEEE' => 'D', 'EEEE' => 'DD', 'EEE' => 'D', 'EE' => 'D', 'E' => 'D', 'MMMM' => 'MM', 'MMM' => 'M', 'MM' => 'mm', 'M' => 'm', 'YYYYY' => 'yy', 'YYYY' => 'yy', 'YYY' => 'yy', 'YY' => 'y', 'Y' => 'yy', 'yyyyy' => 'yy', 'yyyy' => 'yy', 'yyy' => 'yy', 'yy' => 'y', 'y' => 'yy', 'G' => '', 'e' => '', 'a' => '', 'h' => '', 'H' => '', 'm' => '', 's' => '', 'S' => '', 'z' => '', 'Z' => '', 'A' => '');
$newFormat = "";
$isText = false;
$i = 0;
while ($i < strlen($format)) {
$chr = $format[$i];
if ($chr == '"' || $chr == "'") {
$isText = !$isText;
}
$replaced = false;
if ($isText == false) {
foreach ($dateFormat as $zl => $jql) {
if (substr($format, $i, strlen($zl)) == $zl) {
$chr = $jql;
$i += strlen($zl);
$replaced = true;
}
}
}
if ($replaced == false) {
$i++;
}
$newFormat .= $chr;
}
return $newFormat;
}
示例6: indexAction
public function indexAction()
{
$this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Reports"), $this->view->translate("Calls")));
$config = Zend_Registry::get('config');
include $config->system->path->base . "/inspectors/Permissions.php";
$test = new Permissions();
$response = $test->getTests();
$form = $this->getForm();
if ($this->_request->getPost()) {
$formIsValid = $form->isValid($_POST);
$locale = Snep_Locale::getInstance()->getLocale();
if ($locale == 'en_US') {
$format = 'yyyy-MM-dd';
} else {
$format = Zend_Locale_Format::getDateFormat($locale);
}
$ini_date = explode(" ", $_POST['period']['initDay']);
$final_date = explode(" ", $_POST['period']['finalDay']);
$ini_date_valid = Zend_Date::isDate($ini_date[0], $format);
$final_date_valid = Zend_Date::isDate($final_date[0], $format);
if (!$ini_date_valid) {
$iniDateElem = $form->getSubForm('period')->getElement('initDay');
$iniDateElem->addError($this->view->translate('Invalid Date'));
$formIsValid = false;
}
if (!$final_date_valid) {
$finalDateElem = $form->getSubForm('period')->getElement('finalDay');
$finalDateElem->addError($this->view->translate('Invalid Date'));
$formIsValid = false;
}
if ($formIsValid) {
$this->createAction();
}
}
$this->view->form = $form;
}
示例7: install_locale
/**
* Set/Install the given locale.
* This does set the i18n locale as well as the Translatable or Fluent locale (if any of these modules is installed)
* @param string $locale the locale to install
* @throws Zend_Locale_Exception @see Zend_Locale_Format::getDateFormat and @see Zend_Locale_Format::getTimeFormat
*/
public static function install_locale($locale)
{
// If the locale isn't given, silently fail (there might be carts that still have locale set to null)
if (empty($locale)) {
return;
}
if (class_exists('Translatable')) {
Translatable::set_current_locale($locale);
} else {
if (class_exists('Fluent')) {
Fluent::set_persist_locale($locale);
}
}
// Do something like Fluent does to install the locale
i18n::set_locale($locale);
// LC_NUMERIC causes SQL errors for some locales (comma as decimal indicator) so skip
foreach (array(LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_TIME) as $category) {
setlocale($category, "{$locale}.UTF-8", $locale);
}
// Get date/time formats from Zend
require_once 'Zend/Date.php';
i18n::config()->date_format = Zend_Locale_Format::getDateFormat($locale);
i18n::config()->time_format = Zend_Locale_Format::getTimeFormat($locale);
}
示例8: isDate
/**
* Checks if the given date is a real date or datepart.
* Returns false is a expected datepart is missing or a datepart exceeds its possible border.
* But the check will only be done for the expected dateparts which are given by format.
* If no format is given the standard dateformat for the actual locale is used.
* f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY'
*
* @param string $date Date to parse for correctness
* @param string $format OPTIONAL Format for parsing the date string
* @param string|Zend_Locale $locale OPTIONAL Locale for parsing date parts
* @return boolean True when all date parts are correct
*/
public static function isDate($date, $format = null, $locale = null)
{
if (Zend_Locale::isLocale($format)) {
$locale = $format;
$format = null;
}
if ($locale === null) {
$locale = new Zend_Locale();
$locale = $locale->toString();
}
if ($format === null) {
$format = Zend_Locale_Format::getDateFormat($locale);
} else {
if (self::$_Options['format_type'] == 'php') {
$format = Zend_Locale_Format::convertPhpToIsoFormat($format);
}
}
try {
$parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'date_format' => $format, 'format_type' => 'iso', 'fix_date' => false));
} catch (Zend_Locale_Exception $e) {
// date can not be parsed
return false;
}
if ((strpos($format, 'Y') !== false or strpos($format, 'y') !== false) and !isset($parsed['year'])) {
// year expected but not found
return false;
}
if (strpos($format, 'M') !== false and !isset($parsed['month'])) {
// month expected but not found
return false;
}
if (strpos($format, 'd') !== false and !isset($parsed['day'])) {
// day expected but not found
return false;
}
if ((strpos($format, 'H') !== false or strpos($format, 'h') !== false) and !isset($parsed['hour'])) {
// hour expected but not found
return false;
}
if (strpos($format, 'm') !== false and !isset($parsed['minute'])) {
// minute expected but not found
return false;
}
if (strpos($format, 's') !== false and !isset($parsed['second'])) {
// second expected but not found
return false;
}
// set not given dateparts
if (!isset($parsed['hour'])) {
$parsed['hour'] = 0;
}
if (!isset($parsed['minute'])) {
$parsed['minute'] = 0;
}
if (!isset($parsed['second'])) {
$parsed['second'] = 0;
}
if (!isset($parsed['month'])) {
$parsed['month'] = 1;
}
if (!isset($parsed['day'])) {
$parsed['day'] = 1;
}
if (!isset($parsed['year'])) {
$parsed['year'] = 1970;
}
$date = new self($locale);
$timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']);
if ($parsed['year'] != $date->date('Y', $timestamp)) {
// given year differs from parsed year
return false;
}
if ($parsed['month'] != $date->date('n', $timestamp)) {
// given month differs from parsed month
return false;
}
if ($parsed['day'] != $date->date('j', $timestamp)) {
// given day differs from parsed day
return false;
}
if ($parsed['hour'] != $date->date('G', $timestamp)) {
// given hour differs from parsed hour
return false;
}
if ($parsed['minute'] != $date->date('i', $timestamp)) {
// given minute differs from parsed minute
return false;
}
//.........这里部分代码省略.........
示例9: install_locale
/**
* Installs the current locale into i18n
*
* @param boolean $persist Attempt to persist any detected locale within session / cookies
*/
public static function install_locale($persist = true)
{
// Ensure the locale is set correctly given the designated parameters
$locale = self::current_locale($persist);
if (empty($locale)) {
return;
}
i18n::set_locale($locale);
// LC_NUMERIC causes SQL errors for some locales (comma as decimal indicator) so skip
foreach (array(LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_TIME) as $category) {
setlocale($category, "{$locale}.UTF-8", $locale);
}
// Get date/time formats from Zend
require_once 'Zend/Date.php';
i18n::config()->date_format = Zend_Locale_Format::getDateFormat($locale);
i18n::config()->time_format = Zend_Locale_Format::getTimeFormat($locale);
}
示例10: testSetOption
/**
* test setOption
* expected boolean
*/
public function testSetOption()
{
$this->assertEquals(7, count(Zend_Locale_Format::setOptions(array('format_type' => 'php'))));
$this->assertTrue(is_array(Zend_Locale_Format::setOptions()));
try {
$this->assertTrue(Zend_Locale_Format::setOptions(array('format_type' => 'xxx')));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$this->assertTrue(Zend_Locale_Format::setOptions(array('myformat' => 'xxx')));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$format = Zend_Locale_Format::setOptions(array('locale' => 'de', 'number_format' => Zend_Locale_Format::STANDARD));
$test = Zend_Locale_Data::getContent('de', 'decimalnumberformat');
$this->assertEquals($test['default'], $format['number_format']);
try {
$this->assertFalse(Zend_Locale_Format::setOptions(array('number_format' => array('x' => 'x'))));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$format = Zend_Locale_Format::setOptions(array('locale' => 'de', 'date_format' => Zend_Locale_Format::STANDARD));
$test = Zend_Locale_Format::getDateFormat('de');
$this->assertEquals($test, $format['date_format']);
try {
$this->assertFalse(Zend_Locale_Format::setOptions(array('date_format' => array('x' => 'x'))));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('fix_date' => 'no'))));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$format = Zend_Locale_Format::setOptions(array('locale' => Zend_Locale_Format::STANDARD));
$locale = new Zend_Locale();
$this->assertEquals($locale, $format['locale']);
try {
$this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('locale' => 'nolocale'))));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('precision' => 50))));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
// test interaction between class-wide default date format and using locale's default format
try {
$result = array('date_format' => 'MMM d, yyyy', 'locale' => 'en_US', 'month' => '07',
'day' => '4', 'year' => '2007');
Zend_Locale_Format::setOptions(array('format_type' => 'iso', 'date_format' => 'MMM d, yyyy', 'locale' => 'en_US')); // test setUp
} catch (Zend_Locale_Exception $e) {
$this->fail("exception expected");
}
try {
// uses global date_format with global locale
$this->assertSame($result, Zend_Locale_Format::getDate('July 4, 2007'));
} catch (Zend_Locale_Exception $e) {
$this->fail("exception expected");
}
try {
// uses global date_format with given locale
$this->assertSame($result, Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US')));
} catch (Zend_Locale_Exception $e) {
$this->fail("exception expected");
}
try {
// sets a new global date format
Zend_Locale_Format::setOptions(array('date_format' => 'M-d-y'));
} catch (Zend_Locale_Exception $e) {
$this->fail("exception expected");
}
try {
// uses global date format with given locale
// but this date format differs from the original set... (MMMM d, yyyy != M-d-y)
$expected = Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US'));
$this->assertSame($expected['year'], $result['year'] );
$this->assertSame($expected['month'], $result['month']);
$this->assertSame($expected['day'], $result['day'] );
} catch (Zend_Locale_Exception $e) {
//.........这里部分代码省略.........
示例11: resolveZendLocaleToDateFormat
/**
* This function only resolves the default format from Zend Locale to appropriate format
* defined via $dateFormat array mapper.
*
* @param array $dateFormat array for mapping Zend Local to new format.
* @param string|null $format Date format. If not set, it will used format date defined in Zend Local.
* @return new format
*/
public static function resolveZendLocaleToDateFormat(array $dateFormat, $format = null)
{
if ($format == null) {
$locale = Zend_Registry::get('Zend_Locale');
if (!$locale instanceof Zend_Locale) {
require_once 'Zend/Locale/Exception.php';
throw new Zend_Locale_Exception("Cannot resolve Zend Locale format by default, no application wide locale is set.");
}
/**
* @see Zend_Locale_Format
*/
require_once "Zend/Locale/Format.php";
$format = Zend_Locale_Format::getDateFormat($locale);
}
$newFormat = "";
$isText = false;
$i = 0;
while ($i < strlen($format)) {
$chr = $format[$i];
if ($chr == '"' || $chr == "'") {
$isText = !$isText;
}
$replaced = false;
if ($isText == false) {
foreach ($dateFormat as $zl => $jql) {
if (substr($format, $i, strlen($zl)) == $zl) {
$chr = $jql;
$i += strlen($zl);
$replaced = true;
}
}
}
if ($replaced == false) {
$i++;
}
$newFormat .= $chr;
}
return $newFormat;
}
示例12: getCMSFields
/**
* Return a {@link FieldSet} of fields that would appropriate for editing
* this member.
*
* @return FieldSet Return a FieldSet of fields that would appropriate for
* editing this member.
*/
public function getCMSFields()
{
require_once 'Zend/Date.php';
$fields = parent::getCMSFields();
$mainFields = $fields->fieldByName("Root")->fieldByName("Main")->Children;
$password = new ConfirmedPasswordField('Password', null, null, null, true);
$password->setCanBeEmpty(true);
if (!$this->ID) {
$password->showOnClick = false;
}
$mainFields->replaceField('Password', $password);
$mainFields->insertBefore(new HeaderField('MemberDetailsHeader', _t('Member.PERSONALDETAILS', "Personal Details", PR_MEDIUM, 'Headline for formfields')), 'FirstName');
$mainFields->insertBefore(new HeaderField('MemberUserDetailsHeader', _t('Member.USERDETAILS', "User Details", PR_MEDIUM, 'Headline for formfields')), 'Email');
$mainFields->replaceField('Locale', new DropdownField("Locale", _t('Member.INTERFACELANG', "Interface Language", PR_MEDIUM, 'Language of the CMS'), i18n::get_existing_translations()));
$mainFields->removeByName('Bounced');
$mainFields->removeByName('RememberLoginToken');
$mainFields->removeByName('AutoLoginHash');
$mainFields->removeByName('AutoLoginExpired');
$mainFields->removeByName('PasswordEncryption');
$mainFields->removeByName('PasswordExpiry');
$mainFields->removeByName('LockedOutUntil');
if (!self::$lock_out_after_incorrect_logins) {
$mainFields->removeByName('FailedLoginCount');
}
$mainFields->removeByName('Salt');
$mainFields->removeByName('NumVisit');
$mainFields->removeByName('LastVisited');
$fields->removeByName('Subscriptions');
// Groups relation will get us into logical conflicts because
// Members are displayed within group edit form in SecurityAdmin
$fields->removeByName('Groups');
if (Permission::check('EDIT_PERMISSIONS')) {
$groupsField = new TreeMultiselectField('Groups', false, 'Group');
$fields->findOrMakeTab('Root.Groups', singleton('Group')->i18n_plural_name());
$fields->addFieldToTab('Root.Groups', $groupsField);
// Add permission field (readonly to avoid complicated group assignment logic).
// This should only be available for existing records, as new records start
// with no permissions until they have a group assignment anyway.
if ($this->ID) {
$permissionsField = new PermissionCheckboxSetField_Readonly('Permissions', singleton('Permission')->i18n_plural_name(), 'Permission', 'GroupID', $this->getManyManyComponents('Groups'));
$fields->findOrMakeTab('Root.Permissions', singleton('Permission')->i18n_plural_name());
$fields->addFieldToTab('Root.Permissions', $permissionsField);
}
}
$defaultDateFormat = Zend_Locale_Format::getDateFormat($this->Locale);
$dateFormatMap = array('MMM d, yyyy' => Zend_Date::now()->toString('MMM d, yyyy'), 'yyyy/MM/dd' => Zend_Date::now()->toString('yyyy/MM/dd'), 'MM/dd/yyyy' => Zend_Date::now()->toString('MM/dd/yyyy'), 'dd/MM/yyyy' => Zend_Date::now()->toString('dd/MM/yyyy'));
$dateFormatMap[$defaultDateFormat] = Zend_Date::now()->toString($defaultDateFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
$mainFields->push($dateFormatField = new Member_DatetimeOptionsetField('DateFormat', $this->fieldLabel('DateFormat'), $dateFormatMap));
$dateFormatField->setValue($this->DateFormat);
$defaultTimeFormat = Zend_Locale_Format::getTimeFormat($this->Locale);
$timeFormatMap = array('h:mm a' => Zend_Date::now()->toString('h:mm a'), 'H:mm' => Zend_Date::now()->toString('H:mm'));
$timeFormatMap[$defaultTimeFormat] = Zend_Date::now()->toString($defaultTimeFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
$mainFields->push($timeFormatField = new Member_DatetimeOptionsetField('TimeFormat', $this->fieldLabel('TimeFormat'), $timeFormatMap));
$timeFormatField->setValue($this->TimeFormat);
$this->extend('updateCMSFields', $fields);
return $fields;
}
示例13: isDate
/**
* Checks if the given date is a real date or datepart.
* Returns false if a expected datepart is missing or a datepart exceeds its possible border.
* But the check will only be done for the expected dateparts which are given by format.
* If no format is given the standard dateformat for the actual locale is used.
* f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY'
*
* @param string $date Date to parse for correctness
* @param string $format (Optional) Format for parsing the date string
* @param string|Zend_Locale $locale (Optional) Locale for parsing date parts
* @return boolean True when all date parts are correct
*/
public static function isDate($date, $format = null, $locale = null)
{
if (!is_string($date) and !is_numeric($date) and !$date instanceof Zend_Date) {
return false;
}
if ($format !== null and Zend_Locale::isLocale($format, null, false)) {
$locale = $format;
$format = null;
}
if (empty($locale)) {
require_once 'Zend/Registry.php';
if (Zend_Registry::isRegistered('Zend_Locale') === true) {
$locale = Zend_Registry::get('Zend_Locale');
}
}
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, false, false)) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("Given locale ({$locale}) does not exist", (string) $locale);
}
$locale = new Zend_Locale($locale);
}
$locale = (string) $locale;
if ($format === null) {
$format = Zend_Locale_Format::getDateFormat($locale);
} else {
if (self::$_options['format_type'] == 'php') {
$format = Zend_Locale_Format::convertPhpToIsoFormat($format);
}
}
try {
$parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'date_format' => $format, 'format_type' => 'iso', 'fix_date' => false));
if (isset($parsed['year']) and (strpos(strtoupper($format), 'YY') !== false and strpos(strtoupper($format), 'YYYY') === false)) {
$parsed['year'] = self::getFullYear($parsed['year']);
}
} catch (Zend_Locale_Exception $e) {
// Date can not be parsed
return false;
}
if ((strpos($format, 'Y') !== false or strpos($format, 'y') !== false) and !isset($parsed['year'])) {
// Year expected but not found
return false;
}
if (strpos($format, 'M') !== false and !isset($parsed['month'])) {
// Month expected but not found
return false;
}
if (strpos($format, 'd') !== false and !isset($parsed['day'])) {
// Day expected but not found
return false;
}
if ((strpos($format, 'H') !== false or strpos($format, 'h') !== false) and !isset($parsed['hour'])) {
// Hour expected but not found
return false;
}
if (strpos($format, 'm') !== false and !isset($parsed['minute'])) {
// Minute expected but not found
return false;
}
if (strpos($format, 's') !== false and !isset($parsed['second'])) {
// Second expected but not found
return false;
}
// Set not given dateparts
if (isset($parsed['hour']) === false) {
$parsed['hour'] = 0;
}
if (isset($parsed['minute']) === false) {
$parsed['minute'] = 0;
}
if (isset($parsed['second']) === false) {
$parsed['second'] = 0;
}
if (isset($parsed['month']) === false) {
$parsed['month'] = 1;
}
if (isset($parsed['day']) === false) {
$parsed['day'] = 1;
}
if (isset($parsed['year']) === false) {
$parsed['year'] = 1970;
}
$date = new self($parsed, null, $locale);
$timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']);
if ($parsed['year'] != $date->date('Y', $timestamp)) {
// Given year differs from parsed year
return false;
}
//.........这里部分代码省略.........
示例14: splitDateTimeFormat
/**
* This function splits a date time format into a date, separator and time part; the last two
* only when there are time parts in the format.
*
* The results are formats readable by the jQuery Date/Time Picker.
*
* No date formats are allowed after the start of the time parts. (A future extension
* might be to allow either option, but datetimepicker does not understand that.)
*
* Some examples:
* - "yyyy-MM-dd HH:mm" => array("yy-mm-dd", " ", "hh:mm")
* - "X yyyy-MM-dd X" => array("X yy-mm-dd X", false, false)
* - "yy \"hi': mm\" MM" => array("y 'hi'': mm' mm", false, false)
* - "yyyy-MM-dd 'date: yyyy-MM-dd' HH:mm 'time'': hh:mm' HH:mm Q", => array("yy-mm-dd", " 'date: yyyy-MM-dd' ", "HH:mm 'time'': HH:mm' z Q")
* - "HH:mm:ss" => array(false, false, "HH:mm:ss")
* - \Zend_Date::ISO_8601 => array("ISO_8601", "T", "HH:mm:ssZ")
*
* @param string $format Or \Zend_Locale_Format::getDateFormat($locale)
* @return array dateFormat, seperator, timeFormat
*/
public static function splitDateTimeFormat($format = null)
{
if ($format == null) {
$locale = \Zend_Registry::get('Zend_Locale');
if (!$locale instanceof \Zend_Locale) {
throw new \ZendX_JQuery_Exception("Cannot resolve Zend Locale format by default, no application wide locale is set.");
}
/**
* @see \Zend_Locale_Format
*/
$format = \Zend_Locale_Format::getDateFormat($locale);
}
$fullDates = array(\Zend_Date::ATOM => array('ATOM', 'T', 'HH:mm:ssZ'), \Zend_Date::COOKIE => array('COOKIE', ' ', 'HH:mm:ss z'), \Zend_Date::ISO_8601 => array('ISO_8601', 'T', 'HH:mm:ssZ'), \Zend_Date::RFC_822 => array('RFC_822', ' ', 'HH:mm:ss Z'), \Zend_Date::RFC_850 => array('RFC_850', ' ', 'HH:mm:ss z'), \Zend_Date::RFC_1036 => array('RFC_1036', ' ', 'HH:mm:ss Z'), \Zend_Date::RFC_1123 => array('RFC_1123', ' ', 'HH:mm:ss z'), \Zend_Date::RFC_2822 => array('RFC_2822', ' ', 'HH:mm:ss Z'), \Zend_Date::RFC_3339 => array('yy-mm-dd', 'T', 'HH:mm:ssZ'), \Zend_Date::RSS => array('RSS', ' ', 'HH:mm:ss Z'), \Zend_Date::W3C => array('W3C', 'T', 'HH:mm:ssZ'));
if (isset($fullDates[$format])) {
return $fullDates[$format];
}
$dateFormats = array('EEEEE' => 'D', 'EEEE' => 'DD', 'EEE' => 'D', 'EE' => 'D', 'E' => 'D', 'YYYYY' => 'yy', 'YYYY' => 'yy', 'YYY' => 'yy', 'YY' => 'y', 'Y' => 'yy', 'yyyyy' => 'yy', 'yyyy' => 'yy', 'yyy' => 'yy', 'yy' => 'y', 'y' => 'yy', 'MMMM' => 'MM', 'MMM' => 'M', 'MM' => 'mm', 'M' => 'm', 'dd' => 'dd', 'd' => 'd', 'DDD' => 'oo', 'DD' => 'o', 'D' => 'o', 'G' => '', 'e' => '', 'w' => '');
$timeFormats = array('a' => 'tt', 'hh' => 'hh', 'h' => 'h', 'HH' => 'HH', 'H' => 'H', 'mm' => 'mm', 'm' => 'm', 'ss' => 'ss', 's' => 's', 'S' => 'l', 'zzzz' => 'z', 'zzz' => 'z', 'zz' => 'z', 'z' => 'z', 'ZZZZ' => 'Z', 'ZZZ' => 'Z', 'ZZ' => 'Z', 'Z' => 'Z', 'A' => '');
$pregs[] = '"[^"]*"';
// Literal text
$pregs[] = "'[^']*'";
// Literal text
$pregs = array_merge($pregs, array_keys($dateFormats), array_keys($timeFormats));
// Add key words
$preg = sprintf('/(%s)/', implode('|', $pregs));
$parts = preg_split($preg, $format, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
$cache = '';
$dateFormat = false;
$separator = false;
$timeFormat = false;
foreach ($parts as $part) {
if (isset($dateFormats[$part])) {
if (false !== $timeFormat) {
throw new \Zend_Form_Element_Exception(sprintf('Date format specifier %s not allowed after time specifier in %s in format mask %s.', $part, $timeFormat, $format));
}
$dateFormat .= $cache . $dateFormats[$part];
$cache = '';
} elseif (isset($timeFormats[$part])) {
// Switching to time format mode
if (false === $timeFormat) {
if ($dateFormat) {
$separator = $cache;
$timeFormat = $timeFormats[$part];
} else {
$timeFormat = $cache . $timeFormats[$part];
}
} else {
$timeFormat .= $cache . $timeFormats[$part];
}
$cache = '';
} elseif ('"' === $part[0]) {
// Replace double quotes with single quotes, single quotes in string with two single quotes
$cache .= strtr($part, array('"' => "'", "'" => "''"));
} else {
$cache .= $part;
}
}
if ($cache) {
if (false === $timeFormat) {
$dateFormat .= $cache;
} else {
$timeFormat .= $cache;
}
}
// \MUtil_Echo::track($preg);
return array($dateFormat, $separator, $timeFormat);
}
示例15: getCMSFields
/**
* Return a {@link FieldList} of fields that would appropriate for editing
* this member.
*
* @return FieldList Return a FieldList of fields that would appropriate for
* editing this member.
*/
public function getCMSFields()
{
require_once 'Zend/Date.php';
$self = $this;
$this->beforeUpdateCMSFields(function ($fields) use($self) {
$mainFields = $fields->fieldByName("Root")->fieldByName("Main")->Children;
$password = new ConfirmedPasswordField('Password', null, null, null, true);
$password->setCanBeEmpty(true);
if (!$self->ID) {
$password->showOnClick = false;
}
$mainFields->replaceField('Password', $password);
$mainFields->replaceField('Locale', new DropdownField("Locale", _t('Member.INTERFACELANG', "Interface Language", 'Language of the CMS'), i18n::get_existing_translations()));
$mainFields->removeByName('RememberLoginToken');
$mainFields->removeByName('AutoLoginHash');
$mainFields->removeByName('AutoLoginExpired');
$mainFields->removeByName('PasswordEncryption');
$mainFields->removeByName('PasswordExpiry');
$mainFields->removeByName('LockedOutUntil');
if (!$self->config()->lock_out_after_incorrect_logins) {
$mainFields->removeByName('FailedLoginCount');
}
$mainFields->removeByName('Salt');
$mainFields->removeByName('NumVisit');
$mainFields->makeFieldReadonly('LastVisited');
$fields->removeByName('Subscriptions');
// Groups relation will get us into logical conflicts because
// Members are displayed within group edit form in SecurityAdmin
$fields->removeByName('Groups');
if (Permission::check('EDIT_PERMISSIONS')) {
$groupsMap = array();
foreach (Group::get() as $group) {
// Listboxfield values are escaped, use ASCII char instead of »
$groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
}
asort($groupsMap);
$fields->addFieldToTab('Root.Main', ListboxField::create('DirectGroups', singleton('Group')->i18n_plural_name())->setMultiple(true)->setSource($groupsMap)->setAttribute('data-placeholder', _t('Member.ADDGROUP', 'Add group', 'Placeholder text for a dropdown')));
// Add permission field (readonly to avoid complicated group assignment logic).
// This should only be available for existing records, as new records start
// with no permissions until they have a group assignment anyway.
if ($self->ID) {
$permissionsField = new PermissionCheckboxSetField_Readonly('Permissions', false, 'Permission', 'GroupID', $self->getManyManyComponents('Groups'));
$fields->findOrMakeTab('Root.Permissions', singleton('Permission')->i18n_plural_name());
$fields->addFieldToTab('Root.Permissions', $permissionsField);
}
}
$permissionsTab = $fields->fieldByName("Root")->fieldByName('Permissions');
if ($permissionsTab) {
$permissionsTab->addExtraClass('readonly');
}
$defaultDateFormat = Zend_Locale_Format::getDateFormat(new Zend_Locale($self->Locale));
$dateFormatMap = array('MMM d, yyyy' => Zend_Date::now()->toString('MMM d, yyyy'), 'yyyy/MM/dd' => Zend_Date::now()->toString('yyyy/MM/dd'), 'MM/dd/yyyy' => Zend_Date::now()->toString('MM/dd/yyyy'), 'dd/MM/yyyy' => Zend_Date::now()->toString('dd/MM/yyyy'));
$dateFormatMap[$defaultDateFormat] = Zend_Date::now()->toString($defaultDateFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
$mainFields->push($dateFormatField = new MemberDatetimeOptionsetField('DateFormat', $self->fieldLabel('DateFormat'), $dateFormatMap));
$dateFormatField->setValue($self->DateFormat);
$defaultTimeFormat = Zend_Locale_Format::getTimeFormat(new Zend_Locale($self->Locale));
$timeFormatMap = array('h:mm a' => Zend_Date::now()->toString('h:mm a'), 'H:mm' => Zend_Date::now()->toString('H:mm'));
$timeFormatMap[$defaultTimeFormat] = Zend_Date::now()->toString($defaultTimeFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
$mainFields->push($timeFormatField = new MemberDatetimeOptionsetField('TimeFormat', $self->fieldLabel('TimeFormat'), $timeFormatMap));
$timeFormatField->setValue($self->TimeFormat);
});
return parent::getCMSFields();
}