Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function validateAttribute($model, $attribute)
 {
     $timestamp = $this->parseDateTimeValue($model->{$attribute}, $this->getTimeValue($model));
     if ($timestamp === false) {
         $this->addError($model, $attribute, $this->message, []);
     } elseif ($this->min !== null && $timestamp < $this->min) {
         $this->addError($model, $attribute, $this->tooSmall, ['min' => $this->minString]);
     } elseif ($this->max !== null && $timestamp > $this->max) {
         $this->addError($model, $attribute, $this->tooBig, ['max' => $this->maxString]);
     } elseif (!$this->isInDbFormat($model->{$attribute})) {
         // If there is no error, and attribute is not yet in DB Format - convert to DB
         $date = new \DateTime();
         $date->setTimestamp($timestamp);
         if ($this->hasTime()) {
             // Convert timestamp to apps timeZone
             $date->setTimezone(new \DateTimeZone(\Yii::$app->timeZone));
         } else {
             // If we do not need to respect time, set timezone to utc
             // To ensure we're saving 00:00:00 time infos.
             $date->setTimezone(new \DateTimeZone('UTC'));
         }
         if ($this->convertToFormat !== null) {
             $model->{$attribute} = $date->format($this->convertToFormat);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * When a message arrives that contains a trigger, this is started
  *
  * @param $msgData
  */
 public function onMessage($msgData)
 {
     $message = $msgData->message->message;
     $data = $this->trigger->trigger($message, $this->information()["trigger"]);
     if (isset($data["trigger"])) {
         $channelName = $msgData->channel->name;
         $guildName = $msgData->guild->name;
         $date = date("d-m-Y");
         $fullDate = date("Y-m-d H:i:s");
         $dateTime = new DateTime($fullDate);
         $et = $dateTime->setTimezone(new DateTimeZone("America/New_York"));
         $et = $et->format("H:i:s");
         $pt = $dateTime->setTimezone(new DateTimeZone("America/Los_Angeles"));
         $pt = $pt->format("H:i:s");
         $utc = $dateTime->setTimezone(new DateTimeZone("UTC"));
         $utc = $utc->format("H:i:s");
         $cet = $dateTime->setTimezone(new DateTimeZone("Europe/Copenhagen"));
         $cet = $cet->format("H:i:s");
         $msk = $dateTime->setTimezone(new DateTimeZone("Europe/Moscow"));
         $msk = $msk->format("H:i:s");
         $aest = $dateTime->setTimezone(new DateTimeZone("Australia/Sydney"));
         $aest = $aest->format("H:i:s");
         $msg = "**Current EVE Time:** {$utc} / **EVE Date:** {$date} / **PT:** {$pt} / **ET:** {$et} / **CET:** {$cet} / **MSK:** {$msk} / **AEST:** {$aest}";
         $this->log->info("Sending time info to {$channelName} on {$guildName}");
         $msgData->user->reply($msg);
     }
 }
Exemplo n.º 3
0
 /**
  * Constructor.
  *
  * @param \Ecn\RiftConnector\Entity\Zone $zone
  * @param string                         $name
  * @param string                         $startDate Unix Timestamp
  */
 public function __construct(Zone $zone, $name, $startDate)
 {
     $this->name = $name;
     $this->startDate = new \DateTime('@' . $startDate);
     $this->startDate->setTimezone(new \DateTimeZone(date('e')));
     $this->zone = $zone;
 }
 /**
  * @return void
  */
 public function setUp()
 {
     $this->sampleLocale = new \TYPO3\Flow\I18n\Locale('en');
     $this->sampleLocalizedLiterals = (require __DIR__ . '/../Fixtures/MockLocalizedLiteralsArray.php');
     $this->sampleDateTime = new \DateTime('@1276192176');
     $this->sampleDateTime->setTimezone(new \DateTimeZone('Europe/London'));
 }
Exemplo n.º 5
0
 /**
  * Sets the properties in this object as received from the webhook
  *
  * @return void
  */
 public function set($properties)
 {
     $this->properties = $properties;
     if (isset($properties['event'])) {
         $this->event = $properties['event'];
     }
     if (isset($properties['email'])) {
         $this->email = $properties['email'];
     }
     if (isset($properties['timestamp'])) {
         if (is_numeric($properties['timestamp'])) {
             $this->timestamp = new DateTime('@' . $properties['timestamp']);
         } elseif (is_array($properties['timestamp'])) {
             $this->timestamp = new DateTime($properties['timestamp']['date'], new DateTimezone($properties['timestamp']['timezone']));
         }
     } else {
         $this->timestamp = new DateTime('now');
     }
     $this->timestamp->setTimezone(new DateTimezone('UTC'));
     if (isset($properties['category'])) {
         $this->category = $properties['category'];
     }
     if (!empty($properties['data'])) {
         $this->data = $properties['data'];
     }
 }
 /**
  * @param \DateTime $dateTime
  * @return string
  */
 public function getDateStringFromDateTime(\DateTime $dateTime)
 {
     $savedTimeZone = $dateTime->getTimezone();
     $dateTime->setTimezone(new \DateTimeZone($this->targetSystemTimeZone));
     $restApiDateString = $dateTime->format($this->targetSystemDateFormat);
     $dateTime->setTimezone($savedTimeZone);
     return $restApiDateString;
 }
Exemplo n.º 7
0
 /**
  * @param \DateTime $begin should be in UTC date time zone, if not - it will be cast to UTC
  * @param \DateTime $end should be in UTC date time zone, if not - it will be cast to UTC
  */
 public function __construct(\DateTime $begin, \DateTime $end)
 {
     if ($begin > $end) {
         throw new \InvalidArgumentException('Begin date can not be greater than end date.');
     }
     $timezone = new \DateTimeZone(self::DEFAULT_TIMEZONE);
     $this->begin = clone $begin;
     $this->end = clone $end;
     $this->begin->setTimezone($timezone);
     $this->end->setTimezone($timezone);
 }
Exemplo n.º 8
0
 /**
  *
  */
 public function testSetTimezone()
 {
     $dt = new DateTime('2013-03-08 10:00:00');
     $dt->setTimezone('Europe/Berlin');
     $this->assertEquals('2013-03-08 11:00:00', $dt->format('Y-m-d H:i:s'));
     $this->assertEquals('Europe/Berlin', $dt->getTimezone()->getName());
     $dt->setTimezone(new \DateTimeZone('Indian/Mahe'), true);
     $this->assertEquals('2013-03-08 11:00:00', $dt->format('Y-m-d H:i:s'));
     $this->assertEquals('Indian/Mahe', $dt->getTimezone()->getName());
     $dt->setTimezone(null);
     $this->assertEquals('UTC', $dt->getTimezone()->getName());
 }
Exemplo n.º 9
0
 public function toString(\DateTime $pDateTime, $pDateTimeZone)
 {
     if ($pDateTimeZone->getName() == $pDateTime->getTimezone()->getName()) {
         return $pDateTime->format('c');
     } else {
         $lDateTimeZone = $pDateTime->getTimezone();
         $pDateTime->setTimezone($pDateTimeZone);
         $lDateTimeString = $pDateTime->format('c');
         $pDateTime->setTimezone($lDateTimeZone);
         return $lDateTimeString;
     }
     return $pDateTime->format('c');
 }
Exemplo n.º 10
0
 public function testValidSendbankPayment()
 {
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface');
     $templating->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'callbackValidsendbank')));
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $date = new \DateTime();
     $date->setTimeStamp(strtotime('30/11/1981'));
     $date->setTimezone(new \DateTimeZone('Europe/Paris'));
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $order = new OgonePaymentTest_Order();
     $order->setCreatedAt($date);
     $order->setId(2);
     $order->setReference('FR');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $order->setCurrency($currency);
     $order->setCustomer($customer);
     $order->setLocale('es');
     $payment = new OgonePayment($router, $logger, $templating, true);
     $payment->setCode('ogone_1');
     $payment->setOptions(array('url_return_ok' => '', 'url_return_ko' => '', 'url_callback' => '', 'template' => '', 'form_url' => '', 'sha_key' => '', 'sha-out_key' => '', 'pspid' => '', 'home_url' => '', 'catalog_url' => ''));
     $response = $payment->sendbank($order);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $tz = $this->getContainer()->getParameter('default_timezone');
         $plus = $this->getContainer()->getParameter('gmt_as_number');
         $date = new \DateTime("now");
         $date->setTimezone(new \DateTimeZone($tz))->modify('+' . $plus . ' hour');
         $output->writeln(sprintf('<info>[%s]</info> Parsing time is (<info>%s</info>) Egypt local time ...', date('G:i:s'), $date->format('l, F jS h:i:s')));
         $powerGridService = $this->getContainer()->get('power_grid_service');
         $status = $powerGridService->getStatus();
         if ($status) {
             $em = $this->getContainer()->get('doctrine')->getManager();
             $record = new Status();
             $record->setStatus($status);
             $record->setTimestamp($date);
             $em->persist($record);
             $em->flush();
             $output->writeln(sprintf('<info>[%s]</info> NEW STATUS (<info>%s</info>) ...', date('G:i:s'), $status));
         } else {
             $output->writeln(sprintf('<info>[%s]</info> UNKNOWN STATUS, TRY AGAIN ...', date('G:i:s')));
         }
     } catch (\Exception $e) {
         $this->getContainer()->get('doctrine')->resetManager();
         $output->writeln(sprintf('<info>[%s]</info> <error>[error]</error> %s', date('G:i:s'), $e->getMessage()));
     }
 }
Exemplo n.º 12
0
 /**
  * Sets the date and time based on an Unix timestamp.
  *
  * @param DateTimeZone $timezone A DateTimeZone object representing the desired time zone.
  * @return KDate or FALSE on failure.
  */
 public function setTimezone(DateTimeZone $timezone)
 {
     if ($this->_date->setTimezone($timezone) === false) {
         return false;
     }
     return $this;
 }
Exemplo n.º 13
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //$datetime = Carbon::now('Asia/Bangkok');
     $date = new DateTime();
     $date->setTimezone(new DateTimeZone('Asia/Bangkok'));
     DB::table('users')->insert(['name' => 'Pathma In', 'firstName' => 'Pathma', 'lastName' => 'Inpromma', 'cardID' => '1490300066761', 'phone' => '0909359085', 'code' => $date->format('YmdHis'), 'email' => '*****@*****.**', 'password' => bcrypt('kantavee'), 'created_at' => $date->format('Y-m-d H:i:s'), 'role' => 99]);
 }
Exemplo n.º 14
0
 public function convertPHPFormatDateToISOFormatDate($inputPHPFormat, $date)
 {
     $dateFormat = new sfDateFormat();
     try {
         $symfonyPattern = $this->__getSymfonyDateFormatPattern($inputPHPFormat);
         $dateParts = $dateFormat->getDate($date, $symfonyPattern);
         if (is_array($dateParts) && isset($dateParts['year']) && isset($dateParts['mon']) && isset($dateParts['mday'])) {
             $day = $dateParts['mday'];
             $month = $dateParts['mon'];
             $year = $dateParts['year'];
             // Additional check done for 3 digit years, or more than 4 digit years
             if (checkdate($month, $day, $year) && $year >= 1000 && $year <= 9999) {
                 $dateTime = new DateTime();
                 $dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
                 $dateTime->setDate($year, $month, $day);
                 $date = $dateTime->format('Y-m-d');
                 return $date;
             } else {
                 return "Invalid date";
             }
         }
     } catch (Exception $e) {
         return "Invalid date";
     }
     return null;
 }
Exemplo n.º 15
0
	/** 
	 * Gets the date time for the local time zone/area if user timezones are enabled, if not returns system datetime
	 * @param string $systemDateTime
	 * @param string $format
	 * @return string $datetime
	 */
	public function getLocalDateTime($systemDateTime = 'now', $mask = NULL) {
		if(!isset($mask) || !strlen($mask)) {
			$mask = 'Y-m-d H:i:s';
		}
		
		$req = Request::get();
		if ($req->hasCustomRequestUser()) {
			return date($mask, strtotime($req->getCustomRequestDateTime()));
		}
		
		if(!isset($systemDateTime) || !strlen($systemDateTime)) {
			return NULL; // if passed a null value, pass it back
		} elseif(strlen($systemDateTime)) {
			$datetime = new DateTime($systemDateTime);
		} else {
			$datetime = new DateTime();
		}
		
		if(defined('ENABLE_USER_TIMEZONES') && ENABLE_USER_TIMEZONES) {
			$u = new User();
			if($u && $u->isRegistered()) {
				$utz = $u->getUserTimezone();
				if($utz) {
					$tz = new DateTimeZone($utz);
					$datetime->setTimezone($tz);
				}
			}
		}
		if (Localization::activeLocale() != 'en_US') {
			return $this->dateTimeFormatLocal($datetime,$mask);
		} else {
			return $datetime->format($mask);
		}
	}
Exemplo n.º 16
0
function importEvent(\App\Module $module, \DateTime $starttijd, \DateTime $eindtijd, string $uid, string $ruimte, array $groepcodes)
{
    $starttijd->setTimezone(new \DateTimeZone(ini_get('date.timezone')));
    $eindtijd->setTimezone(new \DateTimeZone(ini_get('date.timezone')));
    $contactmoment = \App\Contactmoment::where('ical_uid', $uid)->first();
    if ($contactmoment === null) {
        $contactmoment = \App\Contactmoment::firstOrNew(['starttijd' => $starttijd]);
    }
    $contactmoment->ical_uid = $uid;
    $contactmoment->starttijd = $starttijd;
    $contactmoment->eindtijd = $eindtijd;
    $contactmoment->ruimte = $ruimte;
    if ($contactmoment->les === null) {
        // try to find lesplan
        $lesplan = $module->lessen()->firstOrNew(['jaar' => $contactmoment->starttijd->format('Y'), 'kalenderweek' => (int) $contactmoment->starttijd->format('W')]);
        if ($lesplan->naam === null) {
            $lesplan->naam = "";
        }
        $lesplan->doelgroep()->associate(\App\Doelgroep::find(1));
        $lesplan->save();
        $contactmoment->les()->associate($lesplan);
    }
    foreach ($groepcodes as $groepcode) {
        $blokgroep = \App\Blokgroep::firstOrNew(['code' => $groepcode]);
        $blokgroep->collegejaar = '1516';
        if (preg_match('/42IN(?<bloknummer>\\d+)SO\\w/', $groepcode, $matches) !== 1) {
            continue;
        }
        $blokgroep->nummer = (int) $matches['bloknummer'];
        $blokgroep->save();
    }
    $contactmoment->save();
}
Exemplo n.º 17
0
 public function createResponse(IAsset $asset, Request $request)
 {
     $response = new DispatchResponse();
     //Set the correct content type based on the asset
     $response->headers->set('Content-Type', $asset->getContentType());
     $response->headers->set('X-Content-Type-Options', 'nosniff');
     //Ensure the cache varies on the encoding
     //Domain specific content will vary on the uri itself
     $response->headers->set("Vary", "Accept-Encoding");
     $content = $asset->getContent();
     //Set the etag to the hash of the request uri, as it is in itself a hash
     $response->setEtag(md5($content));
     $response->setPublic();
     //This resource should last for 30 days in cache
     $response->setMaxAge(2592000);
     $response->setSharedMaxAge(2592000);
     $response->setExpires((new \DateTime())->add(new \DateInterval('P30D')));
     //Set the last modified date to now
     $date = new \DateTime();
     $date->setTimezone(new \DateTimeZone('UTC'));
     $response->headers->set('Last-Modified', $date->format('D, d M Y H:i:s') . ' GMT');
     //Check to see if the client already has the content
     if ($request->server->has('HTTP_IF_MODIFIED_SINCE')) {
         $response->setNotModified();
     } else {
         $response->setContent($content);
     }
     return $response;
 }
Exemplo n.º 18
0
 /**
  * Returns all dates calculated by easter sunday
  *
  * @param int $year
  *
  * @return \DateTime[]
  */
 protected function getEasterDates($year)
 {
     $easterSunday = new \DateTime('21.03.' . $year);
     $easterSunday->modify(sprintf('+%d days', easter_days($year)));
     $easterSunday->setTimezone(new \DateTimeZone(date_default_timezone_get()));
     $easterMonday = clone $easterSunday;
     $easterMonday->modify('+1 day');
     $maundyThursday = clone $easterSunday;
     $maundyThursday->modify('-3 days');
     $goodFriday = clone $easterSunday;
     $goodFriday->modify('-2 days');
     $saturday = clone $easterSunday;
     $saturday->modify('-1 days');
     $ascensionDay = clone $easterSunday;
     $ascensionDay->modify('+39 days');
     $pentecostSunday = clone $easterSunday;
     $pentecostSunday->modify('+49 days');
     $pentecostMonday = clone $pentecostSunday;
     $pentecostMonday->modify('+1 days');
     $pentecostSaturday = clone $pentecostSunday;
     $pentecostSaturday->modify('-1 days');
     $corpusChristi = clone $easterSunday;
     $corpusChristi->modify('+60 days');
     return array('maundyThursday' => $maundyThursday, 'easterSunday' => $easterSunday, 'easterMonday' => $easterMonday, 'saturday' => $saturday, 'goodFriday' => $goodFriday, 'ascensionDay' => $ascensionDay, 'pentecostSaturday' => $pentecostSaturday, 'pentecostSunday' => $pentecostSunday, 'pentecostMonday' => $pentecostMonday, 'corpusChristi' => $corpusChristi);
 }
Exemplo n.º 19
0
 public function increment(\DateTime $date, $invert = false)
 {
     $fbgdwznuc = "timezone";
     ${"GLOBALS"}["scqwquyhj"] = "invert";
     ${$fbgdwznuc} = $date->getTimezone();
     $date->setTimezone(new \DateTimeZone("UTC"));
     if (${${"GLOBALS"}["scqwquyhj"]}) {
         $date->modify("-1 hour");
         $date->setTime($date->format("H"), 59);
     } else {
         $date->modify("+1 hour");
         $date->setTime($date->format("H"), 0);
     }
     $date->setTimezone(${${"GLOBALS"}["emrrgkpilcc"]});
     return $this;
 }
 public static function newFromEpoch($epoch, $timezone = 'UTC')
 {
     $date = new DateTime('@' . $epoch);
     $zone = new DateTimeZone($timezone);
     $date->setTimezone($zone);
     return id(new self())->setYear((int) $date->format('Y'))->setMonth((int) $date->format('m'))->setDay((int) $date->format('d'))->setHour((int) $date->format('H'))->setMinute((int) $date->format('i'))->setSecond((int) $date->format('s'))->setTimezone($timezone);
 }
Exemplo n.º 21
0
 /**
  * Formats a datetime string to the specified timezone and format
  *
  * @since 1.0.0
  *
  * @param string    $time_to_set
  * @param string    $format         Defaults to "Y-m-d H:i:s"
  * @param string    $timezone       Defaults to America/Chicago
  * @return DateTime
  */
 function wpdevsclub_format_string_to_datetime($time_to_set = '', $format = 'Y-m-d H:i:s', $timezone = 'America/Chicago')
 {
     date_default_timezone_set($timezone);
     $dt = new DateTime($time_to_set);
     $dt->setTimezone(new DateTimeZone($timezone));
     return $dt->format($format);
 }
Exemplo n.º 22
0
	/** 
	 * Gets the date time for the local time zone/area if user timezones are enabled, if not returns system datetime
	 * @param string $systemDateTime
	 * @param string $format
	 * @return string $datetime
	 */
	public function getLocalDateTime($systemDateTime = 'now', $mask = NULL) {
		if(!isset($mask) || !strlen($mask)) {
			$mask = 'Y-m-d H:i:s';
		}
		
		if(!isset($systemDateTime) || !strlen($systemDateTime)) {
			return NULL; // if passed a null value, pass it back
		} elseif(strlen($systemDateTime)) {
			$datetime = new DateTime($systemDateTime);
		} else {
			$datetime = new DateTime();
		}
		
		if(defined('ENABLE_USER_TIMEZONES') && ENABLE_USER_TIMEZONES) {
			$u = new User();
			if($u && $u->isRegistered()) {
				$utz = $u->getUserTimezone();
				if($utz) {
					$tz = new DateTimeZone($utz);
					$datetime->setTimezone($tz);
				}
			}
		}
		return $datetime->format($mask);
	}
Exemplo n.º 23
0
 function logs($log, $action, $value)
 {
     $temp_output = "";
     if (!is_dir("phppi/logs/")) {
         //Create logs folder
         if (!mkdir("phppi/logs/", 0775)) {
             return false;
         }
     }
     $datetime = new DateTime('', new DateTimeZone('GMT'));
     $datetime->setTimezone(new DateTimeZone($this->settings['log_timezone']));
     if ($action == "add") {
         if ($log == "access" && $this->settings['access_log'] == "on") {
             $temp_output = $datetime->format('Y-m-d H:i:s') . ", " . $_SERVER["REMOTE_ADDR"] . ": " . $value;
         } else {
             if ($log == "phppi") {
             }
         }
     }
     if ($temp_output !== "") {
         $fh = @fopen("phppi/logs/" . $log . ".log", 'a');
         fwrite($fh, $temp_output . "\n");
         fclose($fh);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($rfc3339)
 {
     if (!is_string($rfc3339)) {
         throw new TransformationFailedException('Expected a string.');
     }
     if ('' === $rfc3339) {
         return;
     }
     try {
         $dateTime = new \DateTime($rfc3339);
     } catch (\Exception $e) {
         throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
     }
     if ($this->outputTimezone !== $dateTime->getTimezone()->getName()) {
         try {
             $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
         } catch (\Exception $e) {
             throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
         }
     }
     if (preg_match('/(\\d{4})-(\\d{2})-(\\d{2})/', $rfc3339, $matches)) {
         if (!checkdate($matches[2], $matches[3], $matches[1])) {
             throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
         }
     }
     return $dateTime;
 }
 protected function create_wp_comment($action_id, $message, DateTime $date)
 {
     $comment_date_gmt = $date->format('Y-m-d H:i:s');
     $date->setTimezone(ActionScheduler_TimezoneHelper::get_local_timezone());
     $comment_data = array('comment_post_ID' => $action_id, 'comment_date' => $date->format('Y-m-d H:i:s'), 'comment_date_gmt' => $comment_date_gmt, 'comment_author' => self::AGENT, 'comment_content' => $message, 'comment_agent' => self::AGENT, 'comment_type' => self::TYPE);
     return wp_insert_comment($comment_data);
 }
Exemplo n.º 26
0
 function testOverridingDefaults()
 {
     $dt = new \DateTime();
     $cookie = new Cookie("my_cookie", "my_value", $dt, "/blah", "//blah.com", true, false);
     $expires = $dt->setTimezone(new \DateTimeZone("UTC"))->format("D, d-M-Y H:i:s T");
     $this->assertEquals("my_cookie=my_value; expires={$expires}; path=/blah; domain=//blah.com; secure", (string) $cookie);
 }
 /**
  * Method to send the application response to the client.  All headers will be sent prior to the main
  * application output data.
  *
  * @return  void
  *
  * @since   1.0
  */
 protected function respond()
 {
     // Send the content-type header.
     $this->setHeader('Content-Type', $this->mimeType . '; charset=' . $this->charSet);
     // If the response is set to uncachable, we need to set some appropriate headers so browsers don't cache the response.
     if (!$this->response->cachable) {
         // Expires in the past.
         $this->setHeader('Expires', 'Mon, 1 Jan 2001 00:00:00 GMT', true);
         // Always modified.
         $this->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
         $this->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', false);
         // HTTP 1.0
         $this->setHeader('Pragma', 'no-cache');
     } else {
         // Expires.
         $this->setHeader('Expires', gmdate('D, d M Y H:i:s', time() + 900) . ' GMT');
         // Last modified.
         if ($this->modifiedDate instanceof \DateTime) {
             $this->modifiedDate->setTimezone(new \DateTimeZone('UTC'));
             $this->setHeader('Last-Modified', $this->modifiedDate->format('D, d M Y H:i:s') . ' GMT');
         }
     }
     $this->sendHeaders();
     echo $this->getBody();
 }
Exemplo n.º 28
0
function getThailandTime()
{
    $date = new DateTime();
    $date->setTimezone(new DateTimeZone('Asia/Bangkok'));
    $dateTime = $date->format('Y-m-d H:i:s');
    return $dateTime;
}
Exemplo n.º 29
0
 public function getCreationDate()
 {
     $date = new \DateTime();
     $date->setTimezone(new \DateTimeZone('UTC'));
     $date->setTimestamp(filemtime($this->getDir()));
     return $date;
 }
Exemplo n.º 30
0
 public function makeDecision(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric, $isInvert = false)
 {
     // Get data from BW sensor
     $dbFarm = $dbFarmRole->GetFarmObject();
     $tz = $dbFarm->GetSetting(Entity\FarmSetting::TIMEZONE);
     $date = new DateTime();
     if ($tz) {
         $date->setTimezone(new DateTimeZone($tz));
     }
     $currentDate = array((int) $date->format("Hi"), $date->format("D"));
     $scaling_period = $this->db->GetRow("\n            SELECT * FROM farm_role_scaling_times\n            WHERE '{$currentDate[0]}' >= start_time\n            AND '{$currentDate[0]}' <= end_time\n            AND INSTR(days_of_week, '{$currentDate[1]}') != 0\n            AND farm_roleid = '{$dbFarmRole->ID}'\n            LIMIT 1\n        ");
     if ($scaling_period) {
         $this->logger->info("TimeScalingAlgo({$dbFarmRole->FarmID}, {$dbFarmRole->ID}) Found scaling period. Total {$scaling_period['instances_count']} instances should be running.");
         $this->instancesNumber = $scaling_period['instances_count'];
         $this->lastValue = "(" . implode(' / ', $currentDate) . ") {$scaling_period['start_time']} - {$scaling_period['end_time']} = {$scaling_period['instances_count']}";
         if ($dbFarmRole->GetRunningInstancesCount() + $dbFarmRole->GetPendingInstancesCount() < $this->instancesNumber) {
             return Scalr_Scaling_Decision::UPSCALE;
         } elseif ($dbFarmRole->GetRunningInstancesCount() + $dbFarmRole->GetPendingInstancesCount() > $this->instancesNumber) {
             return Scalr_Scaling_Decision::DOWNSCALE;
         } else {
             return Scalr_Scaling_Decision::NOOP;
         }
     } else {
         if ($dbFarmRole->GetRunningInstancesCount() > $dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_MIN_INSTANCES)) {
             $this->lastValue = "No period defined. Using Min instances setting.";
             return Scalr_Scaling_Decision::DOWNSCALE;
         } else {
             return Scalr_Scaling_Decision::NOOP;
         }
     }
 }