WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 15 months ago

#28614 closed enhancement (worksforme)

Add microtime support to current_time()

Reported by: uuf6429 Owned by: chriscct7
Milestone: Priority: normal
Severity: normal Version: 3.9.1
Component: Date/Time Keywords: has-patch
Focuses: Cc:

Description

current_time() is currently limited to precision to at most, seconds.

I propose adding current_time('microtime') functionality.

The proposed changed affects wp-includes/functions.php, line 67:

    case 'microtime':
        return ( $gmt ) ? microtime(true) : microtime(true) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
        break;

Also, considering this may require better performing code ... I was thinking that perhaps get_option() ... etc should be replaced with a cache (and update_option() should be able to update/reset the cache).

Attachments (1)

28614.diff (715 bytes) - added by nofearinc 5 years ago.

Download all attachments as: .zip

Change History (6)

#1 in reply to: ↑ description @rmccue
5 years ago

Replying to uuf6429:

Also, considering this may require better performing code ... I was thinking that perhaps get_option() ... etc should be replaced with a cache (and update_option() should be able to update/reset the cache).

WordPress has an internal option cache (check the source for get_option and update_option), however this is handled inside those functions and is transparent to functions using them.

@nofearinc
5 years ago

#2 @nofearinc
5 years ago

  • Keywords has-patch added

Adding a sample with the suggested change, break; is omitted as the function execution is interrupted anyway due to the return statement in the case.

#3 @chriscct7
4 years ago

  • Owner set to chriscct7
  • Status changed from new to reviewing

#4 @Rarst
15 months ago

current_time() is a complete disaster (as most things that juggle manual time zone offsets).

The concept of "WordPress timestamp" with time zone offset is deeply problematic and we should be moving towards dropping it completely. Expanding functionality that relies on it is just makes that harder.

#5 @Rarst
15 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from reviewing to closed

I am working on eliminating timestamp use of current_time() in #40657, so now I am even more set that we shouldn't be expanding its "local" time functionality.

WP core doesn't really operate with microtime, and if extension use cases need it — they need to be doing it properly, with sane modern DateTime approach.

Note: See TracTickets for help on using tickets.