sfDateTime2Plugin - 0.3.0
Date manipulation library.
You are currently browsing
the website for symfony 1
Manipulate dates in symfony like a dream.
This plugin will add a date manipulation library to the symfony framework.
|Jerome Etienne||lead||moc.liamg <<ta>> enneite.emorej|
Copyright (c) 2008 Jerome Etienne
Copyright (c) 2007 Stephen Riesenberg
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This plugin has been mainly written by Stephen Riesenberg. I merely fix minor bugs and maintains it.
This plugin will add a date manipulation library to the symfony framework. The library manipulates timestamp values, allowing you to quickly translate a date into another date based on an infinite number of operations. The library contains a base add function, which handles all cases of a single date manipulation. It also contains a large number of other functions based on the add function, which faciliate more complicated operations. Finally, the library contains an instantiable class, which provides an interface hook into the main library allowing chainable date manipulation operations for more readable code.
To install sfDateTimePlugin:
symfony plugin-install symfony/sfDateTimePlugin
svn co http://svn.symfony-project.com/plugins/sfDateTimePlugin2 plugins/sfDateTimePlugin2
Clear your cache
Examples which dump their results to a datetime.
<?php // defaults to now $dt = new sfDate(); // accepts existing sfDate object $dt = new sfDate($dt); // accepts a timestamp integer, like from time() or mktime() $dt = new sfDate(1176856745); // parses date from a string using strtotime $dt = new sfDate('2007-04-17 19:39:05'); echo $dt->firstDayOfWeek()->tomorrow()->dump(); // => 2007-04-16 19:39:05 echo $dt->addYear()->subtractQuarter()->dump(); // => 2008-01-16 19:39:05 echo $dt->finalDayOfQuarter()->clearTime()->dump(); // => 2008-03-31 00:00:00 echo $dt->finalDayOfYear()->subtractWeek(4)->addDay(5)->dump(); // => 2008-12-08 00:00:00 echo $dt->reset()->dump(); // => 2007-04-17 19:39:05
The I18N date helpers are integrated directly into the library.
<!-- <?php use_helper('Date') ?> is not necessary in this case --> Next sunday in your language: <?php echo sfDate::getInstance()->firstDayOfWeek()->addWeek()->date() ?> Last thursday in your language: <?php echo sfDate::getInstance()->previousDay(sfTime::THURSDAY)->date() ?> Now in your language: <?php echo sfDate::getInstance()->datetime() ?>
Constants are available through the sfTime class (as in sfTime::CONSTANT_NAME):
The following functions are available to an instantiated sfDate object, and are chainable:
The following functions are available to an instantiated sfDate object, and are not chainable:
The following functions are available to the sfDate class, and are chainable:
NOTE: All parameters are optional and default to logical values (1 for numbers, DAY for units of time, SUNDAY for days of week, JANUARY for months of year).
NOTE: When using the sfTime function library itself, the first parameter of every function is a timestamp. When using an instantiated sfDate, the timestamp parameter is automatically passed in.
For the full copyright and license information, please view the LICENSE file that was distributed with this source code.