<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Sat, 18 May 2013 20:09:46 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Websanova.com: Timezones, the Right Way]]></title>
      <guid>http://www.phpdeveloper.org/news/18892</guid>
      <link>http://www.phpdeveloper.org/news/18892</link>
      <description><![CDATA[<p>
On the Websanova.com site there's a recent post about doing <a href="http://www.websanova.com/tutorials/php/timezones-the-right-way#.UMshCJPjmjQ">timezones the right way</a> when working with them in PHP and storing them in your (MySQL) database.
</p>
<blockquote>
Timezones are actually a very trivial concept but they seem to be overlooked and over complicated. [...] Rather than storing a timezone with each date it's better to just accept a standard time to store all your dates with, thus doing the conversion to that standard time before storing the value in the database. It doesn't really matter what time we store it as, but it's generally a good idea to just use UTC+00:00.
</blockquote>
<p>
They talk a little about what the UTC timezone is for those that may not know and show how to set it as the default timezone for your PHP application (with <a href="http://php.net/date_default_timezone_set">date_default_timezone_set</a> or updating your php.ini). They also include the MySQL configuration option to set its default timezone and and example SELECT statement for extracting the data back out.
</p>]]></description>
      <pubDate>Fri, 14 Dec 2012 10:17:21 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Gonzalo Ayuso: Handling dates with PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/18540</guid>
      <link>http://www.phpdeveloper.org/news/18540</link>
      <description><![CDATA[<p>
In <a href="http://gonzalo123.com/2012/10/01/handling-dates-with-php/">this new post</a> to his site <i>Gonzalo Ayuso</i> introduces you to one of the more powerful parts of the PHP language - the <a href="http://php.net/datetime">DateTime</a> object.
</p>
<blockquote>
I've seen a lot of newbies (and not newbies) having problems handling dates in PHP (and even with SQL and another languages). When I see someone having problems with dates, I always ask the same question. I type in a text editor "27/11/2012&#8243; and I ask him: What is it? If your answer is "This is a date" you should continue reading the post.
</blockquote>
<p>
He talks about how the DateTime functionality replaces (much more effectively) some of the older date handling methods in PHP. He includes a few examples comparing it to <a href="http://php.net/date">date</a> and showing how it can be used to compare dates. He includes a "Dummy" class he mocked up to show how you could work with DateTime to get/set formatted dates, set the format to use and get the current format. As always, he also provides tests for the code as well.
</p>
<p>
This is just the tip of the iceberg as to what DateTime can do, so I'd suggest checking out <a href="http://php.net/manual/book.datetime.php">the manual page</a> for it to see the full list of features.
</p>]]></description>
      <pubDate>Tue, 02 Oct 2012 08:41:09 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Phil Sturgeon: Why PHP DateTime Rocks]]></title>
      <guid>http://www.phpdeveloper.org/news/18311</guid>
      <link>http://www.phpdeveloper.org/news/18311</link>
      <description><![CDATA[<p>
<i>Phil Sturgeon</i> has a new post sharing some of his thoughts on <a href="http://philsturgeon.co.uk/blog/2012/08/why-php-datetime-rocks">why DateTime rocks</a>, the advanced functionality that PHP has to work with dates, times, timezones, etc.
</p>
<blockquote>
DateTime is nothing new, but it's definitely under-used by many. It was made available in PHP 5.2.0 but got some of its best features until PHP 5.3.0. PHP 5.3.0 is pretty old now, but I learned about <a href="http://uk.php.net/manual/en/datetime.createfromformat.php">DateFormat::createFromFormat()</a> after reading a new addition to <a href="http://www.phptherightway.com/#date_and_time">PHP The Right Way: Date and Time</a>.
</blockquote>
<p>
He shares to "offender" examples where using this function allowed him to simplify and reduce the amount of code needed to handle the formatting of a date into a MySQL format and calculating the difference between two time values.
</p>]]></description>
      <pubDate>Thu, 02 Aug 2012 11:41:29 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Jeremy Cook's Blog: Normalising DateTimes with Doctrine Events]]></title>
      <guid>http://www.phpdeveloper.org/news/18147</guid>
      <link>http://www.phpdeveloper.org/news/18147</link>
      <description><![CDATA[<p>
<i>Jeremy Cook</i> has <a href="http://jeremycook.ca/2012/06/24/normalising-datetimes-with-doctrine-events/">written up a new post</a> showing you a method for normalizing the date and time information in your application (DateTime) with the help of Doctrine's own event listeners.
</p>
<blockquote>
The solution we hit on was to leverage <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#listening-to-lifecycle-events">Doctrine's system of event listeners</a> to help us do the work. Doctrine allows you to register listeners with the entity manager that are called whenever certain events occur. We created an event listener that is triggered on the onFlush event.
</blockquote>
<p>
Code is included for the event listener they created - a simple "onFlush" event that grabs the current entities from the manager, sets the date/time property to allow it to be changed (via Reflection) and updating it with the new cleaned format.
</p>]]></description>
      <pubDate>Wed, 27 Jun 2012 12:44:03 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Derick Rethans' Blog: To GMT or not to GMT]]></title>
      <guid>http://www.phpdeveloper.org/news/17611</guid>
      <link>http://www.phpdeveloper.org/news/17611</link>
      <description><![CDATA[<p>
In <a href="http://derickrethans.nl/gmt-being-tricky.html">this new post</a> to his site, <i>Derick Rethans</i> shows an instance of "GMT being tricky" when it comes to "UTC" versus "GMT" output from PHP's DateTime object.
</p>
<blockquote>
Earlier today, on twitter, @skoop asked: "dear #lazyweb, when I use DateTimeZone('GMT'), why does format('e') output UTC?" [...] As you can see [the example with a format of "e" on a DateTimeZone('GMT')] has UTC and not GMT as you might expect.
</blockquote>
<p>
<i>Derick</i> mentions that sometimes, systems require "GMT" instead of "UTC" in the output they're given. To work around this issue, he shows how to add a "type 2" timezone to the DateTime object by including it when you initialize the object (code samples included). Using alternative methods, you can add these "type 2" timezones in three ways - an offset in the initial string, using the abbreviation (like "EST" or "PST") and specifying the long version of the timezone (like "America/Montreal").
</p>]]></description>
      <pubDate>Thu, 01 Mar 2012 11:39:45 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Working with Dates and Times in PHP and MySQL]]></title>
      <guid>http://www.phpdeveloper.org/news/17608</guid>
      <link>http://www.phpdeveloper.org/news/17608</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new tutorial by <i>Sean Hudgston</i> about <a href="http://phpmaster.com/working-with-dates-and-times">working with dates and times</a> via the PHP date functions and how they cooperate with dates/times from a MySQL database.
</p>
<blockquote>
When working in any programming language, dealing with dates and time is often a trivial and simple task. That is, until time zones have to be supported. Fortunately, PHP has one of the most potent set of date/time tools that help you deal with all sorts of time-related issues: Unix timestamps, formatting dates for human consumption, displaying times with time zones, the difference between now and the second Tuesday of next month, etc. In this article I'll introduce you to the basics of PHP's time functions (time(), mktime(), and date()) and their object-oriented counterparts, and then take a look at MySQL dates and show you how to make them play nicely with PHP.
</blockquote>
<p>
His examples include how to get the current Unix time, formatting dates/times, making timestamps and working with the more powerful DateTime objects. On the MySQL front, he shows the result of a normal date select, one using the "unix_timestamp" function and how to shift the result based on the user's timezone.
</p>]]></description>
      <pubDate>Thu, 01 Mar 2012 08:51:47 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Davey Shafik's Blog: DateTime Timestamp Parsing]]></title>
      <guid>http://www.phpdeveloper.org/news/16882</guid>
      <link>http://www.phpdeveloper.org/news/16882</link>
      <description><![CDATA[<p>
In a new post to his blog <i>Davey Shafik</i> looks at <a href="http://daveyshafik.com/archives/28101-datetime-timestamp-parsing.html">parsing dates with DateTime</a>, the <a href="http://php.net/datetime">new and improved</a> way to handle dates in PHP (well, not so new but definitely improved).
</p>
<blockquote>
As part of a recent project, I was tasked with taking timestamps returned by an API and displaying fuzzy dates in the final output (e.g. 3hrs ago, in 2 weeks, tomorrow). The timestamp format in question looks like: 2012-09-01T16:20:01-05:00 This format can be found in PHP as the DATE_ATOM or DateTime::ATOM constants, which contain the date() formatter string: Y-m-dTH:i:sP With this in hand, we can now easily parse the timestamp into a useful object.
</blockquote>
<p>
Parsing the date into a DateTime object is as easy as giving it the date string and telling it how it's formatted. Then you can do all sorts of fun things. He shows how to shift the timezone by name, by time increment - simple (like "1 hour") and more complex (like "1 hour 5 minutes 3 seconds"). You can find out more about the DateTime object <a href="http://php.net/datetime">in the PHP manual</a>.
</p>]]></description>
      <pubDate>Tue, 20 Sep 2011 11:24:27 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Christian Schaefer's Blog: Beware of the timezone! Working with PHP DateTime & Doctrine for MongoDB]]></title>
      <guid>http://www.phpdeveloper.org/news/16822</guid>
      <link>http://www.phpdeveloper.org/news/16822</link>
      <description><![CDATA[<p>
<i>Christian Schaefer</i> has a recent post pointing out a common frustration among developers of applications with NoSQL backends, specifically with Doctrine, MongoDB and PHP DateTime objects - <a href="http://test.ical.ly/2011/09/01/beware-of-the-timezone-working-with-php-datetime-and-doctrine-for-mongodb-can-cause-conflicts/">timezone conflicts</a>.
</p>
<blockquote>
I really like <a href="http://test.ical.ly/2011/03/25/how-to-select-for-a-specific-date-or-time-with-doctrine-2-0/">Doctrines way of dealing with dates and times</a>. Instead of passing timestamps around or strings with ISO date format it simply makes use of the PHP native type DateTime which provides all you really need to work with. PHPs interface to MongoDB however comes with its own MongoDate type which provides hardly any functionality compared to DateTime and it's not compatible with it. So what's the difference?
</blockquote>
<p>
In some of the <a href="http://test.ical.ly/2011/09/01/beware-of-the-timezone-working-with-php-datetime-and-doctrine-for-mongodb-can-cause-conflicts/#comments">comments to the post</a>, readers mention that the problem is bigger than just the tools used to work with the database, it's that databases usually don't care about timezones when working with date/time. There's also an interesting mention further down about <a href="http://www.lightcubesolutions.com/blog/?p=373">the timezone support MongoDB does have</a> and an example snippet ofo code that uses the support.
</p>]]></description>
      <pubDate>Tue, 06 Sep 2011 13:50:38 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Slawek Lukasiewicz's Blog: Working with date and time in object oriented way]]></title>
      <guid>http://www.phpdeveloper.org/news/16451</guid>
      <link>http://www.phpdeveloper.org/news/16451</link>
      <description><![CDATA[<p>
<i>Slawek Lukasiewicz</i> has a new post today about <a href="http://www.leftjoin.net/2011/06/working-with-date-and-time-in-object-oriented-way/">working with dates and times in PHP</a> on a more object-oriented fashion than in the more traditionally procedural way of just calling PHP date/time functions on the string values.
</p>
<blockquote>
Date and time manipulation in PHP is mostly connected with functions like: date, time or strtotime. They can be sufficient, but if we want to deal with dates like with objects - we can use DateTime class. DateTime class is not only straightforward wrapper for standard functions, it has a lot of additional features - for example timezones.
</blockquote>
<p>
He shows how to use the <a href="http://php.net/datetime">DateTime</a> functionality to return an object you can call several different methods on. He gives examples of the formatting call, comparing one DateTime object to another, how to update the date after the object's created, calculating the difference between two dates and iterating through a certain time period.
</p>]]></description>
      <pubDate>Fri, 10 Jun 2011 08:13:14 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[XPertDeveloper.com: Is Your PHP Application Affected by the Y2K38?]]></title>
      <guid>http://www.phpdeveloper.org/news/16341</guid>
      <link>http://www.phpdeveloper.org/news/16341</link>
      <description><![CDATA[<p>
On the XpertDeveloper.com site there's a post reminding you of an date could cause all sorts of problems with your PHP application - <a href="http://www.xpertdeveloper.com/2010/08/is-your-php-application-affected-by-the-y2k38/">the effects of the Y2K38 bug</a>.
</p>
<blockquote>
<a href="http://en.wikipedia.org/wiki/Year_2038_problem">Y2K38</a>, or the Unix Millennium Bug, affects PHP and many other languages and systems which use a signed 32-bit integer to signify dates as the number of seconds since 00:00:00 UTC on 1 January 1970. The furthest date which can be stored is 03:14:07 UTC on 19 January 2038. Beyond that, the left-most bit is set and the integer becomes a negative decimal number or a time prior to the epoch.
</blockquote>
<p>
If you're worried about your application's support for date and time handling, there's a pretty simple fix - replace your current handling with the <a href="http://php.net/datetime">DateTime</a> functionality. This handles them correctly.
</p>]]></description>
      <pubDate>Mon, 16 May 2011 09:22:18 -0500</pubDate>
    </item>
  </channel>
</rss>
