Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import event into tec without orm #156

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions includes/class-import-facebook-events-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,23 @@ public function get_utc_offset( $datetime ) {

return 'UTC' . $offset;
}

/**
* Converts a given date and time in a specific timezone to a UNIX timestamp in UTC.
*
* @param string $datetime The date and time string
* @param string $timezone The timezone of the given date and time
* @return int UNIX timestamp in UTC.
*/
public function ife_convert_to_utc_timestamp( $datetime, $timezone ) {
try {
$date = new DateTime( $datetime, new DateTimeZone( $timezone ) );
$date->setTimezone( new DateTimeZone( 'UTC' ) );
return $date->getTimestamp();
} catch ( Exception $e ) {
return 0;
}
}

/**
* Render dropdown for Imported event status.
Expand Down
22 changes: 18 additions & 4 deletions includes/class-import-facebook-events-ical_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@ public function generate_centralize_event_array( $event, $event_data = array()
$timezone = $system_timezone;
}*/

//get calendar timezone
$sstartime = $start->format( 'Y-m-d H:i:s' );
$sendtime = $end->format( 'Y-m-d H:i:s' );

if( $timezone == 'UTC' ){
$startime_utc = $sstartime;
$endtime_utc = $sendtime;
}else{
$utc_start_time = $ife_events->common->ife_convert_to_utc_timestamp( $sstartime, $timezone );
$startime_utc = date('Y-m-d H:i:s', $utc_start_time );
$end_time_utc = $ife_events->common->ife_convert_to_utc_timestamp( $sendtime, $timezone );
$endtime_utc = date('Y-m-d H:i:s', $end_time_utc );
}

$start_time = strtotime( $this->convert_datetime_to_timezone_wise_datetime( $start, $force_timezone ) );
$end_time = strtotime( $this->convert_datetime_to_timezone_wise_datetime( $end, $force_timezone ) );
/*$start_time = strtotime( $start );
Expand Down Expand Up @@ -297,8 +311,8 @@ public function generate_centralize_event_array( $event, $event_data = array()
$match = 'https://www.facebook.com/events/';
if ( strpos( $url, $match ) !== false ) {
$timezone = $wordpress_timezone;
$cwt_start = $this->convert_fb_ical_timezone( $start->format('Y-m-d H:i:s') );
$cwt_end = $this->convert_fb_ical_timezone( $end->format('Y-m-d H:i:s') );
$cwt_start = $this->convert_fb_ical_timezone( $sstartime );
$cwt_end = $this->convert_fb_ical_timezone( $sendtime );
$timezone_name = $cwt_start['timezone_name'];
$start_time = strtotime( $cwt_start['date_format'] );
$timezone_name = $cwt_end['timezone_name'];
Expand All @@ -318,8 +332,8 @@ public function generate_centralize_event_array( $event, $event_data = array()
'endtime_local' => $end_time,
'starttime' => date('Ymd\THis', $start_time),
'endtime' => date('Ymd\THis', $end_time),
'startime_utc' => '',
'endtime_utc' => '',
'startime_utc' => $startime_utc,
'endtime_utc' => $endtime_utc,
'timezone' => $timezone,
'timezone_name' => $timezone_name,
'utc_offset' => '',
Expand Down
Loading