/** * Get the i8ln value for a date using the WordPress @see date_i18n function. * * @param string $field_name The EE_Datetime_Field reference for the date being retrieved. * @param string $format PHP valid date/time string format. If none is provided then the internal set format on the object will be used. * @return string Date and time string in set locale or false if no field exists for the given * @throws \EE_Error * field name. */ public function get_i18n_datetime($field_name, $format = NULL) { $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; return date_i18n($format, EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)); }
/** * Get the i8ln value for a date using the WordPress @see date_i18n function. * * @param string $field_name The EE_Datetime_Field reference for the date being retrieved. * @param string $format PHP valid date/time string format. If none is provided then the internal set format on the object will be used. * * @return string Date and time string in set locale or false if no field exists for the given * field name. */ public function get_i18n_datetime($field_name, $format = NULL) { EE_Registry::instance()->load_helper('DTT_Helper'); $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; return date_i18n($format, EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)); }
/** * @since 4.6.12+ */ public function test_get_timestamp_with_offset() { //now in timezone currently set. $default_timezone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); $now = new DateTime("now", $default_timezone); $expected_offset = (int) $now->format('U') + (int) timezone_offset_get($default_timezone, $now); $this->assertEquals($expected_offset, EEH_DTT_Helper::get_timestamp_with_offset($now->format('U'))); //this might fail because of execution time. $this->assertEquals(current_time('timestamp'), EEH_DTT_Helper::get_timestamp_with_offset()); //now let's test with a different timezone for the incoming timestamp. $now->setTimeZone(new DateTimeZone('America/Toronto')); $expected_timestamp = (int) $now->format('U') + (int) timezone_offset_get(new DateTimeZone('America/Toronto'), $now); $this->assertEquals($expected_timestamp, EEH_DTT_Helper::get_timestamp_with_offset($now->format('U'), 'America/Toronto')); }