Esempio n. 1
0
 public function __construct($year, $month, $day, $hour = 0, $min = 0, $sec = 0)
 {
     parent::__construct($year, $month, $day);
     $this->hour = $hour;
     $this->min = $min;
     $this->sec = $sec;
 }
Esempio n. 2
0
 public function stringToDate($data)
 {
     if (get_class($data) == 'SDate') {
         return $data;
     }
     try {
         $date = SDate::parse($data);
     } catch (Exception $e) {
         return null;
     }
     return $date;
 }
Esempio n. 3
0
 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'));
 }
 function testSaveWithTimestamps()
 {
     $created_date = new SDateTime(2005, 12, 01, 20, 30, 00);
     $post = SActiveStore::findByPk('Post', 2);
     $this->assertIsA($post->created_on, 'SDateTime');
     $this->assertEqual($created_date, $post->created_on);
     $this->assertEqual($post->created_on, $post->updated_on);
     $post->text = 'blo blo blo';
     $post->save();
     $this->assertNotEqual($post->created_on, $post->updated_on);
     $today = SDate::today();
     $new_post = new Post(array('title' => 'Timestamps and MySQL', 'author' => 'Goldoraf', 'text' => 'ttttt'));
     $this->assertNull($new_post->created_on);
     $this->assertNull($new_post->updated_on);
     $new_post->save();
     $this->assertIsA($new_post->created_on, 'SDateTime');
     $this->assertIsA($new_post->created_on, 'SDateTime');
     $this->assertEqual($new_post->created_on, $new_post->updated_on);
     $this->assertEqual($today->year, $new_post->created_on->year);
     $this->assertEqual($today->month, $new_post->created_on->month);
     $this->assertEqual($today->day, $new_post->created_on->day);
 }
 public static function formatted_datetime($value)
 {
     $str = SDate::datetime_to_string($value);
     if ($str == '') {
         return array('', '');
     }
     return explode(' ', $str);
 }
Esempio n. 6
0
function select_year($date, $options = array())
{
    $yearOptions = '';
    $today = SDate::today();
    if (!isset($options['start_year'])) {
        $options['start_year'] = $today->year - 5;
    }
    if (!isset($options['end_year'])) {
        $options['end_year'] = $today->year + 5;
    }
    $step = $options['start_year'] < $options['end_year'] ? 1 : -1;
    $selected = is_date_type($date) ? $date->year : $date;
    for ($i = $options['start_year']; $i != $options['end_year'] + $step; $i = $i + $step) {
        if ($i == $selected) {
            $yearOptions .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n";
        } else {
            $yearOptions .= "<option value=\"{$i}\">{$i}</option>\n";
        }
    }
    if (!isset($options['field_name'])) {
        $options['field_name'] = 'year';
    }
    return select_html($options['field_name'], $yearOptions, $options);
}