feat(tw): Applied timezone to datetimes that are not given in local time
This commit is contained in:
parent
c2e181aa75
commit
c302c4653a
@ -38,8 +38,7 @@ class StorageManager {
|
|||||||
if (!isset($this->configs)) {
|
if (!isset($this->configs)) {
|
||||||
throw new \Exception('StorageManger was not initialize or configs are not defined');
|
throw new \Exception('StorageManger was not initialize or configs are not defined');
|
||||||
}
|
}
|
||||||
foreach ($this->configs as $key => $value) {
|
foreach ($this->configs['storages'] as $key => $value) {
|
||||||
if ($key !== 'logger') {
|
|
||||||
$storage = $this->storages[$key];
|
$storage = $this->storages[$key];
|
||||||
if (!isset($storage)){
|
if (!isset($storage)){
|
||||||
throw new \Exception();
|
throw new \Exception();
|
||||||
@ -47,5 +46,4 @@ class StorageManager {
|
|||||||
$storage->save($calendar);
|
$storage->save($calendar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace Aerex\BaikalStorage\Storages;
|
|||||||
use Sabre\VObject\Component\VCalendar as Calendar;
|
use Sabre\VObject\Component\VCalendar as Calendar;
|
||||||
use Aerex\BaikalStorage\Logger;
|
use Aerex\BaikalStorage\Logger;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Carbon\CarbonTimeZone;
|
||||||
|
|
||||||
class Taskwarrior implements IStorage {
|
class Taskwarrior implements IStorage {
|
||||||
|
|
||||||
@ -12,11 +13,13 @@ class Taskwarrior implements IStorage {
|
|||||||
private $tasks = [];
|
private $tasks = [];
|
||||||
private $configs;
|
private $configs;
|
||||||
private $logger;
|
private $logger;
|
||||||
|
private $tz;
|
||||||
|
|
||||||
public function __construct($console, $configs) {
|
public function __construct($console, $configs) {
|
||||||
$this->console = $console;
|
$this->console = $console;
|
||||||
$this->configs = $configs['taskwarrior'];
|
$this->configs = $configs['taskwarrior'];
|
||||||
$this->logger = new Logger($configs, 'Taskwarrior');
|
$this->logger = new Logger($configs, 'Taskwarrior');
|
||||||
|
$this->tz = new CarbonTimeZone($configs['general']['timezone']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConfig() {
|
public function getConfig() {
|
||||||
@ -51,19 +54,19 @@ class Taskwarrior implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->DTSTAMP)){
|
if (isset($vtodo->DTSTAMP)){
|
||||||
$task['entry'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C));
|
$task['entry'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->DTSTART)) {
|
if (isset($vtodo->DTSTART)) {
|
||||||
$task['start'] = new Carbon($vtodo->DTSTART->getDateTime()->format(\DateTime::W3C));
|
$task['start'] = new Carbon($vtodo->DTSTART->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->DTEND)){
|
if (isset($vtodo->DTEND)){
|
||||||
$task['end'] = new Carbon($vtodo->DTEND->getDateTime()->format(\DateTime::W3C));
|
$task['end'] = new Carbon($vtodo->DTEND->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->{'LAST-MODIFIED'})) {
|
if (isset($vtodo->{'LAST-MODIFIED'})) {
|
||||||
$task['modified'] = new Carbon($vtodo->{'LAST-MODIFIED'}->getDateTime()->format(\DateTime::W3C));
|
$task['modified'] = new Carbon($vtodo->{'LAST-MODIFIED'}->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->PRIORITY)) {
|
if (isset($vtodo->PRIORITY)) {
|
||||||
@ -99,13 +102,13 @@ class Taskwarrior implements IStorage {
|
|||||||
case 'COMPLETED':
|
case 'COMPLETED':
|
||||||
$task['status'] = 'completed';
|
$task['status'] = 'completed';
|
||||||
if (!isset($task['end'])) {
|
if (!isset($task['end'])) {
|
||||||
$task['end'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C));
|
$task['end'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'CANCELED':
|
case 'CANCELED':
|
||||||
$task['status'] = 'deleted';
|
$task['status'] = 'deleted';
|
||||||
if (!isset($task['end'])) {
|
if (!isset($task['end'])) {
|
||||||
$task['end'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C));
|
$task['end'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user