public function stringToDateTime($data)
 {
     if (get_class($data) == 'SDateTime') {
         return $data;
     }
     try {
         $date = SDateTime::parse($data);
     } catch (Exception $e) {
         return null;
     }
     return $date;
 }
function select_time($datetime = Null, $options = array())
{
    if ($datetime == Null) {
        $datetime = SDateTime::today();
    }
    $order = isset($options['order']) ? $options['order'] : array('hour', 'minute', 'second');
    $html = '';
    foreach ($order as $param) {
        $html .= call_user_func('select_' . $param, $datetime, $options);
    }
    return $html;
    //return select_hour($datetime, $options).select_minute($datetime, $options).select_second($datetime, $options);
}
Beispiel #3
0
    *     不同的参数类型,决定了这个函数拥有功能丰富的日期/时间处理能力
    */
    static function secondToDate($second)
    {
        $sec = abs((int) $second);
        $begin = new DateTime("@0");
        $end = new DateTime("@{$sec}");
        $res = $begin->diff($end)->format('%a 天,%h 小时,%i 分 , %s 秒');
        return $res;
    }
    /*
    * 人类可读时间转秒数
    *
    * param :$date 人类可读日期  
    * 
    */
    static function DateToSecond($date)
    {
        $t = strtotime($date);
    }
}
// 日期转秒数
// 测试 秒数转可读日期
$ti = 1446538971;
$ti = 1446032094.335;
$ri = date('Y-m-d', $ti);
var_dump($ri);
$ss = SDateTime::secondToDate($ti);
var_dump($ss);
$time = microtime();
var_dump($time);
 public static function typecast($xmlString)
 {
     try {
         $xml = new SimpleXMLElement($xmlString);
     } catch (Exception $e) {
         throw new SXmlRpcValueException("Failed to typecast XML value : {$xmlString}");
     }
     list($type, $value) = each($xml);
     if (!$type) {
         $type = 'string';
     }
     switch ($type) {
         case 'i4':
         case 'int':
             return (int) $value;
             break;
         case 'double':
             return (double) $value;
             break;
         case 'boolean':
             return $value == 1;
             break;
         case 'string':
             return $value;
             break;
         case 'dateTime.iso8601':
             return SDateTime::parse($value);
             break;
         case 'base64':
             break;
         case 'array':
             if (!$value instanceof SimpleXMLElement) {
                 throw new SXmlRpcValueException('Invalid XML string for array type');
             }
             $values = array();
             foreach ($value->data->value as $element) {
                 $values[] = self::typecast($element->asXML());
             }
             return $values;
             break;
         case 'struct':
             if (!$value instanceof SimpleXMLElement) {
                 throw new SXmlRpcValueException('Invalid XML string for struct type');
             }
             $values = array();
             foreach ($value->member as $member) {
                 if (!$member->value instanceof SimpleXMLElement || empty($member->value)) {
                     throw new SXmlRpcValueException('Member of a struct must contain a <value> tag');
                 }
                 $values[(string) $member->name] = self::typecast($member->value->asXML());
             }
             return $values;
             break;
         default:
             throw new SXmlRpcValueException("{$type} is not a native XML-RPC type");
             break;
     }
 }
 public function testParsing()
 {
     $this->assertEqual(new SDate(1969, 7, 21), SDate::parse('1969-07-21'));
     $this->assertEqual(new SDateTime(1969, 7, 21, 20, 35, 05), SDateTime::parse('19690721T20:35:05'));
     $this->assertEqual(new SDateTime(1969, 7, 21, 20, 35, 05), SDateTime::parse('1969-07-21 20:35:05'));
 }
 public function testMigratorGoingDownDueToVersionTarget()
 {
     SMigrator::up(dirname(__FILE__) . '/fixtures/migrate', 1);
     SMigrator::migrate(dirname(__FILE__) . '/fixtures/migrate', 0);
     $this->assertFalse(in_array('last_name', array_keys(SActiveRecord::connection()->columns('people'))));
     $this->assertFalse(SActiveStore::tableExists('reminders'));
     SMigrator::migrate(dirname(__FILE__) . '/fixtures/migrate');
     $this->assertEqual(2, SMigrator::currentVersion());
     SActiveStore::resetAttributeInformation('people');
     $this->assertTrue(in_array('last_name', array_keys(SActiveRecord::connection()->columns('people'))));
     $r = new Reminder(array('content' => 'hello world', 'remind_at' => SDateTime::today()));
     $r->save();
     $this->assertEqual('hello world', SActiveStore::findFirst('reminder')->content);
 }
 private function logProcessing()
 {
     $log = 'Processing ' . $this->controllerClassName() . '::' . $this->actionName() . '() for ' . $this->request->remoteIp() . ' at ' . SDateTime::today()->__toString() . ' [' . $this->request->method() . ']';
     if (($sessId = $this->session->sessionId()) != '') {
         $log .= "\n    Session ID: " . $sessId;
     }
     $log .= "\n    Parameters: " . serialize($this->params) . "\n";
     $this->logger->info($log);
 }
 protected function saveWithTimestamps()
 {
     $t = SDateTime::today();
     if ($this->isNewRecord()) {
         if ($this->attrExists('created_on')) {
             $this->values['created_on'] = $t->__toString();
         }
     }
     if ($this->attrExists('updated_on')) {
         $this->values['updated_on'] = $t->__toString();
     }
 }