/**
  *		create new blank datetime
  *
  * 		@access		public
  *		@return 		EE_Datetime[]		array on success, FALSE on fail
  */
 public function create_new_blank_datetime()
 {
     $blank_datetime = EE_Datetime::new_instance(array('DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + 60 * 60 * 24 * 30, 'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + 60 * 60 * 24 * 30, 'DTT_order' => 1, 'DTT_reg_limit' => EE_INF), $this->_timezone);
     $blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga', $this->_timezone));
     $blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $this->_timezone));
     return array($blank_datetime);
 }
 /**
  *		create new blank datetime
  *
  * 		@access		public
  *		@return 		EE_Datetime[]		array on success, FALSE on fail
  */
 public function create_new_blank_datetime()
 {
     $times = array(EE_Datetime::new_instance(array('DTT_EVT_start' => time('timestamp') + 60 * 60 * 24 * 30, 'DTT_EVT_end' => time('timestamp') + 60 * 60 * 24 * 30, 'DTT_order' => 1, 'DTT_reg_limit' => INF)));
     $times[0]->set_start_time("8am");
     $times[0]->set_end_time("5pm");
     return $times;
 }
 function test_finalize()
 {
     $t = EE_Transaction::new_instance(array('STS_ID' => EEM_Transaction::complete_status_code));
     $t->save();
     $e = EE_Event::new_instance();
     $e->save();
     $tkt = EE_Ticket::new_instance();
     $tkt->save();
     $d = EE_Datetime::new_instance(array('EVT_ID' => $e->ID()));
     $d->save();
     $tkt->_add_relation_to($d, 'Datetime');
     /** @type EE_Registration_Processor $registration_processor */
     $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
     $reg_url = $registration_processor->generate_reg_url_link(1, EE_Line_Item::new_instance(array('LIN_name' => $tkt->name(), 'LIN_desc' => $tkt->description(), 'LIN_unit_price' => $tkt->price(), 'LIN_quantity' => 1, 'LIN_is_taxable' => $tkt->taxable(), 'LIN_order' => 0, 'LIN_total' => $tkt->price(), 'LIN_type' => EEM_Line_Item::type_line_item, 'OBJ_ID' => $tkt->ID(), 'OBJ_type' => 'Ticket')));
     $r = EE_REgistration::new_instance(array('EVT_ID' => $e->ID(), 'TXN_ID' => $t->ID(), 'TKT_ID' => $tkt->ID(), 'STS_ID' => EEM_Registration::status_id_pending_payment, 'REG_url_link' => $reg_url));
     $r->set_reg_code($registration_processor->generate_reg_code($r));
     $registration_processor->update_registration_after_checkout_or_payment($r);
     $this->assertNotNull($r->reg_code());
     $this->assertEquals(EEM_Registration::status_id_approved, $r->status_ID());
 }
 function test_ticket_status()
 {
     $t = EE_Ticket::new_instance(array('TKT_start_date' => current_time('timestamp') - 100, 'TKT_end_date' => current_time('timestamp') + 100, 'TKT_qty' => 10, 'TKT_sold' => 0, 'TKT_deleted' => TRUE));
     $t->save();
     $d = EE_Datetime::new_instance();
     $d->save();
     $t->_add_relation_to($d, 'Datetime');
     $this->assertEquals(EE_Ticket::archived, $t->ticket_status());
     $t->set('TKT_deleted', FALSE);
     $this->assertEquals(EE_Ticket::onsale, $t->ticket_status());
     $t->set('TKT_sold', 10);
     $this->assertEquals(EE_Ticket::sold_out, $t->ticket_status());
     $t->set('TKT_sold', 0);
     $d->set_reg_limit(10);
     $d->save();
     $t->set('TKT_start_date', current_time('timestamp') + 50);
     $this->assertEquals(EE_Ticket::pending, $t->ticket_status());
     $t->set('TKT_start_date', current_time('timestamp') - 100);
     $t->set('TKT_end_date', current_time('timestamp') - 50);
     $this->assertEquals(EE_Ticket::expired, $t->ticket_status());
 }
 /**
  * used by factory to create datetime object
  *
  * @since 4.3.0
  *
  * @param array $args Incoming field values to set on the new object
  *
  * @return EE_Datetime|false
  */
 public function create_object($args)
 {
     $this->_special_args['EVT_ID'] = isset($args['EVT_ID']) ? $args['EVT_ID'] : 0;
     if (isset($args['EVT_ID'])) {
         unset($args['EVT_ID']);
     }
     //timezone?
     if (isset($args['timezone'])) {
         $timezone = $args['timezone'];
         unset($args['timezone']);
     } else {
         $timezone = null;
     }
     //date formats?
     if (isset($args['formats']) && is_array($args['formats'])) {
         $formats = $args['formats'];
         unset($args['formats']);
     } else {
         $formats = array();
     }
     $dtt = EE_Datetime::new_instance($args, $timezone, $formats);
     $dttID = $dtt->save();
     $dtt = $this->_maybe_chained($dtt, $args);
     return $dttID ? $dtt : false;
 }
 function test_get_number_of_tickets_sold()
 {
     $e = EE_Event::new_instance();
     $e->save();
     $d_now = EE_Datetime::new_instance(array('EVT_ID' => $e->ID(), 'DTT_EVT_start' => time() - 100, 'DTT_EVT_end' => time() - 50, 'DTT_sold' => 5));
     $d_now->save();
     $d_exp = EE_Datetime::new_instance(array('EVT_ID' => $e->ID(), 'DTT_EVT_start' => time() - 10, 'DTT_EVT_end' => time() - 5, 'DTT_sold' => 15));
     $d_exp->save();
     $this->assertEquals(20, $e->get_number_of_tickets_sold());
     $e->_remove_relation_to($d_now, 'Datetime');
     $this->assertEquals(15, $e->get_number_of_tickets_sold());
 }
 function test_get_dtt_display_name()
 {
     //test using actual dates because now could result in different results depending on what time of day it is
     $base_date = date_create_from_format('Y-m-d H:i:s', '2015-01-01 00:00:00');
     $testing_date = clone $base_date;
     //setup datetime with different months for start and end dates.
     $testing_date->add(new DateInterval('P1M'));
     $d = EE_Datetime::new_instance(array('DTT_name' => 'monkey time', 'DTT_EVT_start' => $base_date->format('U'), 'DTT_EVT_end' => $testing_date->format('U')));
     $d->set_date_format('Y-m-d');
     $d->set_time_format('h:i a');
     $this->assertEquals($base_date->format('M j\\, Y g:i a') . ' - ' . $testing_date->format('M j\\, Y g:i a'), $d->get_dtt_display_name());
     $this->assertEquals('monkey time', $d->get_dtt_display_name(true));
     //setup datetime with start date and end date with same month but different days.
     $testing_date->sub(new DateInterval('P15D'));
     $d = EE_Datetime::new_instance(array('DTT_name' => 'monkey time', 'DTT_EVT_start' => $base_date->format('U'), 'DTT_EVT_end' => $testing_date->format('U')));
     $d->set_date_format('Y-m-d');
     $d->set_time_format('h:i a');
     $this->assertEquals($base_date->format('M j\\, g:i a') . ' - ' . $testing_date->format('M j\\, g:i a Y'), $d->get_dtt_display_name());
     //setup datetime with start date and end date the same day but different times.
     $testing_date = clone $base_date;
     $testing_date->add(new DateInterval('PT1H'));
     $d = EE_Datetime::new_instance(array('DTT_name' => 'monkey time', 'DTT_EVT_start' => $base_date->format('U'), 'DTT_EVT_end' => $testing_date->format('U')));
     $d->set_date_format('Y-m-d');
     $d->set_time_format('h:i a');
     $this->assertEquals($base_date->format('F j\\, Y') . ' @ ' . $base_date->format('g:i a') . ' - ' . $testing_date->format('g:i a'), $d->get_dtt_display_name());
 }
 function test_datetime_display()
 {
     $d = EE_Datetime::new_instance(array('DTT_name' => 'monkey time', 'DTT_EVT_start' => 1234567, 'DTT_EVT_end' => 23456781));
     $this->assertEquals('Jan 15, 1970 6:56 am - Sep 29, 1970 11:46 am', $d->get_dtt_display_name());
     $this->assertEquals('monkey time', $d->get_dtt_display_name(true));
 }
 /**
  * used by factory to create datetime object
  *
  * @since 4.3.0
  *
  * @param array  $args Incoming field values to set on the new object
  *
  * @return EE_Datetime|false
  */
 public function create_object($args)
 {
     $this->_special_args['EVT_ID'] = isset($args['EVT_ID']) ? $args['EVT_ID'] : 0;
     if (isset($args['EVT_ID'])) {
         unset($args['EVT_ID']);
     }
     $dtt = EE_Datetime::new_instance($args);
     $dttID = $dtt->save();
     $dtt = $this->_maybe_chained($dtt, $args);
     return $dttID ? $dtt : false;
 }
 /**
  * 	 _date_time_modifier_tests
  *
  * @param bool $increment_datetimes
  */
 protected function _date_time_modifier_tests($increment_datetimes = true)
 {
     $orig_timezone_string = get_option('timezone_string');
     $orig_gmt_offset = get_option('gmt_offset');
     // setup data arrays for generating test conditions
     $timezones_and_offsets = array('UTC' => '', 'America/Vancouver' => '', null => -5);
     $periods = array('years' => 'P%Y', 'months' => 'P%M', 'weeks' => 'P%W', 'days' => 'P%D', 'hours' => 'PT%H', 'minutes' => 'PT%M', 'seconds' => 'PT%S');
     // I can not tell a Fib... the following sequence is for Sidney
     $intervals = array(0, 1, 2, 3, 5, 8, 13, 21, 34);
     // loop thru timezones and gmt_offsets and set up environment
     foreach ($timezones_and_offsets as $timezone_string => $gmt_offset) {
         $gmt_offset = $gmt_offset !== 'null' ? $gmt_offset : '';
         update_option('timezone_string', $timezone_string);
         update_option('gmt_offset', $gmt_offset);
         // loop thru remaining data arrays
         foreach ($periods as $period => $designator) {
             foreach ($intervals as $interval) {
                 // don't bother adding more than 5 years
                 if ($period == 'years' && $interval > 5) {
                     continue;
                 }
                 // TEST: add $interval $period ( ie: add 1 year...  add 3 months...  add 34 seconds )
                 // setup some objects used for testing
                 $expected_datetime = $this->setup_DateTime_object();
                 $actual_datetime = EE_Datetime::new_instance(array('DTT_EVT_start' => time()));
                 $expected_datetime->setTimeZone(new DateTimeZone($actual_datetime->get_timezone()));
                 $period_interval = str_replace('%', $interval, $designator);
                 // apply conditions to both objects
                 if ($increment_datetimes) {
                     $expected_datetime->add(new DateInterval($period_interval));
                     $actual_datetime = EEH_DTT_Helper::date_time_add($actual_datetime, 'DTT_EVT_start', $period, $interval);
                 } else {
                     $expected_datetime->sub(new DateInterval($period_interval));
                     $actual_datetime = EEH_DTT_Helper::date_time_subtract($actual_datetime, 'DTT_EVT_start', $period, $interval);
                 }
                 $expected = $expected_datetime->format('Y-m-d H:i:s');
                 $actual = $actual_datetime->get_DateTime_object('DTT_EVT_start')->format('Y-m-d H:i:s');
                 // compare
                 if ($expected !== $actual) {
                     $this->fail(sprintf(__('The %1$s method failed to produce correct results for the the period interval %2$s for timezone "%6$s" and UTC offset "%7$s" .%3$sExpected value: %4$s%3$sActual value: %5$s%3$s', 'event_espresso'), $increment_datetimes ? 'EEH_DTT_Helper::date_time_add()' : 'EEH_DTT_Helper::date_time_subtract()', $period_interval, "\n", $expected, $actual, $timezone_string, $gmt_offset));
                 }
                 unset($expected_datetime);
                 unset($actual_datetime);
             }
         }
     }
     update_option('timezone_string', $orig_timezone_string);
     update_option('gmt_offset', $orig_gmt_offset);
 }