示例#1
0
文件: Time.php 项目: cawaphp/cawa
 /**
  * @param int|DateTime $duration if datetime, start date, if int duration in second
  * @param DateTime $end
  *
  * @return $this|self
  */
 public static function createFromDuration($duration, DateTime $end = null) : self
 {
     if ($duration instanceof DateTime && $end) {
         $duration = $end->getTimestamp() - $duration->getTimestamp();
     }
     return static::create(null, null, null, 0, 0, 0)->addSeconds($duration);
 }
示例#2
0
文件: DateTime.php 项目: cawaphp/html
 /**
  * {@inheritdoc}
  */
 public function setValue($value) : parent
 {
     if ($value instanceof DateObject || $value instanceof DateTimeObject) {
         $value = $value->format('Y-m-d\\TH:i:s');
     } elseif (is_string($value) && $value) {
         $date = new DateTimeObject($value);
         $value = $date->format('Y-m-d\\TH:i:s');
     }
     return parent::setValue($value);
 }
示例#3
0
文件: Date.php 项目: cawaphp/cawa
 /**
  * {@inheritdoc}
  */
 public function format($format = null)
 {
     if (is_null($format)) {
         $format = 'Y-m-d';
     }
     return parent::format($format);
 }
示例#4
0
 /**
  * @param null $name
  *
  * @return string
  */
 public function method($name = null)
 {
     /*
     if (!$ip = Ip::sessionReload("IP")) {
         $ip = Ip::getById(12);
         $ip->sessionSave("IP");
     }
     */
     $list = Ip::getAll();
     $find = $list->find('getCountry', 'JP');
     $cache = Cache::create(["type" => "Apc", "prefix" => "bla", "config" => "redis://*****:*****@doe.com' => 'John Doe'))->setTo(array('*****@*****.**'))->setHtmlBody("sdfsdf");
     // $message->send();
     $http = new Client();
     $http->get("http://www.google.com");
     // $this->app->response->redirect("/");
     $container = new HtmlContainer('<div>');
     $html = new HtmlElement('<a>');
     $html->setContent('Click me')->addClass(array('btn', 'btn-primary'));
     $container->add($html);
     $html = new HtmlElement('<a>');
     $html->setContent('Click now')->addClass(array('btn', 'btn-default'));
     $container->add($html);
     $this->data['main'] = $container->render();
     $this->data['plural'] = DateTime::now()->diffForHumans(DateTime::parse('-1 day')) . '<br />' . DateTime::now()->formatLocalized('%A %d %B %Y') . '<br />' . App::translator()->transChoice('transChoice', 10, [10]) . '<br />' . App::translator()->transChoice('transChoice', 1, [1]);
     $page = new MasterPage();
     $page->setMain($this->render())->setAside('ASIDE FROM ' . get_class() . ' with name ' . $name)->addCss('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
     return $page->render();
 }
示例#5
0
 /**
  * @param string $authorName
  * @param string $language
  * @param int $rating
  * @param string $text
  * @param int $date
  * @param string $authorUrl
  */
 public function __construct(string $authorName, string $language, int $rating, string $text, int $date, string $authorUrl = null)
 {
     $this->authorName = $authorName;
     $this->authorUrl = $authorUrl;
     $this->language = $language;
     $this->rating = $rating;
     $this->text = $text;
     $this->date = DateTime::createFromTimestamp($date);
 }
示例#6
0
文件: DateTime.php 项目: cawaphp/html
 /**
  * {@inheritdoc}
  */
 public function __invoke($content, Column $column, array $primaryValues, array $data) : string
 {
     if (!$content) {
         return '';
     }
     if ($this->format == self::DISPLAY_DURATION_FROMSECONDS) {
         $date = new DateTimeObject();
         $date->addSeconds($content);
         return $date->display(DateTimeObject::DISPLAY_DURATION);
     }
     if (is_string($content)) {
         $content = new DateTimeObject($content);
     }
     if ($this->format == DateTimeObject::DISPLAY_DURATION) {
         return '<abbr title="' . $content->display() . '">' . $content->display($this->format) . '</abbr>';
     } else {
         return $content->display($this->format);
     }
 }
示例#7
0
 /**
  * @param array $data
  *
  * @return $this|self
  */
 protected static function map(array &$data)
 {
     /** @var PlaceDetail $return */
     $return = parent::map($data);
     $return->phone = self::extract($data, 'international_phone_number');
     $return->website = self::extract($data, 'website');
     $return->rating = self::extract($data, 'rating');
     if (isset($data['reviews'])) {
         foreach (self::extract($data, 'reviews') as $current) {
             $return->reviews[] = new Review($current['author_name'], $current['language'], $current['rating'], $current['text'], $current['time'], $current['author_url'] ?? null);
         }
     }
     if (isset($data['opening_hours']['periods'])) {
         foreach (self::extract($data, 'opening_hours/periods') as $current) {
             if (isset($current['open']) && isset($current['close'])) {
                 list($hour, $min) = self::extractHourMin($current['open']);
                 $open = new DateTime();
                 $open->setTimezone('UTC');
                 $open->next($current['open']['day']);
                 $open->hour($hour);
                 $open->minute($min);
                 $open->second(0);
                 $open->addMinutes(-$return->utcOffset);
                 $open->setTimezone(date_default_timezone_get());
                 list($hour, $min) = self::extractHourMin($current['close']);
                 $close = new DateTime();
                 $close->setTimezone('UTC');
                 $close->next($current['close']['day']);
                 $close->hour($hour);
                 $close->minute($min);
                 $close->second(0);
                 $close->addMinutes(-$return->utcOffset);
                 $close->setTimezone(date_default_timezone_get());
                 $return->openingHours[] = new OpeningHoursPeriod($open, $close);
             }
         }
     }
     return $return;
 }
示例#8
0
 /**
  * Test start and end date
  *
  * @param DateTime $start
  * @param \DateInterval $interval
  * @param DateTime $end
  * @param int $options
  *
  * @dataProvider periodProvider
  */
 public function testStartEndDate(DateTime $start, \DateInterval $interval, DateTime $end, int $options = null)
 {
     $period = new DatePeriod($start, $interval, $end, $options);
     $this->assertEquals($period->getStartDate()->format(), $start->format());
     $this->assertEquals($period->getEndDate()->format(), $end->format());
 }
示例#9
0
文件: DateTime.php 项目: cawaphp/cawa
 /**
  * @param string|array $type
  *
  * @return string
  */
 public function display($type = null) : string
 {
     if ($type == self::DISPLAY_DURATION) {
         return $this->diffForHumans(DateTime::now(), true);
     }
     if (is_null($type)) {
         $type = [self::DISPLAY_SHORT, self::DISPLAY_SHORT];
     } elseif (!is_array($type)) {
         $type = [$type, $type];
     } elseif (is_array($type)) {
         if (!isset($type[1])) {
             return Calendar::formatDate($this, $type[0]);
         } elseif (is_null($type[0])) {
             return Calendar::formatTime($this, $type[1]);
         }
     }
     return Calendar::formatDatetime($this, implode('|', $type));
 }
示例#10
0
 /**
  * @param string $type
  * @param $value
  *
  * @return null|DateTime
  */
 private function parseDate(string $type, $value)
 {
     try {
         switch ($type) {
             case 'datetime':
                 $datetime = DateTime::createFromFormat('Y-m-d\\TH:i:s', $value);
                 break;
             case 'date':
                 $datetime = Date::createFromFormat('Y-m-d', $value);
                 break;
             case 'time':
                 $datetime = Time::createFromFormat('H:i:s', $value);
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf("Invalid parse date type '%s'", $type));
         }
     } catch (\Exception $exception) {
         return null;
     }
     return $datetime;
 }
示例#11
0
 /**
  * @param \Cawa\Date\DateTime $date
  *
  * @return $this|self
  */
 public function setMinimunDate(\Cawa\Date\DateTime $date) : self
 {
     $this->widgetOptions = array_merge_recursive($this->widgetOptions, ['minDate' => $date->format('Y-m-d\\TH:i:s')]);
     return $this;
 }