【问题标题】:correcting doctrine datetime on oracle在 oracle 上更正教义日期时间
【发布时间】:2016-06-15 22:26:31
【问题描述】:

我正在使用坚持原则,我的所有日​​期都已取消。当它们应该是-6(美国/芝加哥)时,它们被存储为+6。我在 America/Chicago 上有 php 和应用服务器,可以通过以下方式确认:

php > echo (new \DateTime())->format('Y-m-d h:m:i a e');
2016-03-02 02:03:47 pm America/Chicago

我在 oracle 中创建了一个表来调试:

  CREATE TABLE "APP"."DATE_TEST" 
   (    "ID" VARCHAR2(36 BYTE), 
    "LOCALTZ" TIMESTAMP (0) WITH LOCAL TIME ZONE, 
    "NOTLOCALTZ" TIMESTAMP (0) WITH TIME ZONE
   )

我有一个具有以下原则映射的测试实体:

Acme\Project\Domain\Asset\Entity\DateTest:
    type: entity
    table: DATE_TEST
id:
    id:
        type: guid
        generator:
            strategy: none
fields:
    localtz:
        type: datetime
        column: localtz
    notlocaltz:
        type: datetimetz
        column: notlocaltz

我执行一些代码将数据推送到表中:

protected function execute(InputInterface $input, OutputInterface $output)
    {
        $test = new DateTest();
        $datetime = new \DateTime();
        $test->setLocalTz($datetime);
        $test->setNotLocalTz($datetime);
        $output->writeln($test->getId());
        $output->writeln($datetime->format('Y-m-d h:i:s a'));
        $output->writeln($datetime->getTimezone()->getName());
        $em = $this
            ->getContainer()
            ->get('doctrine.orm.entity_manager');
        $em->persist($test);
        $em->flush();
        $output->writeln("Test complete.");
    }

输出如下

de4e5dcd-9fd6-4b5d-b9f0-6db9d1ef0582
2016-03-02 02:51:02 pm
America/Chicago
Test complete.

这就是我在数据库中看到的

de4e5dcd-9fd6-4b5d-b9f0-6db9d1ef0582    02-MAR-16 08.51.02.000000000 AM 02-MAR-16 02.51.02.000000000 PM +06:00

我已经连接了oracle session init

当我查询数据库的当前时间时,它看起来是正确的:

SELECT SYSTIMESTAMP "NOW" FROM DUAL;
02-MAR-16 02.56.44.342456000 PM -06:00

谁能发现我做错了什么?

【问题讨论】:

  • 值得检查吗?通过 php 执行此查询,如果您使用单独的客户端进行 misc db 活动,请在此处执行:SELECT DBTIMEZONE, SESSIONTIMEZONE from dual;
  • @Beege 从 php 执行那些查询对于两个查询都返回“+00:00”。好像不太对……

标签: php oracle symfony doctrine-orm doctrine


【解决方案1】:

我追踪到设置错误时区格式的 OracleSessionInit 类。 OraclePlatform 类在时间和偏移量之间没有空格,而会话格式有。

在容器中覆盖该格式解决了我的问题。

services:
    oci8.listener:
        class: Doctrine\DBAL\Event\Listeners\OracleSessionInit
        arguments:
            - { NLS_TIMESTAMP_TZ_FORMAT: "YYYY-MM-DD HH24:MI:SSTZH:TZM" }
        tags:
            - { name: doctrine.event_listener, event: postConnect } 

我打开了issue on github,因为我很确定这是一个错误。

【讨论】:

  • 很好的追溯。我无法让我的 php 返回类似(坏)的结果。
猜你喜欢
  • 2013-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-29
  • 2019-12-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多