Issues

ZF-3965: Write getter and setter for private $_offset member

Description

I realize that this would invalidate the $_timezone member, but it would be nice if one could manually modify the $_offset parameter using some getters and setters. In contrast, it would also be nice to be able to give setTimeZone something other than the PHP timezones (more along the lines of "-7" or "GMT+0600"). My reasoning for wanting to set the $_offset member myself are that I can get a unix timestamp for the server, and a unix timestamp for the client, so I can get the value of $_offset, but I can't easily get a value that setTimeZone likes.

Comments

No, there will be no setter/getter for this private property, because there are dependencies on other members.

Offset is used for holding the offset for the servers time to the real time when using Zend_TimeSync.

When creating a date object you can simply set Timezones by setting a real timezone along the olson database, or a windows timezone using Zend_Locale or simply an hour offset like +0600 or -02:00 by using the proper input formats.

Anyhow you calculate this, you must give an hour offset. All other things will not be recognised as Timezone setting as timezones are ALWAYS hour offsets.

There is also a getTimezoneByString method which could be handy.

Feature would corrupt other features necessary for date calculation.

I couldn't convince setTimezone to accept any kind of hour offset (even in formats like 'UTC+0800' or 'UTC-7'), so my solution ended up being looping over the list returned by timezone_abbreviations_list() and just using the first timezone_id that had the offset I was looking for. This isn't the best solution, but it's the best I could come up with to just allow me to adjust my Zend_Date objects into the offset I want/need.

Long story short, timezone_abbreviations_list() doesn't really work too well. Too many duplicates with different offsets.

timezone_name_from_abbr, however, works like a charm:

<?php echo timezone_name_from_abbr('', -25200, 0); // prints out "America/Denver"

Timezones in date strings are eighter defined as timezone name for example "America/Denver" or as hour offset for example "+0800".

Both are recognised by Zend_Date and the mentioned getTimezoneByString method.

Timezones by second offset are not allowed and therefor not supported. You can simply come around this by dividing 25200 by 3600 and use this as input for the houroffset.