Plugin Directory

Changeset 1047433


Ignore:
Timestamp:
12/17/2014 07:26:11 PM (11 years ago)
Author:
freakingid
Message:

Catch errors in DateUtilities

File:
1 edited

Legend:

Unmodified
Added
Removed
  • content-scheduler/trunk/includes/DateUtilities.php

    r1047432 r1047433  
    88        public static function getReadableDateFromTimestamp( $unixTimestamp ) {
    99            // get datetime object from unix timestamp
    10             $datetime = new DateTime( "@$unixTimestamp", new DateTimeZone( 'UTC' ) );
     10            try {
     11                $datetime = new DateTime( "@$unixTimestamp", new DateTimeZone( 'UTC' ) );
     12            } catch (Exception $e) {
     13                $datetime = time();
     14            }
    1115            // set the timezone to the site timezone
    1216            $datetime->setTimezone( new DateTimeZone( DateUtilities::wp_get_timezone_string() ) );
     
    2832        public static function getTimestampFromReadableDate( $dateString, $offsetHours = 0 ) {
    2933            // get datetime object from site timezone
    30             $datetime = new DateTime( $dateString, new DateTimeZone( DateUtilities::wp_get_timezone_string() ) );
     34            try {
     35                $datetime = new DateTime( $dateString, new DateTimeZone( DateUtilities::wp_get_timezone_string() ) );
     36            } catch (Exception $e) {
     37                $datetime = new DateTime( "2000-01-01", new DateTimeZone( DateUtilities::wp_get_timezone_string() ) );
     38            }
    3139            // add the offsetHours
    3240            // $date->add(new DateInterval('P10D'));
Note: See TracChangeset for help on using the changeset viewer.