Kane Samba Kane Samba - 5 months ago 48
PHP Question

DateTime Serialization Returning incorrect Minutes SYMFONY 3

i have a problem (Sorry for my Bad English Again)

So i created an API with Symfony 3 on JSON , it is working , but the DateTime data's are not returned correctly .

i mean , only the hours are returned correctly but the minutes aren't

This is my Entity , Horaire.php

<?php

namespace CBMedBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\VirtualProperty;
use JMS\Serializer\Annotation\Type;

/**
* Horaire
*
* @ORM\Table(name="horaire")
* @ORM\Entity(repositoryClass="CBMedBundle\Repository\HoraireRepository")
*
* @ExclusionPolicy("all")
*/
class Horaire
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var time
*
* @ORM\Column(name="Debut", type="time", length=10)
* @Type("DateTime<'h-m-s'>")
* @Expose
*/
private $debut;

/**
* @var time
*
* @ORM\Column(name="EntreeSalle", type="time", length=10)
* @Type("DateTime<'h-m-s'>")
* @Expose
*/
private $entreeSalle;

/**
* @var time
*
* @ORM\Column(name="HeureAnesthesie", type="time", length=10)
* @Type("DateTime<'h-m-s'>")
* @Expose
*/
private $heureAnesthesie;

/**
* @var time
*
* @ORM\Column(name="Operation", type="time", length=10)
* @Type("DateTime<'h-m-s'>")
* @Expose
*/
private $operation;

/**
* @var time
*
* @ORM\Column(name="incision", type="time", length=10)
* @Type("DateTime<'h-m-s'>")
* @Expose
*/
private $incision;

/**
* @var time
*
* @ORM\Column(name="finOpe", type="time", length=10)
* @Type("DateTime<'h-m-s'>")
* @Expose
*/
private $finOpe;

/**
* @var time
*
* @ORM\Column(name="Reveil", type="time", length=10)
* @Type("DateTime<'h-m-s'>")
* @Expose
*/
private $reveil;

/**
* @var time
*
* @ORM\Column(name="Sortie", type="time", length=10)
* @Type("DateTime<'h-m-s'>")
* @Expose
*/
private $sortie;

/**
* @ORM\OneToOne(targetEntity="CBMedBundle\Entity\Interventions", cascade= {"persist"})
* @Expose
*/
private $Interventions;
//
etc....


As you see , i used the
JMS\Serializer\Annotation\


And i indicated That the DateTime type is in this format
@Type("DateTime<'h-m-s'>")


And this is what i get when i test my API with POSTMAN
IMAGE API POSTMAN

My Real datas on phpmyAdmin
phpmyAdmin Datas

i have "01" on every minutes

How do i fix this please ?

Answer

Try this annotation instead:

@Type("DateTime<'H:i:s'>")

See what that shows please. This is based on PHP DateTime format.

Comments