[wp-trac] [WordPress Trac] #21653: Introduce current_date()

WordPress Trac noreply at wordpress.org
Sun Jan 6 00:47:35 UTC 2013


#21653: Introduce current_date()
-------------------------+------------------------------
 Reporter:  johnbillion  |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  low          |   Milestone:  Awaiting Review
Component:  Date/Time    |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------------------
Changes (by danielbachhuber):

 * cc: danielbachhuber (added)
 * component:  General => Date/Time


Comment:

 Rather than introduce a new function which accepts slightly different
 params, why not add PHP date format to `current_time()`?

 Usage:

 {{{
 current_time( 'Y-m-d' );
 }}}

 How it'd work:

 {{{
 function current_time( $type, $gmt = 0 ) {
         switch ( $type ) {
                 case 'mysql':
                         return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) :
 gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) *
 HOUR_IN_SECONDS ) ) );
                         break;
                 case 'timestamp':
                         return ( $gmt ) ? time() : time() + ( get_option(
 'gmt_offset' ) * HOUR_IN_SECONDS );
                         break;
                 default:
                         return ( $gmt ) ? date( $type ) : date( $type,
 time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
                         break;
         }
 }
 }}}

 Although the naming deviates from PHP,  I believe this approach is
 superior for a couple of reasons:

 1. Less code.
 1. Doesn't create two functions with slightly different use.

 Patch is attached.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21653#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list