Ticket #2149: 2149.patch

File 2149.patch, 1.6 KB (added by pishmishy, 4 years ago)

Preliminary patch

  • formatting.php

     
    731731// give it a date, it will give you the same date as GMT 
    732732function get_gmt_from_date($string) { 
    733733  // note: this only substracts $time_difference from the given date 
    734   preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches); 
    735   $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 
    736   $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_option('gmt_offset') * 3600); 
    737   return $string_gmt; 
     734  global $wpdb; 
     735  $offset =  get_option('gmt_offset'); 
     736  $result = $wpdb->get_results("select '$string' - INTERVAL $offset HOUR as r;"); 
     737  return $result[0]->r; 
    738738} 
    739739 
    740740// give it a GMT date, it will give you the same date with $time_difference added 
    741741function get_date_from_gmt($string) { 
    742742  // note: this only adds $time_difference to the given date 
    743   preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches); 
    744   $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 
    745   $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_option('gmt_offset')*3600); 
    746   return $string_localtime; 
     743  global $wpdb; 
     744  global $wpdb; 
     745  $offset =  get_option('gmt_offset'); 
     746  $result = $wpdb->get_results("select '$string' + INTERVAL $offset HOUR as r;"); 
     747  return $result[0]->r; 
    747748} 
    748749 
    749750// computes an offset in seconds from an iso8601 timezone