| Server IP : 47.82.179.145 / Your IP : 216.73.217.129 Web Server : nginx/1.26.3 System : Linux iZt4n9czhka2zvqfajdlr2Z 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64 User : www ( 1001) PHP Version : 8.3.30 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/scuipturepactory.com/wp-content/plugins.off/latepoint/lib/helpers/ |
Upload File : |
<?php
class OsWpDateTime extends DateTime {
function __construct(?string $time = 'now', ?DateTimeZone $timezone = null){
$timezone = ($timezone instanceof DateTimeZone) ? $timezone : OsTimeHelper::get_wp_timezone();
try{
if(empty($time)) $time = 'now';
parent::__construct($time, $timezone);
}catch(Exception $e){
OsDebugHelper::log('Error parsing date: '.$e->getMessage() , 'date_parsing' );
return parent::__construct('now', $timezone);
}
}
public static function datetime_in_utc(DateTime $datetime, $format = false){
$utc_datetime = clone $datetime;
$utc_datetime->setTimezone(new DateTimeZone("UTC"));
return $format ? $utc_datetime->format($format) : $utc_datetime;
}
public static function date_to_db_format($date_string, $default = ''){
if(empty($date_string)) return $default;
try{
$date = self::os_createFromFormat(OsSettingsHelper::get_date_format(), $date_string);
return $date->format('Y-m-d');
}catch(Exception $e){
return $default;
}
}
public static function date_from_db_format($date_string, $default = ''){
if(empty($date_string)) return $default;
try{
$timezone = new DateTimeZone('UTC');
$date = self::os_createFromFormat('Y-m-d', $date_string, $timezone);
return $date->format(OsSettingsHelper::get_date_format());
}catch(Exception $e){
return $default;
}
}
public static function os_createFromFormat($format, $datetime_string, $timezone = false){
$timezone = ($timezone) ? $timezone : OsTimeHelper::get_wp_timezone();
return self::createFromFormat($format, $datetime_string, $timezone);
}
// TODO will be deprecated, moved to GCal addon
public static function os_get_start_of_google_event($google_event){
if(!empty($google_event->start->dateTime)){
$date_string = $google_event->start->dateTime;
$date_format = \DateTime::RFC3339;
$timezone = new DateTimeZone($google_event->start->timeZone);
}else{
// Full day event
$date_string = $google_event->start->date.' 00:00:00';
$date_format = LATEPOINT_DATETIME_DB_FORMAT;
$timezone = false;
}
return self::os_createFromFormat($date_format, $date_string, $timezone);
}
// TODO will be deprecated, moved to GCal addon
public static function os_get_end_of_google_event($google_event){
if(!empty($google_event->end->dateTime)){
$date_string = $google_event->end->dateTime;
$date_format = \DateTime::RFC3339;
return self::os_createFromFormat($date_format, $date_string);
}else{
// Full day event
// !important, in full day events of Google Calendar - start day is inclusive and the end day is exclusive https://stackoverflow.com/questions/34992747/google-calendar-json-api-full-day-events-always-one-day-longer
$date_string = $google_event->end->date.' 23:59:59';
$date_format = LATEPOINT_DATETIME_DB_FORMAT;
$temp_date = self::os_createFromFormat($date_format, $date_string);
// move back 1 day to accomodate Google rule that end date is 1 day ahead of actual end date of a full day event
$temp_date->modify('-1 day');
return $temp_date;
}
}
}