@@ 1324-1366 (lines=43) @@ | ||
1321 | * |
|
1322 | * @return string |
|
1323 | */ |
|
1324 | function format_date( $date_gmt, $date = null ) { |
|
1325 | $timestamp_gmt = strtotime( "$date_gmt+0000" ); |
|
1326 | ||
1327 | if ( null === $date ) { |
|
1328 | $timestamp = $timestamp_gmt; |
|
1329 | $hours = $minutes = $west = 0; |
|
1330 | } else { |
|
1331 | $date_time = date_create( "$date+0000" ); |
|
1332 | if ( $date_time ) { |
|
1333 | $timestamp = date_format( $date_time, 'U' ); |
|
1334 | } else { |
|
1335 | $timestamp = 0; |
|
1336 | } |
|
1337 | ||
1338 | // "0000-00-00 00:00:00" == -62169984000 |
|
1339 | if ( -62169984000 == $timestamp_gmt ) { |
|
1340 | // WordPress sets post_date=now, post_date_gmt="0000-00-00 00:00:00" for all drafts |
|
1341 | // WordPress sets post_modified=now, post_modified_gmt="0000-00-00 00:00:00" for new drafts |
|
1342 | ||
1343 | // Try to guess the correct offset from the blog's options. |
|
1344 | $timezone_string = get_option( 'timezone_string' ); |
|
1345 | ||
1346 | if ( $timezone_string && $date_time ) { |
|
1347 | $timezone = timezone_open( $timezone_string ); |
|
1348 | if ( $timezone ) { |
|
1349 | $offset = $timezone->getOffset( $date_time ); |
|
1350 | } |
|
1351 | } else { |
|
1352 | $offset = 3600 * get_option( 'gmt_offset' ); |
|
1353 | } |
|
1354 | } else { |
|
1355 | $offset = $timestamp - $timestamp_gmt; |
|
1356 | } |
|
1357 | ||
1358 | $west = $offset < 0; |
|
1359 | $offset = abs( $offset ); |
|
1360 | $hours = (int) floor( $offset / 3600 ); |
|
1361 | $offset -= $hours * 3600; |
|
1362 | $minutes = (int) floor( $offset / 60 ); |
|
1363 | } |
|
1364 | ||
1365 | return (string) gmdate( 'Y-m-d\\TH:i:s', $timestamp ) . sprintf( '%s%02d:%02d', $west ? '-' : '+', $hours, $minutes ); |
|
1366 | } |
|
1367 | ||
1368 | /** |
|
1369 | * Parses a date string and returns the local and GMT representations |
@@ 12-54 (lines=43) @@ | ||
9 | * |
|
10 | * @return string |
|
11 | */ |
|
12 | static function format_date( $date_gmt, $date = null ) { |
|
13 | $timestamp_gmt = strtotime( "$date_gmt+0000" ); |
|
14 | ||
15 | if ( null === $date ) { |
|
16 | $timestamp = $timestamp_gmt; |
|
17 | $hours = $minutes = $west = 0; |
|
18 | } else { |
|
19 | $date_time = date_create( "$date+0000" ); |
|
20 | if ( $date_time ) { |
|
21 | $timestamp = date_format( $date_time, 'U' ); |
|
22 | } else { |
|
23 | $timestamp = 0; |
|
24 | } |
|
25 | ||
26 | // "0000-00-00 00:00:00" == -62169984000 |
|
27 | if ( - 62169984000 == $timestamp_gmt ) { |
|
28 | // WordPress sets post_date=now, post_date_gmt="0000-00-00 00:00:00" for all drafts |
|
29 | // WordPress sets post_modified=now, post_modified_gmt="0000-00-00 00:00:00" for new drafts |
|
30 | ||
31 | // Try to guess the correct offset from the blog's options. |
|
32 | $timezone_string = get_option( 'timezone_string' ); |
|
33 | ||
34 | if ( $timezone_string && $date_time ) { |
|
35 | $timezone = timezone_open( $timezone_string ); |
|
36 | if ( $timezone ) { |
|
37 | $offset = $timezone->getOffset( $date_time ); |
|
38 | } |
|
39 | } else { |
|
40 | $offset = 3600 * get_option( 'gmt_offset' ); |
|
41 | } |
|
42 | } else { |
|
43 | $offset = $timestamp - $timestamp_gmt; |
|
44 | } |
|
45 | ||
46 | $west = $offset < 0; |
|
47 | $offset = abs( $offset ); |
|
48 | $hours = (int) floor( $offset / 3600 ); |
|
49 | $offset -= $hours * 3600; |
|
50 | $minutes = (int) floor( $offset / 60 ); |
|
51 | } |
|
52 | ||
53 | return (string) gmdate( 'Y-m-d\\TH:i:s', $timestamp ) . sprintf( '%s%02d:%02d', $west ? '-' : '+', $hours, $minutes ); |
|
54 | } |
|
55 | } |