Skip to content

Commit

Permalink
Merge pull request #10818 from MrPetovan/task/10691-remove-event-adjust
Browse files Browse the repository at this point in the history
Display the current timezone in date time picker fields
  • Loading branch information
annando committed Oct 3, 2021
2 parents dd3f573 + 64e4af2 commit caa1a5a
Show file tree
Hide file tree
Showing 38 changed files with 662 additions and 710 deletions.
5 changes: 1 addition & 4 deletions database.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2021.12-dev (Siberian Iris)
-- DB_UPDATE_VERSION 1435
-- DB_UPDATE_VERSION 1436
-- ------------------------------------------


Expand Down Expand Up @@ -565,7 +565,6 @@ CREATE TABLE IF NOT EXISTS `event` (
`location` text COMMENT 'event location',
`type` varchar(20) NOT NULL DEFAULT '' COMMENT 'event or birthday',
`nofinish` boolean NOT NULL DEFAULT '0' COMMENT 'if event does have no end this is 1',
`adjust` boolean NOT NULL DEFAULT '1' COMMENT 'adjust to timezone of the recipient (0 or 1)',
`ignore` boolean NOT NULL DEFAULT '0' COMMENT '0 or 1',
`allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
`allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
Expand Down Expand Up @@ -1699,7 +1698,6 @@ CREATE VIEW `post-user-view` AS SELECT
`event`.`location` AS `event-location`,
`event`.`type` AS `event-type`,
`event`.`nofinish` AS `event-nofinish`,
`event`.`adjust` AS `event-adjust`,
`event`.`ignore` AS `event-ignore`,
`diaspora-interaction`.`interaction` AS `signed_text`,
`parent-item-uri`.`guid` AS `parent-guid`,
Expand Down Expand Up @@ -1860,7 +1858,6 @@ CREATE VIEW `post-thread-user-view` AS SELECT
`event`.`location` AS `event-location`,
`event`.`type` AS `event-type`,
`event`.`nofinish` AS `event-nofinish`,
`event`.`adjust` AS `event-adjust`,
`event`.`ignore` AS `event-ignore`,
`diaspora-interaction`.`interaction` AS `signed_text`,
`parent-item-uri`.`guid` AS `parent-guid`,
Expand Down
6 changes: 0 additions & 6 deletions doc/API-Entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,6 @@ Ex: Wed May 23 06:01:13 +0000 2007
<td>Optional. Location.</td>
</tr>

<tr>
<td><code>adjust</code></td>
<td>Boolean</td>
<td>???</td>
</tr>

<tr>
<td><code>ignore</code></td>
<td>Boolean</td>
Expand Down
1 change: 0 additions & 1 deletion doc/database/db_event.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Fields
| location | event location | text | YES | | NULL | |
| type | event or birthday | varchar(20) | NO | | | |
| nofinish | if event does have no end this is 1 | boolean | NO | | 0 | |
| adjust | adjust to timezone of the recipient (0 or 1) | boolean | NO | | 1 | |
| ignore | 0 or 1 | boolean | NO | | 0 | |
| allow_cid | Access Control - list of allowed contact.id '<19><78>' | mediumtext | YES | | NULL | |
| allow_gid | Access Control - list of allowed groups | mediumtext | YES | | NULL | |
Expand Down
5 changes: 0 additions & 5 deletions doc/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ The finishing date/time has to be after the beginning date/time of the event.
But you don't have to specify it.
If the event is open-ended or the finishing date/time does not matter, just select the box below the two first fields.

* **Adjust for viewer timezone**: If you check this box, the beginning and finishing times will automatically converted to the local time according to the timezone setting

This might prevent early birthday wishes, or the panic that you have forgotten the birthday from your buddy at the other side of the world.
And similar events.

* **Title**: a title for the event
* **Description**: a longer description for the event
* **Location**: the location the event will took place
Expand Down
11 changes: 1 addition & 10 deletions mod/cal.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,11 @@ function cal_content(App $a)
$start = DateTimeFormat::utc($start);
$finish = DateTimeFormat::utc($finish);

$adjust_start = DateTimeFormat::local($start);
$adjust_finish = DateTimeFormat::local($finish);

// put the event parametes in an array so we can better transmit them
$event_params = [
'event_id' => intval($_GET['id'] ?? 0),
'start' => $start,
'finish' => $finish,
'adjust_start' => $adjust_start,
'adjust_finish' => $adjust_finish,
'ignore' => $ignored,
];

Expand All @@ -210,7 +205,7 @@ function cal_content(App $a)
if (DBA::isResult($r)) {
$r = Event::sortByDate($r);
foreach ($r as $rr) {
$j = $rr['adjust'] ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j');
$j = DateTimeFormat::local($rr['start'], 'j');
if (empty($links[$j])) {
$links[$j] = DI::baseUrl() . '/' . DI::args()->getCommand() . '#link-' . $j;
}
Expand All @@ -229,11 +224,7 @@ function cal_content(App $a)
if (!empty($_GET['id'])) {
$tpl = Renderer::getMarkupTemplate("event.tpl");
} else {
// if (DI::config()->get('experimentals','new_calendar')==1){
$tpl = Renderer::getMarkupTemplate("events_js.tpl");
// } else {
// $tpl = Renderer::getMarkupTemplate("events.tpl");
// }
}

// Get rid of dashes in key names, Smarty3 can't handle them
Expand Down
77 changes: 14 additions & 63 deletions mod/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ function events_init(App $a)
return;
}

// If it's a json request abort here because we don't
// need the widget data
if (DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] === 'json') {
return;
}

if (empty(DI::page()['aside'])) {
DI::page()['aside'] = '';
}
Expand All @@ -80,7 +74,6 @@ function events_post(App $a)
$start_text = Strings::escapeHtml($_REQUEST['start_text'] ?? '');
$finish_text = Strings::escapeHtml($_REQUEST['finish_text'] ?? '');

$adjust = intval($_POST['adjust'] ?? 0);
$nofinish = intval($_POST['nofinish'] ?? 0);

$share = intval($_POST['share'] ?? 0);
Expand All @@ -99,16 +92,9 @@ function events_post(App $a)
$finish = $finish_text;
}

if ($adjust) {
$start = DateTimeFormat::convert($start, 'UTC', date_default_timezone_get());
if (!$nofinish) {
$finish = DateTimeFormat::convert($finish, 'UTC', date_default_timezone_get());
}
} else {
$start = DateTimeFormat::utc($start);
if (!$nofinish) {
$finish = DateTimeFormat::utc($finish);
}
$start = DateTimeFormat::convert($start, 'UTC', $a->getTimeZone());
if (!$nofinish) {
$finish = DateTimeFormat::convert($finish, 'UTC', $a->getTimeZone());
}

// Don't allow the event to finish before it begins.
Expand All @@ -127,7 +113,6 @@ function events_post(App $a)
'location' => $location,
'start' => $start_text,
'finish' => $finish_text,
'adjust' => $adjust,
'nofinish' => $nofinish,
];

Expand Down Expand Up @@ -196,7 +181,6 @@ function events_post(App $a)
$datarray['desc'] = $desc;
$datarray['location'] = $location;
$datarray['type'] = $type;
$datarray['adjust'] = $adjust;
$datarray['nofinish'] = $nofinish;
$datarray['uid'] = $uid;
$datarray['cid'] = $cid;
Expand Down Expand Up @@ -331,28 +315,11 @@ function events_content(App $a)
$start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
$finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);

if (DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] === 'json') {
if (!empty($_GET['start'])) {
$start = $_GET['start'];
}
if (!empty($_GET['end'])) {
$finish = $_GET['end'];
}
}

$start = DateTimeFormat::utc($start);
$finish = DateTimeFormat::utc($finish);

$adjust_start = DateTimeFormat::local($start);
$adjust_finish = DateTimeFormat::local($finish);

// put the event parametes in an array so we can better transmit them
$event_params = [
'event_id' => intval($_GET['id'] ?? 0),
'start' => $start,
'finish' => $finish,
'adjust_start' => $adjust_start,
'adjust_finish' => $adjust_finish,
'ignore' => $ignored,
];

Expand All @@ -368,7 +335,7 @@ function events_content(App $a)
if (DBA::isResult($r)) {
$r = Event::sortByDate($r);
foreach ($r as $rr) {
$j = $rr['adjust'] ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j');
$j = DateTimeFormat::local($rr['start'], 'j');
if (empty($links[$j])) {
$links[$j] = DI::baseUrl() . '/' . DI::args()->getCommand() . '#link-' . $j;
}
Expand All @@ -383,12 +350,6 @@ function events_content(App $a)
$events = Event::prepareListForTemplate($r);
}

if (DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] === 'json') {
header('Content-Type: application/json');
echo json_encode($events);
exit();
}

if (!empty($_GET['id'])) {
$tpl = Renderer::getMarkupTemplate("event.tpl");
} else {
Expand Down Expand Up @@ -457,15 +418,13 @@ function events_content(App $a)

// In case of an error the browser is redirected back here, with these parameters filled in with the previous values
if (!empty($_REQUEST['nofinish'])) {$orig_event['nofinish'] = $_REQUEST['nofinish'];}
if (!empty($_REQUEST['adjust'])) {$orig_event['adjust'] = $_REQUEST['adjust'];}
if (!empty($_REQUEST['summary'])) {$orig_event['summary'] = $_REQUEST['summary'];}
if (!empty($_REQUEST['desc'])) {$orig_event['desc'] = $_REQUEST['desc'];}
if (!empty($_REQUEST['location'])) {$orig_event['location'] = $_REQUEST['location'];}
if (!empty($_REQUEST['start'])) {$orig_event['start'] = $_REQUEST['start'];}
if (!empty($_REQUEST['finish'])) {$orig_event['finish'] = $_REQUEST['finish'];}

$n_checked = (!empty($orig_event['nofinish']) ? ' checked="checked" ' : '');
$a_checked = (!empty($orig_event['adjust']) ? ' checked="checked" ' : '');

$t_orig = $orig_event['summary'] ?? '';
$d_orig = $orig_event['desc'] ?? '';
Expand All @@ -481,24 +440,19 @@ function events_content(App $a)
$sdt = $orig_event['start'] ?? 'now';
$fdt = $orig_event['finish'] ?? 'now';

$tz = date_default_timezone_get();
if (isset($orig_event['adjust'])) {
$tz = ($orig_event['adjust'] ? date_default_timezone_get() : 'UTC');
}

$syear = DateTimeFormat::convert($sdt, $tz, 'UTC', 'Y');
$smonth = DateTimeFormat::convert($sdt, $tz, 'UTC', 'm');
$sday = DateTimeFormat::convert($sdt, $tz, 'UTC', 'd');
$syear = DateTimeFormat::local($sdt, 'Y');
$smonth = DateTimeFormat::local($sdt, 'm');
$sday = DateTimeFormat::local($sdt, 'd');

$shour = !empty($orig_event) ? DateTimeFormat::convert($sdt, $tz, 'UTC', 'H') : '00';
$sminute = !empty($orig_event) ? DateTimeFormat::convert($sdt, $tz, 'UTC', 'i') : '00';
$shour = !empty($orig_event) ? DateTimeFormat::local($sdt, 'H') : '00';
$sminute = !empty($orig_event) ? DateTimeFormat::local($sdt, 'i') : '00';

$fyear = DateTimeFormat::convert($fdt, $tz, 'UTC', 'Y');
$fmonth = DateTimeFormat::convert($fdt, $tz, 'UTC', 'm');
$fday = DateTimeFormat::convert($fdt, $tz, 'UTC', 'd');
$fyear = DateTimeFormat::local($fdt, 'Y');
$fmonth = DateTimeFormat::local($fdt, 'm');
$fday = DateTimeFormat::local($fdt, 'd');

$fhour = !empty($orig_event) ? DateTimeFormat::convert($fdt, $tz, 'UTC', 'H') : '00';
$fminute = !empty($orig_event) ? DateTimeFormat::convert($fdt, $tz, 'UTC', 'i') : '00';
$fhour = !empty($orig_event) ? DateTimeFormat::local($fdt, 'H') : '00';
$fminute = !empty($orig_event) ? DateTimeFormat::local($fdt, 'i') : '00';

if (!$cid && in_array($mode, ['new', 'copy'])) {
$acl = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($orig_event));
Expand Down Expand Up @@ -549,8 +503,6 @@ function events_content(App $a)
true,
'start_text'
),
'$a_text' => DI::l10n()->t('Adjust for viewer timezone'),
'$a_checked' => $a_checked,
'$d_text' => DI::l10n()->t('Description:'),
'$d_orig' => $d_orig,
'$l_text' => DI::l10n()->t('Location:'),
Expand All @@ -562,7 +514,6 @@ function events_content(App $a)
'$share' => ['share', DI::l10n()->t('Share this event'), $share_checked, '', $share_disabled],
'$sh_checked' => $share_checked,
'$nofinish' => ['nofinish', DI::l10n()->t('Finish date/time is not known or not relevant'), $n_checked],
'$adjust' => ['adjust', DI::l10n()->t('Adjust for viewer timezone'), $a_checked],
'$preview' => DI::l10n()->t('Preview'),
'$acl' => $acl,
'$submit' => DI::l10n()->t('Submit'),
Expand Down
2 changes: 1 addition & 1 deletion mod/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ function item_post(App $a) {
Hook::callAll('post_local',$datarray);

if (!empty($_REQUEST['scheduled_at'])) {
$scheduled_at = DateTimeFormat::convert($_REQUEST['scheduled_at'], 'UTC', $a->getTimezone());
$scheduled_at = DateTimeFormat::convert($_REQUEST['scheduled_at'], 'UTC', $a->getTimeZone());
if ($scheduled_at > DateTimeFormat::utcNow()) {
unset($datarray['created']);
unset($datarray['edited']);
Expand Down
6 changes: 3 additions & 3 deletions mod/ping.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function ping_init(App $a)
$ev = DI::cache()->get($cachekey);
if (is_null($ev)) {
$ev = q(
"SELECT type, start, adjust FROM `event`
"SELECT type, start FROM `event`
WHERE `event`.`uid` = %d AND `start` < '%s' AND `finish` > '%s' and `ignore` = 0
ORDER BY `start` ASC ",
intval(local_user()),
Expand All @@ -230,7 +230,7 @@ function ping_init(App $a)
$all_events = count($ev);

if ($all_events) {
$str_now = DateTimeFormat::timezoneNow($a->getTimeZone(), 'Y-m-d');
$str_now = DateTimeFormat::localNow('Y-m-d');
foreach ($ev as $x) {
$bd = false;
if ($x['type'] === 'birthday') {
Expand All @@ -239,7 +239,7 @@ function ping_init(App $a)
} else {
$events ++;
}
if (DateTimeFormat::convert($x['start'], ((intval($x['adjust'])) ? $a->getTimeZone() : 'UTC'), 'UTC', 'Y-m-d') === $str_now) {
if (DateTimeFormat::local($x['start'], 'Y-m-d') === $str_now) {
$all_events_today ++;
if ($bd) {
$birthdays_today ++;
Expand Down
4 changes: 2 additions & 2 deletions mod/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ function settings_post(App $a)
}

if (($timezone != $user['timezone']) && strlen($timezone)) {
date_default_timezone_set($timezone);
$a->setTimeZone($timezone);
}

$aclFormatter = DI::aclFormatter();
Expand Down Expand Up @@ -601,7 +601,7 @@ function settings_content(App $a)
$expire_network_only = DI::pConfig()->get(local_user(), 'expire', 'network_only', false);

if (!strlen($user['timezone'])) {
$timezone = date_default_timezone_get();
$timezone = $a->getTimeZone();
}

// Set the account type to "Community" when the page is a community page but the account type doesn't fit
Expand Down
17 changes: 10 additions & 7 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
use Friendica\Util\ConfigFileLoader;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Profiler;
use Friendica\Util\Strings;
Expand Down Expand Up @@ -217,12 +218,13 @@ public function getContactId():int
/**
* Set the timezone
*
* @param int $timezone
* @param string $timezone A valid time zone identifier, see https://www.php.net/manual/en/timezones.php
* @return void
*/
public function setTimeZone(string $timezone)
{
$this->timezone = $timezone;
$this->timezone = (new \DateTimeZone($timezone))->getName();
DateTimeFormat::setLocalTimeZone($this->timezone);
}

/**
Expand Down Expand Up @@ -338,6 +340,9 @@ public function load()
{
set_time_limit(0);

// Ensure that all "strtotime" operations do run timezone independent
date_default_timezone_set('UTC');

// This has to be quite large to deal with embedded private photos
ini_set('pcre.backtrack_limit', 500000);

Expand Down Expand Up @@ -372,15 +377,13 @@ public function load()
private function loadDefaultTimezone()
{
if ($this->config->get('system', 'default_timezone')) {
$this->timezone = $this->config->get('system', 'default_timezone');
$timezone = $this->config->get('system', 'default_timezone', 'UTC');
} else {
global $default_timezone;
$this->timezone = !empty($default_timezone) ? $default_timezone : 'UTC';
$timezone = $default_timezone ?? '' ?: 'UTC';
}

if ($this->timezone) {
date_default_timezone_set($this->timezone);
}
$this->setTimeZone($timezone);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Content/Text/BBCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,6 @@ function ($matches) use ($simple_html, $uriid) {
$text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/ism", $sub, $text);
$text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/ism", '', $text);
$text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/ism", '', $text);
$text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism", '', $text);
$text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism", '', $text);
}

Expand Down

0 comments on commit caa1a5a

Please sign in to comment.