Ejemplo n.º 1
0
 /**
  * getVar get variable prepared according to format
  *
  * @param XoopsObject $obj    object containing variable
  * @param string      $key    name of variable
  * @param string      $format Dtype::FORMAT_* constant indicating desired formatting
  *
  * @return int|DateTime
  */
 public function getVar(XoopsObject $obj, $key, $format)
 {
     $storedValue = $obj->vars[$key]['value'];
     switch (strtolower($format)) {
         case Dtype::FORMAT_NONE:
         case 'n':
             $value = $storedValue;
             break;
         default:
             $value = Time::cleanTime($storedValue);
             break;
     }
     return $value;
 }
Ejemplo n.º 2
0
 /**
  * render
  *
  * @return string rendered form element
  */
 public function render()
 {
     $xoops = \Xoops::getInstance();
     $display_value = \Xoops\Core\Locale\Time::formatDate($this->getValue(false));
     $dataList = $this->isDatalist();
     if (!empty($dataList)) {
         $this->add('list', 'list_' . $this->getName());
     }
     $this->themeDecorateElement();
     $this->suppressRender(['value']);
     $attributes = $this->renderAttributeString();
     $xoops->theme()->addBaseStylesheetAssets('@jqueryuicss');
     $xoops->theme()->addBaseScriptAssets('@jqueryui');
     \Xoops\Core\Locale\Time::localizeDatePicker();
     $xoops->theme()->addScript('', '', ' $(function() { $( "#' . $this->get('id') . '" ).datepicker({' . 'showOn: "button", buttonImageOnly: false, changeYear: true, constrainInput: false, ' . 'buttonImage: "' . $xoops->url('media/xoops/images/icons/calendar.png') . '", ' . 'buttonImageOnly: false, buttonText: "' . \XoopsLocale::A_SELECT . '" }); }); ');
     return '<input ' . $attributes . 'value="' . $display_value . '" ' . $this->getExtra() . ' >';
 }
Ejemplo n.º 3
0
 /**
  * Get a localized list of times at specified interval
  *
  * @param int $interval interval between times in minutes
  * @param int $start    time in seconds from midnight to start list
  * @param int $end      time in seconds from midnight to end list
  *
  * @return array
  */
 public static function getList($interval = 15, $start = 0, $end = 86400)
 {
     $timeList = array();
     $tz = new \DateTimeZone('UTC');
     $start = (int) $start;
     $end = (int) $end;
     if (abs($end - $start) > 86400) {
         $start = 0;
         $end = 86400;
     }
     $end = $end <= 86400 && $end > 0 ? $end : 86400;
     $interval = (int) $interval !== 0 ? 60 * $interval : 60 * 15;
     for ($t = $start; $t < $end; $t += $interval) {
         //$formatted = Calendar::formatTimeEx($t, 'short', $tz);
         $formatted = \Xoops\Core\Locale\Time::formatTime($t, 'short', $tz);
         $timeList[$formatted] = $formatted;
     }
     return $timeList;
 }
Ejemplo n.º 4
0
 /**
  * __construct
  *
  * @param string|array      $caption Caption or array of all attributes
  * @param string            $name    name
  * @param integer|\DateTime $value   unix timestamp or DateTime object
  */
 public function __construct($caption, $name = null, $value = 0)
 {
     // stash everything in the tray and sort out later
     if (is_array($caption)) {
         parent::__construct($caption);
         $this->set(':joiner', '');
     } else {
         parent::__construct($caption, '', $name);
         $this->set('value', $value);
     }
     $workingTime = \Xoops\Core\Locale\Time::cleanTime($this->get('value', 0));
     $dateDefinition = ['caption' => '', 'name' => $this->get('name') . '[date]', 'id' => $this->get('name') . '-date', 'size' => 15, 'value' => $workingTime, ElementFactory::FORM_KEY => $this];
     new DateSelect($dateDefinition);
     $minuteInterval = $this->get(':minuteinterval', 15);
     $hours = (int) ltrim($workingTime->format('H'), '0');
     $minutes = (int) ltrim($workingTime->format('i'), '0');
     $timeDefinition = ['caption' => '', 'name' => $this->get('name') . '[time]', 'id' => $this->get('name') . '-time', 'size' => 1, 'value' => \Xoops\Core\Locale\Time::formatTime($hours * 3600 + 60 * $minuteInterval * ceil($minutes / $minuteInterval), 'short', new \DateTimeZone('UTC')), ElementFactory::FORM_KEY => $this, 'option' => \Xoops\Core\Lists\Time::getList($minuteInterval)];
     new Select($timeDefinition);
 }
Ejemplo n.º 5
0
 /**
  * @dataProvider formatTimestampProvider
  */
 public function test_formatTimestamp($locale, $timezone, $format, $shortform, $expected)
 {
     $instance = $this->myClass;
     \Xoops\Locale::setTimeZone(new \DateTimeZone($timezone));
     \Xoops\Locale::setCurrent($locale);
     $dateTime = \Xoops\Core\Locale\Time::cleanTime();
     $dateTime->setDate(2015, 12, 14);
     $dateTime->setTime(0, 0, 0);
     $time = $dateTime->getTimestamp();
     $value = $instance::formatTimestamp($time, $format);
     $this->assertSame($expected, $value);
     if (!empty($shortform)) {
         $value = $instance::formatTimestamp($time, $shortform);
         $this->assertSame($expected, $value);
     }
 }
Ejemplo n.º 6
0
 /**
  * Get User Timestamp (kind of pointless, since timestamps are UTC?)
  *
  * @param \DateTime|int $time DateTime object or unix timestamp
  *
  * @return int unix timestamp
  */
 public function getUserTimestamp($time)
 {
     $dt = \Xoops\Core\Locale\Time::cleanTime($time);
     return $dt->getTimestamp();
 }
Ejemplo n.º 7
0
 /**
  * Function to display formatted times in user timezone
  *
  * @param mixed  $time
  * @param string $format Format codes ()
  *                       's' or 'short'  - short;
  *                       'm' or 'medium' - medium;
  *                       'l' or 'long'   - long;
  *                       'c' or 'custom' - format determined according to interval to present;
  *                       'e' or 'elapse' - Elapsed;
  *                       'mysql' - Y-m-d H:i:s;
  *                       'rss'
  *
  * @return string
  */
 public static function formatTimestamp($time, $format = 'l')
 {
     $workingTime = Time::cleanTime($time);
     switch (strtolower($format)) {
         case 'short':
         case 's':
             return Time::formatDateTime($workingTime, 'short');
         case 'medium':
         case 'm':
             return Time::formatDateTime($workingTime, 'medium');
         case 'long':
         case 'l':
             return Time::formatDateTime($workingTime, 'long');
         case 'full':
         case 'f':
             return Time::formatDateTime($workingTime, 'full');
         case 'custom':
         case 'c':
             $specialName = Calendar::getDateRelativeName($workingTime, true);
             if ($specialName != '') {
                 return $specialName;
             }
             // no break - fall through
         // no break - fall through
         case 'elapse':
         case 'e':
             return Time::describeRelativeInterval($workingTime);
         case 'short-date':
             return Time::formatDate($workingTime, 'short');
         case 'short-time':
             return Time::formatTime($workingTime, 'short');
         case 'medium-date':
             return Time::formatDate($workingTime, 'medium');
         case 'medium-time':
             return Time::formatTime($workingTime, 'medium');
         case 'long-date':
             return Time::formatDate($workingTime, 'long');
         case 'long-time':
             return Time::formatTime($workingTime, 'long');
         case 'full-date':
             return Time::formatDate($workingTime, 'full');
         case 'full-time':
             return Time::formatTime($workingTime, 'full');
         case 'rss':
             $workingTime->setTimezone(new \DateTimeZone('UTC'));
             return $workingTime->format($workingTime::RSS);
         case 'mysql':
             $workingTime->setTimezone(new \DateTimeZone('UTC'));
             return $workingTime->format('Y-m-d H:i:s');
         default:
             if ($format != '') {
                 return $workingTime->format($format);
             }
             return Time::formatDateTime($workingTime, 'long');
             break;
     }
 }
Ejemplo n.º 8
0
 * @copyright 2011-2015 XOOPS Project (http://xoops.org)
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
 * @author    trabis <*****@*****.**>
 * @author    Richard Griffith <*****@*****.**>
 */
include dirname(dirname(__DIR__)) . '/mainfile.php';
$xoops = Xoops::getInstance();
$xoops->header();
$default = Time::cleanTime();
$dateOnly = Request::getDateTime('date', $default);
$dateAndTime = Request::getDateTime('date_time', $default);
// Date demo form
$form = new Xoops\Form\ThemeForm('Date and Time', 'form_localedates', '', 'post');
$date = new Xoops\Form\DateSelect('Date', 'date', $dateOnly);
$date->setDescription(\XoopsLocale::formatTimestamp($dateOnly, 'custom'));
$form->addElement($date, true);
$date_time = new Xoops\Form\DateTime('Date time', 'date_time', $dateAndTime);
$date_time->setDescription(Time::describeRelativeInterval($dateAndTime));
$form->addElement($date_time, true);
$buttonSubmit = new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit');
$form->addElement($buttonSubmit);
$form->display();
// Locale selection form
$localePicker = new Xoops\Form\ThemeForm('Change Locale', 'form_locale', '', 'get');
$localeSelect = new Xoops\Form\SelectLocale('Locale', 'lang', Request::getString('lang', 'en_US'));
$localePicker->addElement($localeSelect);
$buttonSubmit = new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit');
$localePicker->addElement($buttonSubmit);
$localePicker->display();
\Xoops\Utils::dumpFile(__FILE__);
$xoops->footer();
Ejemplo n.º 9
0
 /**
  * Return a DateTime object from a Xoops\Form\DateSelect of Xoops\Form\DateTime field
  *
  * @param string $name    Variable name
  * @param mixed  $default Default value if the variable does not exist
  * @param string $hash    Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
  *
  * @return \DateTime object
  */
 public static function getDateTime($name, $default = null, $hash = 'default')
 {
     $values = self::getVar($name, [], $hash, 'array');
     $count = count($values);
     if ($count === 1) {
         $date = reset($values);
         $ret = Time::inputToDateTime($date);
     } elseif (isset($values['date']) && isset($values['time'])) {
         $ret = Time::inputToDateTime($values);
     } else {
         $ret = Time::cleanTime($default);
     }
     return $ret;
 }