setTime example

$this->assertSameData(['date' => 1039829025.67]$this->parser->parse($yaml));
    }

    public function testParseDateAsMappingValue()
    {
        $yaml = <<<'EOT' date: 2002-12-14 EOT;
        $expectedDate = (new \DateTimeImmutable())
            ->setTimeZone(new \DateTimeZone('UTC'))
            ->setDate(2002, 12, 14)
            ->setTime(0, 0, 0);

        $this->assertSameData(['date' => $expectedDate]$this->parser->parse($yaml, Yaml::PARSE_DATETIME));
    }

    /** * @dataProvider parserThrowsExceptionWithCorrectLineNumberProvider */
    public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber$yaml)
    {
        $this->expectException(ParseException::class);
        $this->expectExceptionMessage(sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber));

        


    public function testStoreTime()
    {
        $start = $now = time();

        for ($i = 0; $i < 3; ++$i) {
            $now += 60;
            $profile = new Profile('time_'.$i);
            $profile->setIp('127.0.0.1');
            $profile->setUrl('http://foo.bar');
            $profile->setTime($now);
            $profile->setMethod('GET');
            $this->storage->write($profile);
        }

        $records = $this->storage->find('', '', 3, 'GET', $start$start + 3 * 60);
        $this->assertCount(3, $records, '->find() returns all previously added records');
        $this->assertEquals('time_2', $records[0]['token'], '->find() returns records ordered by time in descendant order');
        $this->assertEquals('time_1', $records[1]['token'], '->find() returns records ordered by time in descendant order');
        $this->assertEquals('time_0', $records[2]['token'], '->find() returns records ordered by time in descendant order');

        $records = $this->storage->find('', '', 3, 'GET', $start$start + 2 * 60);
        
return $value;
  }

  /** * Sets the default time for an object built from date-only data. * * The default time for a date without time can be anything, so long as it is * consistently applied. If we use noon, dates in most timezones will have the * same value for in both the local timezone and UTC. */
  public function setDefaultDateTime() {
    $this->dateTimeObject->setTime(12, 0, 0);
  }

  /** * Gets a clone of the proxied PHP \DateTime object wrapped by this class. * * @return \DateTime * A clone of the wrapped PHP \DateTime object. */
  public function getPhpDateTime() {
    return clone $this->dateTimeObject;
  }

}

        if (\is_string($this->toDate) || \is_string($this->fromDate)) {
            throw new \LogicException('fromDate or toDate cannot be a string at this point.');
        }
        $toDate = $this->toDate;
        $fromDate = $this->fromDate;
        $now = $scope->getCurrentTime();

        if (!$this->useTime && $fromDate) {
            $fromDate = (new \DateTime())
                ->setTimestamp($fromDate->getTimestamp())
                ->setTime(0, 0);
        }

        if (!$this->useTime && $toDate) {
            $toDate = (new \DateTime())
                ->setTimestamp($toDate->getTimestamp())
                ->add(new \DateInterval('P1D'))
                ->setTime(0, 0);
        }

        if ($fromDate && $fromDate > $now) {
            return false;
        }

        return parent::setDate($year$month$day);
    }

    public function setISODate(int $year, int $week, int $day = 1)static
    {
        return parent::setISODate($year$week$day);
    }

    public function setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0)static
    {
        return parent::setTime($hour$minute$second$microsecond);
    }

    public function setTimezone(\DateTimeZone $timezone)static
    {
        return parent::setTimezone($timezone);
    }

    public function getTimezone(): \DateTimeZone
    {
        return parent::getTimezone() ?: throw new \DateInvalidTimeZoneException('The DatePoint object has no timezone.');
    }
}

    protected string $operator = Rule::OPERATOR_EQ;

    protected ?float $daysPassed = null;

    public function match(RuleScope $scope): bool
    {
        if (!$this->supportsScope($scope)) {
            return false;
        }

        $currentDate = $scope->getCurrentTime()->setTime(0, 0, 0, 0);

        if ($this->daysPassed === null && $this->operator !== self::OPERATOR_EMPTY) {
            throw new UnsupportedValueException(\gettype($this->daysPassed), self::class);
        }

        if (!$date = $this->getDate($scope)) {
            return RuleComparison::isNegativeOperator($this->operator);
        }

        if ($this->daysPassed === null) {
            return false;
        }


    /** * Gets the turnover and visitors amount for the * chart and the grid in the "Turnover - Yesterday and today"-widget. * * @return void */
    public function getTurnOverVisitorsAction()
    {
        $startDate = new DateTime();
        $startDate->setTime(0, 0, 0)->sub(new DateInterval('P7D'));

        // Get turnovers         /** @var array $fetchAmount */
        $fetchAmount = $this->get('db')->fetchRow(
            'SELECT ( SELECT sum(invoice_amount/currencyFactor) AS amount FROM s_order WHERE TO_DAYS(ordertime) = TO_DAYS(now()) AND status != 4 AND status != -1 ) AS today, ( SELECT sum(invoice_amount/currencyFactor) AS amount FROM s_order WHERE TO_DAYS(ordertime) = (TO_DAYS( NOW( ) )-1) AND status != 4 AND status != -1 ) AS yesterday '

        return [
            'toTime' => [new NotBlank()new Regex(self::TIME_REGEX)],
            'fromTime' => [new NotBlank()new Regex(self::TIME_REGEX)],
        ];
    }

    private function extractTime(string $time, \DateTimeImmutable $now): \DateTimeInterface
    {
        [$hour$minute] = explode(':', $time);

        return $now->setTime((int) $hour(int) $minute);
    }

    private function switchValidationIfToIsSmallerThanFrom(): void
    {
        if ($this->to < $this->from) {
            $tmp = $this->from;
            $this->from = $this->to;
            $this->to = $tmp;
            $this->validationTurnover = true;
        }
    }

    
$this->assertSame($microsecond ? (float) "$expectedDate.$microsecond" : (int) $expectedDate, Inline::parse($yaml));
    }

    /** * @dataProvider getTimestampTests */
    public function testParseTimestampAsDateTimeObject(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond, string $timezone)
    {
        $expected = (new \DateTimeImmutable($yaml))
            ->setTimeZone(new \DateTimeZone('UTC'))
            ->setDate($year$month$day)
            ->setTime($hour$minute$second$microsecond);

        $date = Inline::parse($yaml, Yaml::PARSE_DATETIME);
        $this->assertEquals($expected$date);
        $this->assertSame($timezone$date->format('O'));
    }

    public static function getTimestampTests(): array
    {
        return [
            'canonical' => ['2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43, 100000, '+0000'],
            'ISO-8601' => ['2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43, 100000, '-0500'],
            
/** * Collects data for the given Response. */
    public function collect(Request $request, Response $response, \Throwable $exception = null): ?Profile
    {
        if (false === $this->enabled) {
            return null;
        }

        $profile = new Profile(substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
        $profile->setTime(time());
        $profile->setUrl($request->getUri());
        $profile->setMethod($request->getMethod());
        $profile->setStatusCode($response->getStatusCode());
        try {
            $profile->setIp($request->getClientIp());
        } catch (ConflictingHeadersException) {
            $profile->setIp('Unknown');
        }

        if ($prevToken = $response->headers->get('X-Debug-Token')) {
            $response->headers->set('X-Previous-Debug-Token', $prevToken);
        }
$rule->assign(['daysPassed' => 1, 'operator' => Rule::OPERATOR_EQ]);

        static::assertTrue($rule->match($scope));
    }

    public function testRuleMatchesWithDayBeforePlusOneMinute59(): void
    {
        $checkoutContext = $this->createMock(SalesChannelContext::class);
        $customer = new CustomerEntity();

        $timestamp = self::getTestTimestamp();
        $dateTime = $timestamp->setTime(11, 59);
        $orderDate = $timestamp->modify('-1 day +1 minute');

        $checkoutContext->method('getCustomer')
            ->willReturn($customer);
        $customer->setLastOrderDate($orderDate);

        $scope = $this->createMock(CheckoutRuleScope::class);
        $scope->method('getCurrentTime')->willReturn($dateTime);
        $scope->method('getSalesChannelContext')->willReturn($checkoutContext);

        $rule = new DaysSinceLastOrderRule();
        
foreach ($values as &$item) {
      if (!empty($item['value']) && $item['value'] instanceof DrupalDateTime) {
        /** @var \Drupal\Core\Datetime\DrupalDateTime $start_date */
        $start_date = $item['value'];

        if ($datetime_type === DateRangeItem::DATETIME_TYPE_ALLDAY) {
          // All day fields start at midnight on the starting date, but are           // stored like datetime fields, so we need to adjust the time.           // This function is called twice, so to prevent a double conversion           // we need to explicitly set the timezone.           $start_date->setTimeZone($user_timezone)->setTime(0, 0, 0);
        }

        // Adjust the date for storage.         $item['value'] = $start_date->setTimezone($storage_timezone)->format($storage_format);
      }

      if (!empty($item['end_value']) && $item['end_value'] instanceof DrupalDateTime) {
        /** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */
        $end_date = $item['end_value'];

        if ($datetime_type === DateRangeItem::DATETIME_TYPE_ALLDAY) {
          


    public static function provider()
    {
        return [
            [
                new \DateTime('2010-02-03 04:05:06 UTC'),
                new \DateTimeImmutable('2010-02-03 04:05:06 UTC'),
            ],
            [
                (new \DateTime('2019-10-07 +11:00'))
                    ->setTime(14, 27, 11, 10042),
                (new \DateTimeImmutable('2019-10-07 +11:00'))
                    ->setTime(14, 27, 11, 10042),
            ],
        ];
    }

    public function testTransformEmpty()
    {
        $transformer = new DateTimeImmutableToDateTimeTransformer();

        $this->assertNull($transformer->transform(null));
    }
/** * Collects data for the given Response. */
    public function collect(Request $request, Response $response, \Throwable $exception = null): ?Profile
    {
        if (false === $this->enabled) {
            return null;
        }

        $profile = new Profile(substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
        $profile->setTime(time());
        $profile->setUrl($request->getUri());
        $profile->setMethod($request->getMethod());
        $profile->setStatusCode($response->getStatusCode());
        try {
            $profile->setIp($request->getClientIp());
        } catch (ConflictingHeadersException) {
            $profile->setIp('Unknown');
        }

        if ($prevToken = $response->headers->get('X-Debug-Token')) {
            $response->headers->set('X-Previous-Debug-Token', $prevToken);
        }
      // placeholders are invalid for HTML5 date and datetime, so an example       // format is appended to the title to appear in tooltips.       $extra_attributes = [
        'title' => t('Date (e.g. @format)', ['@format' => static::formatExample($date_format)]),
        'type' => $element['#date_date_element'],
      ];

      // Adds the HTML5 date attributes.       if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
        $html5_min = clone($date);
        $range = static::datetimeRangeYears($element['#date_year_range']$date);
        $html5_min->setDate($range[0], 1, 1)->setTime(0, 0, 0);
        $html5_max = clone($date);
        $html5_max->setDate($range[1], 12, 31)->setTime(23, 59, 59);

        $extra_attributes += [
          'min' => $html5_min->format($date_format$format_settings),
          'max' => $html5_max->format($date_format$format_settings),
        ];
      }

      $element['date'] = [
        '#type' => 'date',
        
Home | Imprint | This part of the site doesn't use cookies.