Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Type DateTime and Timestamp (U format) #343

Closed
four43 opened this issue Sep 19, 2014 · 2 comments
Closed

Type DateTime and Timestamp (U format) #343

four43 opened this issue Sep 19, 2014 · 2 comments
Milestone

Comments

@four43
Copy link

four43 commented Sep 19, 2014

We are outputting a DateTime as a timestamp in our application. This result is a string, but it would be great if it was an integer.

/**
 * @JMS\VirtualProperty
 * @JMS\SerializedName("dateCreated")
 * @JMS\Type("DateTime<'U'>")
 */
public function getDateCreated() {
    return $this->dateCreated;
}

Returns:

{
    "dateCreated":"1411139100"
}

Maybe keep the type of the PHP date call? date('U') returns a number.

Thanks for all your work on this. This is a great library and we're having a lot of fun with it.

-Seth

EDIT: date('U') returns a number, DateTime::format('U') returns a string. sigh PHP...

Bukashk0zzz added a commit to Bukashk0zzz/serializer that referenced this issue Mar 10, 2016
@goetas goetas added this to the v1.7 milestone Mar 13, 2017
@goetas
Copy link
Collaborator

goetas commented Apr 3, 2017

EDIT: date('U') returns a number, DateTime::format('U') returns a string. sigh PHP...

looks to be a PHP behavior

@goetas
Copy link
Collaborator

goetas commented Apr 11, 2017

Easy workarounds starting from 1.6.0:

/**
 * @Serializer\VirtualProperty(
 *     "dateCreated",
 *     exp="object.getDateCreated().getTimestamp()",
 *     options={@Serializer\Type("integer")}
 *  )
 */
class Foo {
  public function getDateCreated() {
      return $this->dateCreated;
  }
}

@goetas goetas closed this as completed Apr 11, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants