Alexey Zakhlestin's Blog

Programming for Mac and Web

DateTime vs Numeric Timezone


Is it possible to create DateTime object if I have some date string, and a numeric timezone value?

Something like: ` $timestamp = ‘2007-07-07 07:07:07’; $timezone = ‘+0300’;

$obj = new DateTime($timestamp, new DateTimeZone(????)); `

I need this, to add proper support for YAML-timestamps in my syck extension.

In YAML, timestamps have several representations:

  • canonical: 2001-12-15T02:59:43.1Z

  • valid iso8601: 2001-12-14t21:59:43.10-05:00

  • space separated: 2001-12-14 21:59:43.10 -5

  • no time zone (Z): 2001-12-15 2:59:43.10

  • date (00:00:00Z): 2002-12-14

As you can see, in each case timezone is represented by numeric, while PHP expects me to specify timezone as a toponym…