/** * Constructor * * @param var... $args */ public function __construct() { $this->name = ''; $args = func_get_args(); foreach ($args as $part) { if ($part instanceof self) { $this->name .= $part->getName(); } else { $this->name .= strtr($part, '\\', '/') . '/'; } } $this->name = rtrim($this->name, '/') . '/'; $this->mod = Date::now(); $this->compression = Compression::$NONE; }
/** * Helper method * * @param string input * @param bool lower whether this is the lower boundary * @return util.Date */ protected function parseDate($input, $lower) { switch ($input) { case '__NOW__': if ($lower) { $r = DateUtil::getMidnight(Date::now()); } else { $r = DateUtil::getMidnight(DateUtil::addDays(Date::now(), 1)); } break; case '__FUTURE__': $r = Date::now(); break; case '__UNLIMITED__': $r = null; break; default: $r = new Date($input); } return $r; }
/** * Parse raw listing entry. * * @param string $raw a single line * @param peer.ftp.FtpConnection $connection * @param string $base default "/" * @param util.Date $ref default NULL * @return peer.ftp.FtpEntry */ public function entryFrom($raw, FtpConnection $conn = null, $base = '/', Date $ref = null) { sscanf($raw, '%s %d %s %s %d %s %d %[^ ] %[^$]', $permissions, $numlinks, $user, $group, $size, $month, $day, $date, $filename); // Only qualify filenames if they appear unqualified in the listing if ('/' !== $filename[0]) { $filename = $base . $filename; } // Create a directory or an entry if ('d' === $permissions[0]) { $e = new FtpDir($filename, $conn); } else { $e = new FtpFile($filename, $conn); } // If the entry contains a timestamp, the year is omitted, "Apr 4 20:16" // instead of "Apr 4 2009". This compact format is used when the file // time is within six months* from the current date, in either direction! // // *] #define SIXMONTHS ((365 / 2) * 86400) := 15724800 // See http://svn.freebsd.org/base/projects/releng_7_xen/bin/ls/print.c if (strstr($date, ':')) { $ref || ($ref = Date::now()); $d = new Date($month . ' ' . $day . ' ' . $ref->getYear() . ' ' . $date); if ($d->getTime() - $ref->getTime() > 15724800) { $d = DateUtil::addMonths($d, -12); } } else { $d = new Date($month . ' ' . $day . ' ' . $date); } try { $e->setPermissions(substr($permissions, 1)); $e->setNumlinks($numlinks); $e->setUser($user); $e->setGroup($group); $e->setSize($size); $e->setDate($d); } catch (\lang\IllegalArgumentException $e) { throw new \lang\FormatException('Cannot parse "' . $raw . '": ' . $e->getMessage()); } return $e; }
public function date_accessors() { $d = Date::now(); $this->fixture->setDate($d); $this->assertEquals($d, $this->fixture->getDate()); }
/** * LIST: This command causes a list of file names and file details * to be sent from the FTP site to the client. * * @param peer.Socket socket * @param string params */ public function onList($socket, $params) { if (!($dataSocket = $this->openDatasock($socket))) { return; } // Split options from arguments if (substr($params, 0, 1) === '-') { list($options, $params) = explode(' ', substr($params, 1), 2); $this->cat && $this->cat->debug('+++ Options:', $options); } else { $options = ''; } if (!($entry = $this->storage->lookup($socket->hashCode(), $params))) { $this->answer($socket, 550, $params . ': No such file or directory'); $dataSocket->close(); unset($dataSocket); $this->cat && $this->cat->debug($socket, $this->datasock[$socket->hashCode()]); return; } // Invoke interceptor if (!$this->checkInterceptors($socket, $entry, 'onRead')) { $dataSocket->close(); return; } $this->answer($socket, 150, sprintf('Opening %s mode data connection for filelist', $this->sessions[$socket->hashCode()]->typeName())); // If a collection was specified, list its elements, otherwise, // list the single element if ($entry instanceof StorageCollection && !strstr($options, 'd')) { $elements = $entry->elements(); } else { $elements = [$entry]; } $before6Months = DateUtil::addMonths(Date::now(), -6)->getTime(); for ($i = 0, $s = sizeof($elements); $i < $s; $i++) { $buf = sprintf('%s %2d %s %s %8d %s %s', $this->permissionString($elements[$i]->getPermissions()), $elements[$i]->numLinks(), $elements[$i]->getOwner(), $elements[$i]->getGroup(), $elements[$i]->getSize(), date($elements[$i]->getModifiedStamp() < $before6Months ? 'M d Y' : 'M d H:i', $elements[$i]->getModifiedStamp()), $elements[$i]->getName()); $this->cat && $this->cat->debug(' ', $buf); $dataSocket->write($buf . $this->eol($this->sessions[$socket->hashCode()]->getType())); } $dataSocket->close(); $this->answer($socket, 226, 'Transfer complete'); }
public function genericFinderGetAll() { $this->getConnection()->setResultSet(new MockResultSet([0 => ['job_id' => 1, 'title' => $this->getName(), 'valid_from' => \util\Date::now(), 'expire_at' => null], 1 => ['job_id' => 2, 'title' => $this->getName() . ' #2', 'valid_from' => \util\Date::now(), 'expire_at' => null]])); $all = (new GenericFinder(Job::getPeer()))->getAll(new \rdbms\Criteria()); $this->assertEquals(2, sizeof($all)); $this->assertInstanceOf(Job::class, $all[0]); $this->assertInstanceOf(Job::class, $all[1]); }
public function setDateFieldValueOnWrongObject() { $this->fixture->getField('date')->set(new Object(), Date::now()); }
public function typeof_date_should_match_date_instance() { $this->assertTrue(Arg::anyOfType('util.Date')->matches(Date::now())); }
public function testDoSelectMax() { for ($i = 0; $i < 4; $i++) { $this->setResults(new MockResultSet(array(0 => array('job_id' => 654, 'title' => 'Java Unit tester', 'valid_from' => Date::now(), 'expire_at' => null), 1 => array('job_id' => 655, 'title' => 'Java Unit tester 1', 'valid_from' => Date::now(), 'expire_at' => null), 2 => array('job_id' => 656, 'title' => 'Java Unit tester 2', 'valid_from' => Date::now(), 'expire_at' => null), 3 => array('job_id' => 657, 'title' => 'Java Unit tester 3', 'valid_from' => Date::now(), 'expire_at' => null)))); $this->assertEquals($i ? $i : 4, count(Job::getPeer()->doSelect(new \rdbms\Criteria(), $i))); } }
public function updated() { $this->fixture->setUpdated($d = \util\Date::now()); $this->assertEquals($d, $this->fixture->getUpdated()); }
public function duedate() { $this->fixture->setDuedate($date = Date::now()); $this->assertEquals($date, $this->fixture->getDuedate()); }
public function setValue() { with($d = Date::now()); $this->wrapper->setValue('orderdate', $d); $this->assertEquals($d, $this->wrapper->getValue('orderdate')); }
/** * Constructor * * @param int uid default -1 */ public function __construct($uid = -1) { $this->uid = $uid; $this->date = Date::now(); }
public function expiredJobs() { return new \rdbms\Criteria(array('expire_at', \util\Date::now(), GREATER_THAN)); }
public function declared_accessor_not_overwritten() { $this->assertEquals('Comment: Test', (new Comment('Tester', 'Test', Date::now()))->text()); }
public function createDateFromStaticNowFunctionWithZimeZone() { $d = Date::now(new TimeZone('Australia/Sydney')); $this->assertEquals('Australia/Sydney', $d->getTimeZone()->getName()); }
public function formatNullWithDefault() { $now = \util\Date::now(); $writer = $this->newWriter()->withProcessors([(new FormatDate('Y-m-d H:i'))->withDefault($now), null]); $writer->write([null, 'Order placed']); $this->assertEquals($now->toString('Y-m-d H:i') . ";Order placed\n", $this->out->getBytes()); }
public function genericFinderGetAll() { $this->getConnection()->setResultSet(new MockResultSet(array(0 => array('job_id' => 1, 'title' => $this->getName(), 'valid_from' => \util\Date::now(), 'expire_at' => null), 1 => array('job_id' => 2, 'title' => $this->getName() . ' #2', 'valid_from' => \util\Date::now(), 'expire_at' => null)))); $all = create(new GenericFinder(Job::getPeer()))->getAll(new \rdbms\Criteria()); $this->assertEquals(2, sizeof($all)); $this->assertClass($all[0], 'net.xp_framework.unittest.rdbms.dataset.Job'); $this->assertClass($all[1], 'net.xp_framework.unittest.rdbms.dataset.Job'); }
/** * Adds an item * * @param string title * @param string link * @param string description default '' * @param string util.Date default NULL date defaulting to current date/time * @return object the added item */ public function addItem($title, $link, $description = '', Date $date = null) { if (null === $date) { $date = isset($this->channel->date) ? $this->channel->date : Date::now(); } $item = new \stdClass(); $item->title = $title; $item->link = $link; $item->description = $description; $node = (new \xml\Node('item'))->withChild(new \xml\Node('title', $title))->withChild(new \xml\Node('link', $link))->withChild(new \xml\Node('description', $description))->withChild(new \xml\Node('dc:date', $date->toString(DATE_ATOM))); $node->setAttribute('rdf:about', $link); $item->node = $this->root()->addChild($node); $this->items[] = $item; $this->channel->sequence->addChild(new \xml\Node('rdf:li', null, ['rdf:resource' => $link])); return $item; }