public function dateClassesCanCoexist()
 {
     $bd = new \info·binford6100·Date();
     $ud = new Date();
     $this->assertEquals('info.binford6100.Date', $bd->getClassName());
     $this->assertEquals('util.Date', $ud->getClassName());
 }
 /**
  * Checks validity
  *
  * @param   util.Date date default NULL (date to check against, defaulting to now)
  * @return  bool TRUE if this certificate is valid for the given date
  */
 public function checkValidity($date = null)
 {
     if (null === $date) {
         $date = new Date();
     }
     return $date->getTime() >= $this->_info['validFrom_time_t'] || $date->getTime() <= $this->_info['validTo_time_t'];
 }
 public function testSerialization()
 {
     $msg = new XPSoapMessage();
     $msg->createCall('Test', 'testSerialization');
     $this->assertEquals('Test', $msg->action);
     $this->assertEquals('testSerialization', $msg->method);
     $this->assertEquals('SOAP-ENV:Envelope', $msg->root()->getName());
     $this->assertNotEmpty($msg->root()->getAttributes());
     $msg->setData(array('int' => 1, 'float' => 6.1, 'string' => 'Binford', 'string2' => '"<&>"', 'bool' => true, 'date' => \util\Date::fromString('1977-12-14 11:55AM Europe/Berlin'), 'null' => null, 'array' => array(2, 3), 'hash' => array('class' => 'Test', 'method' => 'testSerialization')));
     // Let's be somewhat forgiving on whitespace
     $src = trim(chop($msg->getSource(0)));
     $this->assertEquals('<SOAP-ENV:Envelope', substr($src, 0, 18));
     $this->assertEquals('</SOAP-ENV:Envelope>', substr($src, -20));
     $this->assertContains($src, '<int xsi:type="xsd:int">1</int>', 'integer');
     $this->assertContains($src, '<float xsi:type="xsd:float">6.1</float>', 'float');
     $this->assertContains($src, '<string xsi:type="xsd:string">Binford</string>', 'string');
     $this->assertContains($src, '<string2 xsi:type="xsd:string">&quot;&lt;&amp;&gt;&quot;</string2>', 'escaping');
     $this->assertContains($src, '<bool xsi:type="xsd:boolean">true</bool>', 'bool');
     $this->assertContains($src, '<date xsi:type="xsd:dateTime">1977-12-14T11:55:00+01:00</date>', 'date');
     $this->assertContains($src, '<null xsi:nil="true"/>', 'null');
     $this->assertContains($src, '<array xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:anyType[2]">', 'array');
     $this->assertContains($src, '<item xsi:type="xsd:int">2</item>', 'array.inner');
     $this->assertContains($src, '<item xsi:type="xsd:int">3</item>', 'array.inner');
     $this->assertContains($src, '<hash xsi:type="xsd:struct">', 'hash');
     $this->assertContains($src, '<class xsi:type="xsd:string">Test</class>', 'hash.inner');
     $this->assertContains($src, '<method xsi:type="xsd:string">testSerialization</method>', 'hash.inner');
     return $src;
 }
 /**
  * Set up this test
  *
  */
 public function setUp()
 {
     $this->tz = date_default_timezone_get();
     date_default_timezone_set('GMT');
     $this->nowTime = time();
     $this->nowDate = new \util\Date($this->nowTime);
     $this->refDate = \util\Date::fromString('1977-12-14 11:55');
 }
 /**
  * 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;
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
 /**
  * Read from a file
  *
  * @deprecated  Use img.io.MetaDataReader instead
  * @param   io.File file
  * @param   var default default void what should be returned in case no data is found
  * @return  img.util.IptcData
  * @throws  lang.FormatException in case malformed meta data is encountered
  * @throws  lang.ElementNotFoundException in case no meta data is available
  * @throws  img.ImagingException in case reading meta data fails
  */
 public static function fromFile(\io\File $file)
 {
     if (false === getimagesize($file->getURI(), $info)) {
         $e = new ImagingException('Cannot read image information from ' . $file->getURI());
         \xp::gc(__FILE__);
         throw $e;
     }
     if (!isset($info['APP13'])) {
         if (func_num_args() > 1) {
             return func_get_arg(1);
         }
         throw new ElementNotFoundException('Cannot get IPTC information from ' . $file->getURI() . ' (no APP13 marker)');
     }
     if (!($iptc = iptcparse($info['APP13']))) {
         throw new \lang\FormatException('Cannot parse IPTC information from ' . $file->getURI());
     }
     // Parse creation date
     if (3 == sscanf(@$iptc['2#055'][0], '%4d%2d%d', $year, $month, $day)) {
         $created = Date::create($year, $month, $day, 0, 0, 0);
     } else {
         $created = null;
     }
     with($i = new self());
     $i->setTitle(@$iptc['2#005'][0]);
     $i->setUrgency(@$iptc['2#010'][0]);
     $i->setCategory(@$iptc['2#015'][0]);
     $i->setSupplementalCategories(@$iptc['2#020']);
     $i->setKeywords(@$iptc['2#025']);
     $i->setSpecialInstructions(@$iptc['2#040'][0]);
     $i->setDateCreated($created);
     $i->setAuthor(@$iptc['2#080'][0]);
     $i->setAuthorPosition(@$iptc['2#085'][0]);
     $i->setCity(@$iptc['2#090'][0]);
     $i->setState(@$iptc['2#095'][0]);
     $i->setCountry(@$iptc['2#101'][0]);
     $i->setOriginalTransmissionReference(@$iptc['2#103'][0]);
     $i->setHeadline(@$iptc['2#105'][0]);
     $i->setCredit(@$iptc['2#110'][0]);
     $i->setSource(@$iptc['2#115'][0]);
     $i->setCopyrightNotice(@$iptc['2#116'][0]);
     $i->setCaption(@$iptc['2#120'][0]);
     $i->setWriter(@$iptc['2#122'][0]);
     return $i;
 }
Example #8
0
 /**
  * Cast a given value
  *
  * @see     xp://scriptlet.xml.workflow.casters.ParamCaster
  * @param   array value
  * @return  array value
  */
 public function castValue($value)
 {
     $return = [];
     foreach ($value as $k => $v) {
         if ('' === $v) {
             return 'empty';
         }
         $pv = call_user_func(self::$parse, $v);
         if (!is_int($pv['year']) || !is_int($pv['month']) || !is_int($pv['day']) || 0 < $pv['warning_count'] || 0 < $pv['error_count']) {
             return 'invalid';
         }
         try {
             $date = Date::create($pv['year'], $pv['month'], $pv['day'], $pv['hour'], $pv['minute'], $pv['second']);
         } catch (\lang\IllegalArgumentException $e) {
             return $e->getMessage();
         }
         $return[$k] = $date;
     }
     return $return;
 }
 /**
  * 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;
 }
Example #10
0
 /**
  * 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');
 }
 /**
  * Setup method 
  */
 public function setUp()
 {
     $this->fixture = new MockCollection('.');
     // Warning: Changing this list will make some tests fail!
     $this->addElement($this->fixture, new MockElement('./first.txt', 1200, Date::fromString('Oct 10  2006'), Date::fromString('Dec 14  2005'), Date::fromString('Oct 30  2005')));
     $this->addElement($this->fixture, new MockElement('./second.txt', 333, Date::fromString('Oct 10  2006'), Date::fromString('Dec 24  2005'), Date::fromString('Oct 30  2005')));
     $this->addElement($this->fixture, new MockElement('./third.jpg', 18882, Date::fromString('Dec 11  2003'), Date::fromString('Dec 10  2003'), Date::fromString('Dec 10  2003')));
     $this->addElement($this->fixture, new MockElement('./zerobytes.png', 0, Date::fromString('Dec 11  2003'), Date::fromString('Dec 10  2003'), Date::fromString('Dec 10  2003')));
     with($sub = $this->addElement($this->fixture, new MockCollection('./sub')));
     $this->addElement($sub, new MockElement('./sub/IMG_6100.jpg', 531718, Date::fromString('Mar  9  2006'), Date::fromString('Mar  9  2006'), Date::fromString('Mar  9  2006')));
     $this->addElement($sub, new MockElement('./sub/IMG_6100.txt', 5932, Date::fromString('Mar 13  2006'), Date::fromString('Mar 13  2006'), Date::fromString('Mar 13  2006')));
     with($sec = $this->addElement($this->fixture, new MockCollection('./sub/sec')));
     $this->addElement($sec, new MockElement('./sub/sec/lang.base.php', 16739, Date::fromString('Oct 11  2006'), Date::fromString('Oct 11  2006'), Date::fromString('Feb 21  2002')));
     $this->addElement($sec, new MockElement('./sub/sec/__xp__.php', 8589, Date::fromString('Oct  8  2006'), Date::fromString('Oct  8  2006'), Date::fromString('Jul 23  2006')));
     // Self-check
     $this->assertEquals($this->total, array_sum($this->sizes));
 }
Example #12
0
 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 dateFormatCallbackWithoutTZ()
 {
     $date = new Date('2009-09-20 21:33:00');
     $this->assertEquals($date->toString('Y-m-d H:i:s T'), $this->runTransformation(Node::fromObject($date, 'date')->getSource(), 'xp.date::format', ['string(/date/value)', "'Y-m-d H:i:s T'"]));
 }
 function dateFunctionTest()
 {
     $date = new Date();
     $myDate = $date->toString($this->myconn->getFormatter()->dialect->dateFormat);
     $syDate = $date->toString($this->syconn->getFormatter()->dialect->dateFormat);
     $pgDate = $date->toString($this->pgconn->getFormatter()->dialect->dateFormat);
     $sqDate = $date->toString($this->sqconn->getFormatter()->dialect->dateFormat);
     $this->assertProjection('cast(sysdate() as char)', 'convert(varchar, getdate())', 'str(getdate())', 'php(\'strval\', php(\'date\', \'Y-m-d H:i:s\', php(\'time\')))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::str(SQLFunctions::getdate())));
     $this->assertProjection('cast(timestampadd(month, -4, sysdate()) as char)', 'convert(varchar, dateadd(month, -4, getdate()))', 'str(dateadd(month, -4, getdate()))', 'php(\'strval\', dateadd("m", -4, php(\'date\', \'Y-m-d H:i:s\', php(\'time\'))))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::str(SQLFunctions::dateadd('month', '-4', SQLFunctions::getdate()))));
     $this->assertProjection('timestampdiff(second, timestampadd(day, -4, sysdate()), sysdate())', 'datediff(second, dateadd(day, -4, getdate()), getdate())', 'datediff(second, dateadd(day, -4, getdate()), getdate())', 'datediff_not_implemented', create(new \rdbms\Criteria())->setProjection(SQLFunctions::datediff('second', SQLFunctions::dateadd('day', '-4', SQLFunctions::getdate()), SQLFunctions::getdate())));
     $this->assertProjection('cast(extract(hour from sysdate()) as char)', 'datename(hour, getdate())', 'datename(hour, getdate())', 'php(\'strval\', php(\'idate\', "H", php(\'strtotime\', php(\'date\', \'Y-m-d H:i:s\', php(\'time\')))))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::datename('hour', SQLFunctions::getdate())));
     $this->assertProjection('extract(hour from \'' . $myDate . '\')', 'datepart(hour, \'' . $syDate . '\')', 'datepart(hour, \'' . $pgDate . '\')', 'php(\'idate\', "H", php(\'strtotime\', \'' . $sqDate . '\'))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::datepart('hour', $date)));
 }
 public function date_accessors()
 {
     $d = Date::now();
     $this->fixture->setDate($d);
     $this->assertEquals($d, $this->fixture->getDate());
 }
 /**
  * Returns a date in the format used by MS-DOS.
  *
  * @see     http://www.vsft.com/hal/dostime.htm
  * @param   util.Date date
  * @return  int
  */
 protected function dosDate(Date $date)
 {
     return (($date->getYear() - 1980 & 0x7f) << 4 | $date->getMonth() & 0xf) << 5 | $date->getDay() & 0x1f;
 }
 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());
 }
Example #18
0
 /**
  * Get last modified date. Uses the "MDTM" command internally.
  *
  * @return  util.Date or NULL if the server does not support this
  * @throws  io.IOException in case the connection is closed
  */
 public function lastModified()
 {
     $r = $this->connection->sendCommand('MDTM %s', $this->name);
     sscanf($r[0], "%d %[^\r\n]", $code, $message);
     if (213 === $code) {
         sscanf($message, '%4d%02d%02d%02d%02d%02d', $y, $m, $d, $h, $i, $s);
         // YYYYMMDDhhmmss
         return Date::create($y, $m, $d, $h, $i, $s);
     } else {
         if (550 === $code) {
             return null;
         } else {
             throw new \peer\ProtocolException('MDTM: Unexpected response ' . $code . ': ' . $message);
         }
     }
 }
Example #19
0
 /**
  * Checks whether this date is after a given date
  *
  * @param   util.Date date
  * @return  bool
  */
 public function isAfter(Date $date)
 {
     return $this->getTime() > $date->getTime();
 }
 /**
  * Returns an IptcData instance or NULL if this image does not contain 
  * IPTC Data
  * 
  * @return img.util.IptcData
  */
 public function iptcData()
 {
     if (!($seg = $this->segmentsOf('img.io.IptcSegment'))) {
         return null;
     }
     with($data = new IptcData(), $iptc = $seg[0]->rawData());
     // Parse creation date
     if (3 == sscanf(@$iptc['2#055'][0], '%4d%2d%d', $year, $month, $day)) {
         $created = \util\Date::create($year, $month, $day, 0, 0, 0);
     } else {
         $created = null;
     }
     $data->setTitle(@$iptc['2#005'][0]);
     $data->setUrgency(@$iptc['2#010'][0]);
     $data->setCategory(@$iptc['2#015'][0]);
     $data->setSupplementalCategories(@$iptc['2#020']);
     $data->setKeywords(@$iptc['2#025']);
     $data->setSpecialInstructions(@$iptc['2#040'][0]);
     $data->setDateCreated($created);
     $data->setAuthor(@$iptc['2#080'][0]);
     $data->setAuthorPosition(@$iptc['2#085'][0]);
     $data->setCity(@$iptc['2#090'][0]);
     $data->setState(@$iptc['2#095'][0]);
     $data->setCountry(@$iptc['2#101'][0]);
     $data->setOriginalTransmissionReference(@$iptc['2#103'][0]);
     $data->setHeadline(@$iptc['2#105'][0]);
     $data->setCredit(@$iptc['2#110'][0]);
     $data->setSource(@$iptc['2#115'][0]);
     $data->setCopyrightNotice(@$iptc['2#116'][0]);
     $data->setCaption(@$iptc['2#120'][0]);
     $data->setWriter(@$iptc['2#122'][0]);
     return $data;
 }
Example #21
0
 /**
  * Translates a date from one timezone to a date of this timezone.
  * The value of the date is not changed by this operation.
  *
  * @param   util.Date date
  * @return  util.Date
  */
 public function translate(Date $date)
 {
     $handle = clone $date->getHandle();
     date_timezone_set($handle, $this->tz);
     return new Date($handle);
 }
Example #22
0
 /**
  * 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 testSetTimezone()
 {
     $this->assertEquals(\util\Date::create(2000, 1, 1, 17, 15, 11, new TimeZone('GMT')), DateUtil::setTimeZone($this->fixture, new TimeZone('America/New_York')));
 }
Example #25
0
 public function createDateFromTime()
 {
     $date = new Date('19.19');
     $this->assertEquals(strtotime('19.19'), $date->getTime());
 }
Example #26
0
 public function setDateFieldValueOnWrongObject()
 {
     $this->fixture->getField('date')->set(new Object(), 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 setValue()
 {
     with($d = Date::now());
     $this->wrapper->setValue('orderdate', $d);
     $this->assertEquals($d, $this->wrapper->getValue('orderdate'));
 }
Example #29
0
 /**
  * Convert days and seconds since 01.01.1900 to a date
  *
  * @param   int days
  * @param   int seconds
  * @return  string
  */
 protected function toDate($days, $seconds)
 {
     return Date::create(1900, 1, 1 + $days, 0, 0, $seconds / 300);
 }
 public function typeof_date_should_match_date_instance()
 {
     $this->assertTrue(Arg::anyOfType('util.Date')->matches(Date::now()));
 }