DRY for getting calendar timezone setting

This commit is contained in:
Bart Visscher 2012-07-21 00:45:13 +02:00
parent 1c30a97833
commit 060b8865a4
9 changed files with 24 additions and 14 deletions

View File

@ -27,7 +27,7 @@ if (!$end){
}
$start = new DateTime('@'.$start);
$end = new DateTime('@'.$end);
$timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$timezone = OC_Calendar_App::getTimezone();
$start->setTimezone(new DateTimeZone($timezone));
$end->setTimezone(new DateTimeZone($timezone));

View File

@ -9,7 +9,7 @@
* This class manages our app actions
*/
OC_Calendar_App::$l10n = new OC_L10N('calendar');
OC_Calendar_App::$tz = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
OC_Calendar_App::$tz = OC_Calendar_App::getTimezone();
class OC_Calendar_App{
const CALENDAR = 'calendar';
const EVENT = 'event';
@ -282,7 +282,17 @@ class OC_Calendar_App{
public static function getWeekofMonth(){
return OC_Calendar_Object::getWeekofMonth(self::$l10n);
}
/**
* @return (string) $timezone as set by user or the default timezone
*/
public static function getTimezone() {
return OCP\Config::getUserValue(OCP\User::getUser(),
'calendar',
'timezone',
date_default_timezone_get());
}
/**
* @brief checks the access for a calendar / an event
* @param (int) $id - id of the calendar / event

View File

@ -856,7 +856,7 @@ class OC_Calendar_Object{
$vevent->setDateTime('DTSTART', $start, Sabre_VObject_Property_DateTime::DATE);
$vevent->setDateTime('DTEND', $end, Sabre_VObject_Property_DateTime::DATE);
}else{
$timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
$start = new DateTime($from.' '.$fromtime, $timezone);
$end = new DateTime($to.' '.$totime, $timezone);

View File

@ -12,7 +12,7 @@ class OC_Search_Provider_Calendar extends OC_Search_Provider{
}else{
$searchquery[] = $query;
}
$user_timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$user_timezone = OC_Calendar_App::getTimezone();
$l = new OC_l10n('calendar');
foreach($calendars as $calendar){
$objects = OC_Calendar_Object::all($calendar['id']);

View File

@ -22,7 +22,7 @@ $request['description'] = null;
$vcalendar = OC_Task_App::createVCalendarFromRequest($request);
$id = OC_Calendar_Object::add($cid, $vcalendar->serialize());
$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$user_timezone = OC_Calendar_App::getTimezone();
$task = OC_Task_App::arrayForJSON($id, $vcalendar->VTODO, $user_timezone);
OCP\JSON::success(array('task' => $task));

View File

@ -26,7 +26,7 @@ $tmpl->assign('details', $vcalendar->VTODO);
$tmpl->assign('id', $id);
$page = $tmpl->fetchPage();
$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$user_timezone = OC_Calendar_App::getTimezone();
$task = OC_Task_App::arrayForJSON($id, $vcalendar->VTODO, $user_timezone);
OCP\JSON::success(array('data' => array( 'id' => $id, 'page' => $page, 'task' => $task )));

View File

@ -11,7 +11,7 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('tasks');
$calendars = OC_Calendar_Calendar::allCalendars(OCP\User::getUser(), true);
$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$user_timezone = OC_Calendar_App::getTimezone();
$tasks = array();
foreach( $calendars as $calendar ){

View File

@ -39,7 +39,7 @@ switch($property) {
$type = null;
if ($due != 'false') {
try {
$timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
$due = new DateTime('@'.$due);
$due->setTimezone($timezone);
@ -64,6 +64,6 @@ switch($property) {
}
OC_Calendar_Object::edit($id, $vcalendar->serialize());
$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$user_timezone = OC_Calendar_App::getTimezone();
$task_info = OC_Task_App::arrayForJSON($id, $vtodo, $user_timezone);
OCP\JSON::success(array('data' => $task_info));

View File

@ -82,7 +82,7 @@ class OC_Task_App {
}
try {
$timezone = OCP\Config::getUserValue(OCP\User::getUser(), "calendar", "timezone", "Europe/London");
$timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
new DateTime($request['due'], $timezone);
} catch (Exception $e) {
@ -94,7 +94,7 @@ class OC_Task_App {
}
if ($request['percent_complete'] == 100 && !empty($request['completed'])) {
try {
$timezone = OCP\Config::getUserValue(OCP\User::getUser(), "calendar", "timezone", "Europe/London");
$timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
new DateTime($request['completed'], $timezone);
} catch (Exception $e) {
@ -147,7 +147,7 @@ class OC_Task_App {
$vtodo->setString('PRIORITY', $priority);
if ($due) {
$timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
$due = new DateTime($due, $timezone);
$vtodo->setDateTime('DUE', $due);
@ -176,7 +176,7 @@ class OC_Task_App {
$completed = null;
}
if ($completed) {
$timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$timezone = OC_Calendar_App::getTimezone();
$timezone = new DateTimeZone($timezone);
$completed = new DateTime($completed, $timezone);
$vtodo->setDateTime('COMPLETED', $completed);