strtotime example

function rest_parse_date( $date$force_utc = false ) {
    if ( $force_utc ) {
        $date = preg_replace( '/[+-]\d+:?\d+$/', '+00:00', $date );
    }

    $regex = '#^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}(?::\d{2})?)?$#';

    if ( ! preg_match( $regex$date$matches ) ) {
        return false;
    }

    return strtotime( $date );
}

/** * Parses a 3 or 6 digit hex color (with #). * * @since 5.4.0 * * @param string $color 3 or 6 digit hex color (with #). * @return string|false */
function rest_parse_hex_color( $color ) {
    
$this->assertEquals(0, $cookies[0]->getExpiresTime());
        $this->assertNull($cookies[0]->getDomain());
        $this->assertEquals('/', $cookies[0]->getPath());
        $this->assertFalse($cookies[0]->isSecure());
        $this->assertFalse($cookies[0]->isHttpOnly());

        $this->assertEquals('test', $cookies[1]->getName());
        $this->assertNull($cookies[1]->getValue());

        $this->assertEquals('ABC', $cookies[2]->getName());
        $this->assertEquals('AeD', $cookies[2]->getValue());
        $this->assertEquals(strtotime('Wed, 13 Jan 2021 22:23:01 GMT')$cookies[2]->getExpiresTime());
        $this->assertEquals('dunglas.fr', $cookies[2]->getDomain());
        $this->assertEquals('/kevin', $cookies[2]->getPath());
        $this->assertTrue($cookies[2]->isSecure());
        $this->assertTrue($cookies[2]->isHttpOnly());
        if (\defined('Symfony\Component\HttpFoundation\Cookie::SAMESITE_STRICT')) {
            $this->assertEquals(Cookie::SAMESITE_STRICT, $cookies[2]->getSameSite());
        }

        $this->assertEquals('The response body', $symfonyResponse->getContent());
        $this->assertEquals(200, $symfonyResponse->getStatusCode());

        
if ( in_array( 'slug', $fields, true ) ) {
            $data['slug'] = $user->user_nicename;
        }

        if ( in_array( 'roles', $fields, true ) ) {
            // Defensively call array_values() to ensure an array is returned.             $data['roles'] = array_values( $user->roles );
        }

        if ( in_array( 'registered_date', $fields, true ) ) {
            $data['registered_date'] = gmdate( 'c', strtotime( $user->user_registered ) );
        }

        if ( in_array( 'capabilities', $fields, true ) ) {
            $data['capabilities'] = (object) $user->allcaps;
        }

        if ( in_array( 'extra_capabilities', $fields, true ) ) {
            $data['extra_capabilities'] = (object) $user->caps;
        }

        if ( in_array( 'avatar_urls', $fields, true ) ) {
            
continue;
            }

            if (null !== $requestBody && $requestBody !== $this->getContent($request['postData'] ?? [])) {
                continue;
            }

            $info = [
                'http_code' => $response['status'],
                'http_method' => $entryMethod,
                'response_headers' => [],
                'start_time' => strtotime($startedDateTime),
                'url' => $entryUrl,
            ];

            /** @var array{name: string, value: string} $header */
            foreach ($response['headers'] as $header) {
                ['name' => $name, 'value' => $value] = $header;

                $info['response_headers'][$name][] = $value;
            }

            return new MockResponse($body$info);
        }


        $data = $this->get('db')->fetchAll($sql[$timeBack]);

        $result = [];
        foreach ($data as $row) {
            $result[] = [
                'timestamp' => strtotime($row['date']),
                'date' => date('d.m.Y', strtotime($row['date'])),
                'visitors' => $row['visitors'],
            ];
        }

        // Get current users online         $currentUsers = $this->get('db')->fetchOne(
            'SELECT COUNT(DISTINCT remoteaddr) FROM s_statistics_currentusers WHERE time > DATE_SUB(NOW(), INTERVAL 3 MINUTE)'
        );
        
/** * Checks if a date string is plausible. * If not, returns null. Otherwise the string. * * @param string $date * * @return string|null */
    private function checkDate($date)
    {
        $dateCheck = strtotime($date);

        return \is_int($dateCheck) && $dateCheck > 0 ? $date : null;
    }
}
 elseif ($string instanceof DateTime) {
        return $string->getTimestamp();
    } elseif (strlen($string) == 14 && ctype_digit($string)) {
        // it is mysql timestamp format of YYYYMMDDHHMMSS?         return mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2),
                       substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4));
    } elseif (is_numeric($string)) {
        // it is a numeric string, we handle it as timestamp         return (int) $string;
    } else {
        // strtotime should handle it         $time = strtotime($string);
        if ($time == -1 || $time === false) {
            // strtotime() was not able to parse $string, use "now":             return time();
        }
        return $time;
    }
}

?>
$summary = parent::settingsSummary();

    $time_diff = $this->getSetting('time_diff');
    $date_format = $this->getSetting('date_format');
    $date_format = $date_format === static::CUSTOM_DATE_FORMAT ? $this->getSetting('custom_date_format') : $date_format;

    if ($time_diff['enabled']) {
      $summary[] = $this->t('Displayed as a time difference');

      $options = ['granularity' => $time_diff['granularity']];

      $timestamp = strtotime('1 year 1 month 1 week 1 day 1 hour 1 minute');
      $interval = $this->dateFormatter->formatTimeDiffUntil($timestamp$options);
      $display = new FormattableMarkup($time_diff['future_format']['@interval' => $interval]);
      $summary[] = $this->t('Future date: %display', ['%display' => $display]);

      $timestamp = strtotime('-1 year -1 month -1 week -1 day -1 hour -1 minute');
      $interval = $this->dateFormatter->formatTimeDiffSince($timestamp$options);
      $display = new FormattableMarkup($time_diff['past_format']['@interval' => $interval]);
      $summary[] = $this->t('Past date: %display', ['%display' => $display]);

      if ($time_diff['refresh']) {
        $refresh_intervals = $this->getRefreshIntervals();
        
if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7]$l2 ) ) {
                        $b['year']   = gmdate( 'Y' );
                        $b['hour']   = $l2[1];
                        $b['minute'] = $l2[2];
                    } else {
                        $b['year']   = $lucifer[7];
                        $b['hour']   = 0;
                        $b['minute'] = 0;
                    }

                    $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day']$b['month']$b['year']$b['hour']$b['minute'] ) );
                    $b['name'] = $lucifer[8];
                }
            }
        }

        // Replace symlinks formatted as "source -> target" with just the source name.         if ( isset( $b['islink'] ) && $b['islink'] ) {
            $b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] );
        }

        return $b;
    }
$changeset_date = wp_unslash( $_POST['customize_changeset_date'] );
            if ( preg_match( '/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/', $changeset_date ) ) {
                $mm         = substr( $changeset_date, 5, 2 );
                $jj         = substr( $changeset_date, 8, 2 );
                $aa         = substr( $changeset_date, 0, 4 );
                $valid_date = wp_checkdate( $mm$jj$aa$changeset_date );
                if ( ! $valid_date ) {
                    wp_send_json_error( 'bad_customize_changeset_date', 400 );
                }
                $changeset_date_gmt = get_gmt_from_date( $changeset_date );
            } else {
                $timestamp = strtotime( $changeset_date );
                if ( ! $timestamp ) {
                    wp_send_json_error( 'bad_customize_changeset_date', 400 );
                }
                $changeset_date_gmt = gmdate( 'Y-m-d H:i:s', $timestamp );
            }
        }

        $lock_user_id = null;
        $autosave     = ! empty( $_POST['customize_changeset_autosave'] );
        if ( ! $is_new_changeset ) {
            $lock_user_id = wp_check_post_lock( $this->changeset_post_id() );
        }
namespace Symfony\Component\BrowserKit\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\BrowserKit\Exception\InvalidArgumentException;
use Symfony\Component\BrowserKit\Exception\UnexpectedValueException;

class CookieTest extends TestCase
{
    public function testToString()
    {
        $cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
        $this->assertEquals('foo=bar; expires=Fri, 20 May 2011 15:25:52 GMT; domain=.myfoodomain.com; path=/; secure; httponly', (string) $cookie, '->__toString() returns string representation of the cookie');

        $cookie = new Cookie('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
        $this->assertEquals('foo=bar%20with%20white%20spaces; expires=Fri, 20 May 2011 15:25:52 GMT; domain=.myfoodomain.com; path=/; secure; httponly', (string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)');

        $cookie = new Cookie('foo', null, 1, '/admin/', '.myfoodomain.com');
        $this->assertEquals('foo=; expires=Thu, 01 Jan 1970 00:00:01 GMT; domain=.myfoodomain.com; path=/admin/; httponly', (string) $cookie, '->__toString() returns string representation of a cleared cookie if value is NULL');

        $cookie = new Cookie('foo', 'bar', 0, '/', '');
        $this->assertEquals('foo=bar; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; httponly', (string) $cookie);

        
$this->assertTrue($c->test($m), '->test() tests a string against the expression');
        }

        foreach ($noMatch as $m) {
            $this->assertFalse($c->test($m), '->test() tests a string against the expression');
        }
    }

    public static function getTestData()
    {
        return [
            ['< 2005-10-10', [strtotime('2005-10-09')][strtotime('2005-10-15')]],
            ['until 2005-10-10', [strtotime('2005-10-09')][strtotime('2005-10-15')]],
            ['before 2005-10-10', [strtotime('2005-10-09')][strtotime('2005-10-15')]],
            ['> 2005-10-10', [strtotime('2005-10-15')][strtotime('2005-10-09')]],
            ['after 2005-10-10', [strtotime('2005-10-15')][strtotime('2005-10-09')]],
            ['since 2005-10-10', [strtotime('2005-10-15')][strtotime('2005-10-09')]],
            ['!= 2005-10-10', [strtotime('2005-10-11')][strtotime('2005-10-10')]],
        ];
    }
}
CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery());
    }

    private function getQuery(): RangeQuery
    {
        $dayLimit = (int) $this->config->get('markAsNew');
        $timestamp = strtotime('-' . $dayLimit . ' days');
        if ($timestamp === false) {
            throw new RuntimeException(sprintf('Could not convert "-%s days" into a timestamp', $dayLimit));
        }

        return new RangeQuery('formattedCreatedAt', [
            'gte' => date('Y-m-d', $timestamp),
            'lte' => date('Y-m-d'),
        ]);
    }
}


        /** @var Enlight_Controller_Front $controller */
        $controller = $this->container->get('front');

        if ($this->container->initialized('session')) {
            $session = $this->container->get('session');
            $session->offsetSet('auto-user', null);
        }

        $controller->Response()->headers->setCookie(
            new Cookie('slt', null, strtotime('-1 Year')$controller->Request()->getBasePath() . '/')
        );
    }

    public function checkCookie(Enlight_Controller_EventArgs $args)
    {
        $request = $args->getRequest();

        $config = $this->container->get(Shopware_Components_Config::class);

        if (!$config->get('useSltCookie')) {
            return;
        }
static::assertMatchesRegularExpression('/\/\/ No expired files found./', $message);
    }

    public function testExecuteWithAllFilesExpired(): void
    {
        $num = 5;
        $data = $this->prepareImportExportFileTestData($num);

        $filePathes = [];
        foreach (array_keys($data) as $key) {
            $filePathes[] = $data[$key]['path'];
            $data[$key]['expireDate'] = date('Y-m-d H:i:s', strtotime('-1 second'));
        }

        $this->fileRepository->create(array_values($data)$this->context);

        $commandTester = new CommandTester($this->deleteExpiredFilesCommand);
        $commandTester->setInputs(['y']);
        $commandTester->execute([]);

        $message = $commandTester->getDisplay();
        static::assertMatchesRegularExpression(
            sprintf('/Are you sure that you want to delete %d expired files\? \(yes\/no\) \[no\]:/', $num),
            
Home | Imprint | This part of the site doesn't use cookies.