feat(tw): Applied timezone to datetimes that are not given in local time

This commit is contained in:
Aerex 2020-06-03 00:46:06 -05:00
parent c2e181aa75
commit c302c4653a
2 changed files with 14 additions and 13 deletions

View File

@ -38,8 +38,7 @@ class StorageManager {
if (!isset($this->configs)) {
throw new \Exception('StorageManger was not initialize or configs are not defined');
}
foreach ($this->configs as $key => $value) {
if ($key !== 'logger') {
foreach ($this->configs['storages'] as $key => $value) {
$storage = $this->storages[$key];
if (!isset($storage)){
throw new \Exception();
@ -48,4 +47,3 @@ class StorageManager {
}
}
}
}

View File

@ -5,6 +5,7 @@ namespace Aerex\BaikalStorage\Storages;
use Sabre\VObject\Component\VCalendar as Calendar;
use Aerex\BaikalStorage\Logger;
use Carbon\Carbon;
use Carbon\CarbonTimeZone;
class Taskwarrior implements IStorage {
@ -12,11 +13,13 @@ class Taskwarrior implements IStorage {
private $tasks = [];
private $configs;
private $logger;
private $tz;
public function __construct($console, $configs) {
$this->console = $console;
$this->configs = $configs['taskwarrior'];
$this->logger = new Logger($configs, 'Taskwarrior');
$this->tz = new CarbonTimeZone($configs['general']['timezone']);
}
public function getConfig() {
@ -51,19 +54,19 @@ class Taskwarrior implements IStorage {
}
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)) {
$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)){
$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'})) {
$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)) {
@ -99,13 +102,13 @@ class Taskwarrior implements IStorage {
case 'COMPLETED':
$task['status'] = 'completed';
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;
case 'CANCELED':
$task['status'] = 'deleted';
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;
}