Make WordPress Core

Ticket #16920: get_gmt_from_date-php5-unittest.php

File get_gmt_from_date-php5-unittest.php, 707 bytes (added by technosailor, 14 years ago)

Unit test for get_gmt_from_date()

Line 
1<?php
2function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
3        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);
4        $tz = get_option('timezone_string');
5        date_default_timezone_set( $tz );
6        $datetime = new DateTime( $string );
7        $datetime->setTimezone( new DateTimeZone('UTC') );
8        $offset = $datetime->getOffset();
9        $datetime->modify( '+' . $offset / 3600 . ' hours');
10        $string_gmt = gmdate($format, $datetime->format('U'));
11        date_default_timezone_set('UTC');
12        return $string_gmt;
13}
14
15function get_option( $option )
16{
17        // Fudge get_option() outside of WP paradigm
18        return 'America/Chicago';
19}
20
21echo get_gmt_from_date('2001-03-01 12:34:56');