Completed
Branch FET-11170-model-use-money-enti... (00bce3)
by
unknown
58:42 queued 45:24
created
core/helpers/EEH_DTT_Helper.helper.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
      * Get Timezone Offset for given timezone object.
198 198
      *
199 199
      * @param DateTimeZone $date_time_zone
200
-     * @param null         $time
201
-     * @return mixed
200
+     * @param integer|null         $time
201
+     * @return integer
202 202
      * @throws InvalidArgumentException
203 203
      * @throws InvalidDataTypeException
204 204
      * @throws InvalidInterfaceException
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      * @param  DateTime   $DateTime DateTime object
321 321
      * @param  string     $period   a value to indicate what interval is being used in the calculation. The options are
322 322
      *                              'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
323
-     * @param  int|string $value    What you want to increment the date by
323
+     * @param  integer $value    What you want to increment the date by
324 324
      * @param  string     $operand  What operand you wish to use for the calculation
325 325
      * @return DateTime return whatever type came in.
326 326
      * @throws Exception
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
      * this method will add that "1" into your date regardless of the format.
857 857
      *
858 858
      * @param string $month
859
-     * @return string
859
+     * @return integer
860 860
      */
861 861
     public static function first_of_month_timestamp($month = '')
862 862
     {
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
     /**
1005 1005
      * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1006 1006
      *
1007
-     * @param int|WP_User $user_id
1007
+     * @param integer $user_id
1008 1008
      * @return string
1009 1009
      */
1010 1010
     public static function get_user_locale($user_id = 0)
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      */
135 135
     public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true)
136 136
     {
137
-        $gmt_offset =  (int) $gmt_offset;
137
+        $gmt_offset = (int) $gmt_offset;
138 138
         /** @var array[] $abbreviations */
139 139
         $abbreviations = DateTimeZone::listAbbreviations();
140 140
         foreach ($abbreviations as $abbreviation) {
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
      */
329 329
     protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
330 330
     {
331
-        if (! $DateTime instanceof DateTime) {
331
+        if ( ! $DateTime instanceof DateTime) {
332 332
             throw new EE_Error(
333 333
                 sprintf(
334 334
                     esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
@@ -338,25 +338,25 @@  discard block
 block discarded – undo
338 338
         }
339 339
         switch ($period) {
340 340
             case 'years' :
341
-                $value = 'P' . $value . 'Y';
341
+                $value = 'P'.$value.'Y';
342 342
                 break;
343 343
             case 'months' :
344
-                $value = 'P' . $value . 'M';
344
+                $value = 'P'.$value.'M';
345 345
                 break;
346 346
             case 'weeks' :
347
-                $value = 'P' . $value . 'W';
347
+                $value = 'P'.$value.'W';
348 348
                 break;
349 349
             case 'days' :
350
-                $value = 'P' . $value . 'D';
350
+                $value = 'P'.$value.'D';
351 351
                 break;
352 352
             case 'hours' :
353
-                $value = 'PT' . $value . 'H';
353
+                $value = 'PT'.$value.'H';
354 354
                 break;
355 355
             case 'minutes' :
356
-                $value = 'PT' . $value . 'M';
356
+                $value = 'PT'.$value.'M';
357 357
                 break;
358 358
             case 'seconds' :
359
-                $value = 'PT' . $value . 'S';
359
+                $value = 'PT'.$value.'S';
360 360
                 break;
361 361
         }
362 362
         switch ($operand) {
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
      */
385 385
     protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
386 386
     {
387
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
387
+        if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
388 388
             throw new EE_Error(
389 389
                 sprintf(
390 390
                     esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
                 'date' => $date_format['js'],
498 498
                 'time' => $time_format['js'],
499 499
             ),
500
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
500
+            'moment' => $date_format['moment'].' '.$time_format['moment'],
501 501
         );
502 502
     }
503 503
 
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
          *
517 517
          * @var array
518 518
          */
519
-        $symbols_map          = array(
519
+        $symbols_map = array(
520 520
             // Day
521 521
             //01
522 522
             'd' => array(
@@ -668,26 +668,26 @@  discard block
 block discarded – undo
668 668
         $escaping             = false;
669 669
         $format_string_length = strlen($format_string);
670 670
         for ($i = 0; $i < $format_string_length; $i++) {
671
-            $char = $format_string[ $i ];
671
+            $char = $format_string[$i];
672 672
             if ($char === '\\') { // PHP date format escaping character
673 673
                 $i++;
674 674
                 if ($escaping) {
675
-                    $jquery_ui_format .= $format_string[ $i ];
676
-                    $moment_format    .= $format_string[ $i ];
675
+                    $jquery_ui_format .= $format_string[$i];
676
+                    $moment_format    .= $format_string[$i];
677 677
                 } else {
678
-                    $jquery_ui_format .= '\'' . $format_string[ $i ];
679
-                    $moment_format    .= $format_string[ $i ];
678
+                    $jquery_ui_format .= '\''.$format_string[$i];
679
+                    $moment_format    .= $format_string[$i];
680 680
                 }
681 681
                 $escaping = true;
682 682
             } else {
683 683
                 if ($escaping) {
684 684
                     $jquery_ui_format .= "'";
685 685
                     $moment_format    .= "'";
686
-                    $escaping         = false;
686
+                    $escaping = false;
687 687
                 }
688
-                if (isset($symbols_map[ $char ])) {
689
-                    $jquery_ui_format .= $symbols_map[ $char ]['js'];
690
-                    $moment_format    .= $symbols_map[ $char ]['moment'];
688
+                if (isset($symbols_map[$char])) {
689
+                    $jquery_ui_format .= $symbols_map[$char]['js'];
690
+                    $moment_format    .= $symbols_map[$char]['moment'];
691 691
                 } else {
692 692
                     $jquery_ui_format .= $char;
693 693
                     $moment_format    .= $char;
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
     {
746 746
 
747 747
         if (
748
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime)
748
+            ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime)
749 749
             || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00'
750 750
                 || $date_2->format(
751 751
                     EE_Datetime_Field::mysql_time_format
@@ -781,8 +781,8 @@  discard block
 block discarded – undo
781 781
             ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS
782 782
             : (float) get_option('gmt_offset');
783 783
         $query_interval = $offset < 0
784
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
785
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
784
+            ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)'
785
+            : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)';
786 786
         return $query_interval;
787 787
     }
788 788
 
@@ -799,16 +799,16 @@  discard block
 block discarded – undo
799 799
     public static function get_timezone_string_for_display()
800 800
     {
801 801
         $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
802
-        if (! empty($pretty_timezone)) {
802
+        if ( ! empty($pretty_timezone)) {
803 803
             return esc_html($pretty_timezone);
804 804
         }
805 805
         $timezone_string = get_option('timezone_string');
806 806
         if ($timezone_string) {
807 807
             static $mo_loaded = false;
808 808
             // Load translations for continents and cities just like wp_timezone_choice does
809
-            if (! $mo_loaded) {
809
+            if ( ! $mo_loaded) {
810 810
                 $locale = get_locale();
811
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
811
+                $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo';
812 812
                 load_textdomain('continents-cities', $mofile);
813 813
                 $mo_loaded = true;
814 814
             }
@@ -831,10 +831,10 @@  discard block
 block discarded – undo
831 831
         } else {
832 832
             //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
833 833
             //to minutes, eg 30 or 15, respectively
834
-            $hour_fraction = (float) ('0.' . $parts[1]);
834
+            $hour_fraction = (float) ('0.'.$parts[1]);
835 835
             $parts[1]      = (string) $hour_fraction * 60;
836 836
         }
837
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
837
+        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts));
838 838
     }
839 839
 
840 840
 
@@ -917,9 +917,9 @@  discard block
 block discarded – undo
917 917
             'Pacific',
918 918
         );
919 919
         // Load translations for continents and cities.
920
-        if (! $mo_loaded || $locale !== $locale_loaded) {
920
+        if ( ! $mo_loaded || $locale !== $locale_loaded) {
921 921
             $locale_loaded = $locale ? $locale : get_locale();
922
-            $mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
922
+            $mofile        = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo';
923 923
             unload_textdomain('continents-cities');
924 924
             load_textdomain('continents-cities', $mofile);
925 925
             $mo_loaded = true;
@@ -927,11 +927,11 @@  discard block
 block discarded – undo
927 927
         $zone_data = array();
928 928
         foreach (timezone_identifiers_list() as $zone) {
929 929
             $zone = explode('/', $zone);
930
-            if (! in_array($zone[0], $continents, true)) {
930
+            if ( ! in_array($zone[0], $continents, true)) {
931 931
                 continue;
932 932
             }
933 933
             // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
934
-            $exists      = array(
934
+            $exists = array(
935 935
                 0 => isset($zone[0]) && $zone[0],
936 936
                 1 => isset($zone[1]) && $zone[1],
937 937
                 2 => isset($zone[2]) && $zone[2],
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
         usort($zone_data, '_wp_timezone_choice_usort_callback');
958 958
         $structure = array();
959 959
         if (empty($selected_zone)) {
960
-            $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>';
960
+            $structure[] = '<option selected="selected" value="">'.__('Select a city').'</option>';
961 961
         }
962 962
         foreach ($zone_data as $key => $zone) {
963 963
             // Build value in an array to join later
@@ -968,30 +968,30 @@  discard block
 block discarded – undo
968 968
             } else {
969 969
                 // It's inside a continent group
970 970
                 // Continent optgroup
971
-                if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) {
971
+                if ( ! isset($zone_data[$key - 1]) || $zone_data[$key - 1]['continent'] !== $zone['continent']) {
972 972
                     $label       = $zone['t_continent'];
973
-                    $structure[] = '<optgroup label="' . esc_attr($label) . '">';
973
+                    $structure[] = '<optgroup label="'.esc_attr($label).'">';
974 974
                 }
975 975
                 // Add the city to the value
976 976
                 $value[] = $zone['city'];
977 977
                 $display = $zone['t_city'];
978
-                if (! empty($zone['subcity'])) {
978
+                if ( ! empty($zone['subcity'])) {
979 979
                     // Add the subcity to the value
980 980
                     $value[] = $zone['subcity'];
981
-                    $display .= ' - ' . $zone['t_subcity'];
981
+                    $display .= ' - '.$zone['t_subcity'];
982 982
                 }
983 983
             }
984 984
             // Build the value
985 985
             $value       = implode('/', $value);
986 986
             $selected    = $value === $selected_zone ? ' selected="selected"' : '';
987
-            $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>'
987
+            $structure[] = '<option value="'.esc_attr($value).'"'.$selected.'>'
988 988
                            . esc_html($display)
989 989
                            . '</option>';
990 990
             // Close continent optgroup
991
-            if (! empty($zone['city'])
991
+            if ( ! empty($zone['city'])
992 992
                 && (
993
-                    ! isset($zone_data[ $key + 1 ])
994
-                    || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent'])
993
+                    ! isset($zone_data[$key + 1])
994
+                    || (isset($zone_data[$key + 1]) && $zone_data[$key + 1]['continent'] !== $zone['continent'])
995 995
                 )
996 996
             ) {
997 997
                 $structure[] = '</optgroup>';
Please login to merge, or discard this patch.
Indentation   +954 added lines, -954 removed lines patch added patch discarded remove patch
@@ -21,1014 +21,1014 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * return the timezone set for the WP install
26
-     *
27
-     * @return string valid timezone string for PHP DateTimeZone() class
28
-     * @throws InvalidArgumentException
29
-     * @throws InvalidDataTypeException
30
-     * @throws InvalidInterfaceException
31
-     */
32
-    public static function get_timezone()
33
-    {
34
-        return EEH_DTT_Helper::get_valid_timezone_string();
35
-    }
24
+	/**
25
+	 * return the timezone set for the WP install
26
+	 *
27
+	 * @return string valid timezone string for PHP DateTimeZone() class
28
+	 * @throws InvalidArgumentException
29
+	 * @throws InvalidDataTypeException
30
+	 * @throws InvalidInterfaceException
31
+	 */
32
+	public static function get_timezone()
33
+	{
34
+		return EEH_DTT_Helper::get_valid_timezone_string();
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     * get_valid_timezone_string
40
-     *    ensures that a valid timezone string is returned
41
-     *
42
-     * @param string $timezone_string
43
-     * @return string
44
-     * @throws InvalidArgumentException
45
-     * @throws InvalidDataTypeException
46
-     * @throws InvalidInterfaceException
47
-     */
48
-    public static function get_valid_timezone_string($timezone_string = '')
49
-    {
50
-        return self::getHelperAdapter()->getValidTimezoneString($timezone_string);
51
-    }
38
+	/**
39
+	 * get_valid_timezone_string
40
+	 *    ensures that a valid timezone string is returned
41
+	 *
42
+	 * @param string $timezone_string
43
+	 * @return string
44
+	 * @throws InvalidArgumentException
45
+	 * @throws InvalidDataTypeException
46
+	 * @throws InvalidInterfaceException
47
+	 */
48
+	public static function get_valid_timezone_string($timezone_string = '')
49
+	{
50
+		return self::getHelperAdapter()->getValidTimezoneString($timezone_string);
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
56
-     *
57
-     * @static
58
-     * @param  string $timezone_string Timezone string to check
59
-     * @param bool    $throw_error
60
-     * @return bool
61
-     * @throws InvalidArgumentException
62
-     * @throws InvalidDataTypeException
63
-     * @throws InvalidInterfaceException
64
-     */
65
-    public static function validate_timezone($timezone_string, $throw_error = true)
66
-    {
67
-        return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error);
68
-    }
54
+	/**
55
+	 * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
56
+	 *
57
+	 * @static
58
+	 * @param  string $timezone_string Timezone string to check
59
+	 * @param bool    $throw_error
60
+	 * @return bool
61
+	 * @throws InvalidArgumentException
62
+	 * @throws InvalidDataTypeException
63
+	 * @throws InvalidInterfaceException
64
+	 */
65
+	public static function validate_timezone($timezone_string, $throw_error = true)
66
+	{
67
+		return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error);
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * _create_timezone_object_from_timezone_name
73
-     *
74
-     * @param float|string $gmt_offset
75
-     * @return string
76
-     * @throws InvalidArgumentException
77
-     * @throws InvalidDataTypeException
78
-     * @throws InvalidInterfaceException
79
-     */
80
-    public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
81
-    {
82
-        return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset);
83
-    }
71
+	/**
72
+	 * _create_timezone_object_from_timezone_name
73
+	 *
74
+	 * @param float|string $gmt_offset
75
+	 * @return string
76
+	 * @throws InvalidArgumentException
77
+	 * @throws InvalidDataTypeException
78
+	 * @throws InvalidInterfaceException
79
+	 */
80
+	public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
81
+	{
82
+		return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset);
83
+	}
84 84
 
85 85
 
86
-    /**
87
-     * Gets the site's GMT offset based on either the timezone string
88
-     * (in which case teh gmt offset will vary depending on the location's
89
-     * observance of daylight savings time) or the gmt_offset wp option
90
-     *
91
-     * @return int seconds offset
92
-     * @throws InvalidArgumentException
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidInterfaceException
95
-     */
96
-    public static function get_site_timezone_gmt_offset()
97
-    {
98
-        return self::getHelperAdapter()->getSiteTimezoneGmtOffset();
99
-    }
86
+	/**
87
+	 * Gets the site's GMT offset based on either the timezone string
88
+	 * (in which case teh gmt offset will vary depending on the location's
89
+	 * observance of daylight savings time) or the gmt_offset wp option
90
+	 *
91
+	 * @return int seconds offset
92
+	 * @throws InvalidArgumentException
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidInterfaceException
95
+	 */
96
+	public static function get_site_timezone_gmt_offset()
97
+	{
98
+		return self::getHelperAdapter()->getSiteTimezoneGmtOffset();
99
+	}
100 100
 
101 101
 
102
-    /**
103
-     * Depending on PHP version,
104
-     * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
105
-     * To get around that, for these fringe timezones we bump them to a known valid offset.
106
-     * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
107
-     *
108
-     * @deprecated 4.9.54.rc    Developers this was always meant to only be an internally used method.  This will be
109
-     *                          removed in a future version of EE.
110
-     * @param int $gmt_offset
111
-     * @return int
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     */
116
-    public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
117
-    {
118
-        return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset);
119
-    }
102
+	/**
103
+	 * Depending on PHP version,
104
+	 * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
105
+	 * To get around that, for these fringe timezones we bump them to a known valid offset.
106
+	 * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
107
+	 *
108
+	 * @deprecated 4.9.54.rc    Developers this was always meant to only be an internally used method.  This will be
109
+	 *                          removed in a future version of EE.
110
+	 * @param int $gmt_offset
111
+	 * @return int
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 */
116
+	public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
117
+	{
118
+		return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset);
119
+	}
120 120
 
121 121
 
122
-    /**
123
-     * get_timezone_string_from_abbreviations_list
124
-     *
125
-     * @deprecated 4.9.54.rc  Developers, this was never intended to be public.  This is a soft deprecation for now.
126
-     *                        If you are using this, you'll want to work out an alternate way of getting the value.
127
-     * @param int  $gmt_offset
128
-     * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset.
129
-     * @return string
130
-     * @throws EE_Error
131
-     * @throws InvalidArgumentException
132
-     * @throws InvalidDataTypeException
133
-     * @throws InvalidInterfaceException
134
-     */
135
-    public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true)
136
-    {
137
-        $gmt_offset =  (int) $gmt_offset;
138
-        /** @var array[] $abbreviations */
139
-        $abbreviations = DateTimeZone::listAbbreviations();
140
-        foreach ($abbreviations as $abbreviation) {
141
-            foreach ($abbreviation as $timezone) {
142
-                if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) {
143
-                    try {
144
-                        $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id']));
145
-                        if ($offset !== $gmt_offset) {
146
-                            continue;
147
-                        }
148
-                        return $timezone['timezone_id'];
149
-                    } catch (Exception $e) {
150
-                        continue;
151
-                    }
152
-                }
153
-            }
154
-        }
155
-        //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
156
-        if ($coerce === true) {
157
-            $timezone_string = self::get_timezone_string_from_abbreviations_list(
158
-                self::adjust_invalid_gmt_offsets($gmt_offset),
159
-                false
160
-            );
161
-            if ($timezone_string) {
162
-                return $timezone_string;
163
-            }
164
-        }
165
-        throw new EE_Error(
166
-            sprintf(
167
-                esc_html__(
168
-                    'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
169
-                    'event_espresso'
170
-                ),
171
-                $gmt_offset / HOUR_IN_SECONDS,
172
-                '<a href="http://www.php.net/manual/en/timezones.php">',
173
-                '</a>'
174
-            )
175
-        );
176
-    }
122
+	/**
123
+	 * get_timezone_string_from_abbreviations_list
124
+	 *
125
+	 * @deprecated 4.9.54.rc  Developers, this was never intended to be public.  This is a soft deprecation for now.
126
+	 *                        If you are using this, you'll want to work out an alternate way of getting the value.
127
+	 * @param int  $gmt_offset
128
+	 * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset.
129
+	 * @return string
130
+	 * @throws EE_Error
131
+	 * @throws InvalidArgumentException
132
+	 * @throws InvalidDataTypeException
133
+	 * @throws InvalidInterfaceException
134
+	 */
135
+	public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true)
136
+	{
137
+		$gmt_offset =  (int) $gmt_offset;
138
+		/** @var array[] $abbreviations */
139
+		$abbreviations = DateTimeZone::listAbbreviations();
140
+		foreach ($abbreviations as $abbreviation) {
141
+			foreach ($abbreviation as $timezone) {
142
+				if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) {
143
+					try {
144
+						$offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id']));
145
+						if ($offset !== $gmt_offset) {
146
+							continue;
147
+						}
148
+						return $timezone['timezone_id'];
149
+					} catch (Exception $e) {
150
+						continue;
151
+					}
152
+				}
153
+			}
154
+		}
155
+		//if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
156
+		if ($coerce === true) {
157
+			$timezone_string = self::get_timezone_string_from_abbreviations_list(
158
+				self::adjust_invalid_gmt_offsets($gmt_offset),
159
+				false
160
+			);
161
+			if ($timezone_string) {
162
+				return $timezone_string;
163
+			}
164
+		}
165
+		throw new EE_Error(
166
+			sprintf(
167
+				esc_html__(
168
+					'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
169
+					'event_espresso'
170
+				),
171
+				$gmt_offset / HOUR_IN_SECONDS,
172
+				'<a href="http://www.php.net/manual/en/timezones.php">',
173
+				'</a>'
174
+			)
175
+		);
176
+	}
177 177
 
178 178
 
179
-    /**
180
-     * Get Timezone Transitions
181
-     *
182
-     * @param DateTimeZone $date_time_zone
183
-     * @param int|null     $time
184
-     * @param bool         $first_only
185
-     * @return array
186
-     * @throws InvalidArgumentException
187
-     * @throws InvalidDataTypeException
188
-     * @throws InvalidInterfaceException
189
-     */
190
-    public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
191
-    {
192
-        return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only);
193
-    }
179
+	/**
180
+	 * Get Timezone Transitions
181
+	 *
182
+	 * @param DateTimeZone $date_time_zone
183
+	 * @param int|null     $time
184
+	 * @param bool         $first_only
185
+	 * @return array
186
+	 * @throws InvalidArgumentException
187
+	 * @throws InvalidDataTypeException
188
+	 * @throws InvalidInterfaceException
189
+	 */
190
+	public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
191
+	{
192
+		return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only);
193
+	}
194 194
 
195 195
 
196
-    /**
197
-     * Get Timezone Offset for given timezone object.
198
-     *
199
-     * @param DateTimeZone $date_time_zone
200
-     * @param null         $time
201
-     * @return mixed
202
-     * @throws InvalidArgumentException
203
-     * @throws InvalidDataTypeException
204
-     * @throws InvalidInterfaceException
205
-     */
206
-    public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null)
207
-    {
208
-        return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time);
209
-    }
196
+	/**
197
+	 * Get Timezone Offset for given timezone object.
198
+	 *
199
+	 * @param DateTimeZone $date_time_zone
200
+	 * @param null         $time
201
+	 * @return mixed
202
+	 * @throws InvalidArgumentException
203
+	 * @throws InvalidDataTypeException
204
+	 * @throws InvalidInterfaceException
205
+	 */
206
+	public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null)
207
+	{
208
+		return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time);
209
+	}
210 210
 
211 211
 
212
-    /**
213
-     * Prints a select input for the given timezone string.
214
-     * @param string $timezone_string
215
-     * @deprecatd 4.9.54.rc   Soft deprecation.  Consider using \EEH_DTT_Helper::wp_timezone_choice instead.
216
-     * @throws InvalidArgumentException
217
-     * @throws InvalidDataTypeException
218
-     * @throws InvalidInterfaceException
219
-     */
220
-    public static function timezone_select_input($timezone_string = '')
221
-    {
222
-        self::getHelperAdapter()->timezoneSelectInput($timezone_string);
223
-    }
212
+	/**
213
+	 * Prints a select input for the given timezone string.
214
+	 * @param string $timezone_string
215
+	 * @deprecatd 4.9.54.rc   Soft deprecation.  Consider using \EEH_DTT_Helper::wp_timezone_choice instead.
216
+	 * @throws InvalidArgumentException
217
+	 * @throws InvalidDataTypeException
218
+	 * @throws InvalidInterfaceException
219
+	 */
220
+	public static function timezone_select_input($timezone_string = '')
221
+	{
222
+		self::getHelperAdapter()->timezoneSelectInput($timezone_string);
223
+	}
224 224
 
225 225
 
226
-    /**
227
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
228
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
229
-     * the site is used.
230
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
231
-     * computed timestamp (i.e. date_i18n() )
232
-     *
233
-     * @param int    $unix_timestamp                  if 0, then time() will be used.
234
-     * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
235
-     *                                                site will be used.
236
-     * @return int $unix_timestamp with the offset applied for the given timezone.
237
-     * @throws InvalidArgumentException
238
-     * @throws InvalidDataTypeException
239
-     * @throws InvalidInterfaceException
240
-     */
241
-    public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
242
-    {
243
-        return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string);
244
-    }
226
+	/**
227
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
228
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
229
+	 * the site is used.
230
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
231
+	 * computed timestamp (i.e. date_i18n() )
232
+	 *
233
+	 * @param int    $unix_timestamp                  if 0, then time() will be used.
234
+	 * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
235
+	 *                                                site will be used.
236
+	 * @return int $unix_timestamp with the offset applied for the given timezone.
237
+	 * @throws InvalidArgumentException
238
+	 * @throws InvalidDataTypeException
239
+	 * @throws InvalidInterfaceException
240
+	 */
241
+	public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
242
+	{
243
+		return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string);
244
+	}
245 245
 
246 246
 
247
-    /**
248
-     *    _set_date_time_field
249
-     *    modifies EE_Base_Class EE_Datetime_Field objects
250
-     *
251
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
252
-     * @param    DateTime    $DateTime            PHP DateTime object
253
-     * @param  string        $datetime_field_name the datetime fieldname to be manipulated
254
-     * @return EE_Base_Class
255
-     * @throws EE_Error
256
-     */
257
-    protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
258
-    {
259
-        // grab current datetime format
260
-        $current_format = $obj->get_format();
261
-        // set new full timestamp format
262
-        $obj->set_date_format(EE_Datetime_Field::mysql_date_format);
263
-        $obj->set_time_format(EE_Datetime_Field::mysql_time_format);
264
-        // set the new date value using a full timestamp format so that no data is lost
265
-        $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
266
-        // reset datetime formats
267
-        $obj->set_date_format($current_format[0]);
268
-        $obj->set_time_format($current_format[1]);
269
-        return $obj;
270
-    }
247
+	/**
248
+	 *    _set_date_time_field
249
+	 *    modifies EE_Base_Class EE_Datetime_Field objects
250
+	 *
251
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
252
+	 * @param    DateTime    $DateTime            PHP DateTime object
253
+	 * @param  string        $datetime_field_name the datetime fieldname to be manipulated
254
+	 * @return EE_Base_Class
255
+	 * @throws EE_Error
256
+	 */
257
+	protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
258
+	{
259
+		// grab current datetime format
260
+		$current_format = $obj->get_format();
261
+		// set new full timestamp format
262
+		$obj->set_date_format(EE_Datetime_Field::mysql_date_format);
263
+		$obj->set_time_format(EE_Datetime_Field::mysql_time_format);
264
+		// set the new date value using a full timestamp format so that no data is lost
265
+		$obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
266
+		// reset datetime formats
267
+		$obj->set_date_format($current_format[0]);
268
+		$obj->set_time_format($current_format[1]);
269
+		return $obj;
270
+	}
271 271
 
272 272
 
273
-    /**
274
-     *    date_time_add
275
-     *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
276
-     *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
277
-     *
278
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
279
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
280
-     * @param  string        $period              what you are adding. The options are (years, months, days, hours,
281
-     *                                            minutes, seconds) defaults to years
282
-     * @param  integer       $value               what you want to increment the time by
283
-     * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it
284
-     *                                            (chaining)
285
-     * @throws EE_Error
286
-     * @throws Exception
287
-     */
288
-    public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
289
-    {
290
-        //get the raw UTC date.
291
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
292
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
293
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
294
-    }
273
+	/**
274
+	 *    date_time_add
275
+	 *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
276
+	 *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
277
+	 *
278
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
279
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
280
+	 * @param  string        $period              what you are adding. The options are (years, months, days, hours,
281
+	 *                                            minutes, seconds) defaults to years
282
+	 * @param  integer       $value               what you want to increment the time by
283
+	 * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it
284
+	 *                                            (chaining)
285
+	 * @throws EE_Error
286
+	 * @throws Exception
287
+	 */
288
+	public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
289
+	{
290
+		//get the raw UTC date.
291
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
292
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
293
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
294
+	}
295 295
 
296 296
 
297
-    /**
298
-     *    date_time_subtract
299
-     *    same as date_time_add except subtracting value instead of adding.
300
-     *
301
-     * @param EE_Base_Class $obj
302
-     * @param  string       $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
303
-     * @param string        $period
304
-     * @param int           $value
305
-     * @return EE_Base_Class
306
-     * @throws EE_Error
307
-     * @throws Exception
308
-     */
309
-    public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
310
-    {
311
-        //get the raw UTC date
312
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
313
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
314
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
315
-    }
297
+	/**
298
+	 *    date_time_subtract
299
+	 *    same as date_time_add except subtracting value instead of adding.
300
+	 *
301
+	 * @param EE_Base_Class $obj
302
+	 * @param  string       $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
303
+	 * @param string        $period
304
+	 * @param int           $value
305
+	 * @return EE_Base_Class
306
+	 * @throws EE_Error
307
+	 * @throws Exception
308
+	 */
309
+	public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
310
+	{
311
+		//get the raw UTC date
312
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
313
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
314
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
315
+	}
316 316
 
317 317
 
318
-    /**
319
-     * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
320
-     *
321
-     * @param  DateTime   $DateTime DateTime object
322
-     * @param  string     $period   a value to indicate what interval is being used in the calculation. The options are
323
-     *                              'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
324
-     * @param  int|string $value    What you want to increment the date by
325
-     * @param  string     $operand  What operand you wish to use for the calculation
326
-     * @return DateTime return whatever type came in.
327
-     * @throws Exception
328
-     * @throws EE_Error
329
-     */
330
-    protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
331
-    {
332
-        if (! $DateTime instanceof DateTime) {
333
-            throw new EE_Error(
334
-                sprintf(
335
-                    esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
336
-                    print_r($DateTime, true)
337
-                )
338
-            );
339
-        }
340
-        switch ($period) {
341
-            case 'years' :
342
-                $value = 'P' . $value . 'Y';
343
-                break;
344
-            case 'months' :
345
-                $value = 'P' . $value . 'M';
346
-                break;
347
-            case 'weeks' :
348
-                $value = 'P' . $value . 'W';
349
-                break;
350
-            case 'days' :
351
-                $value = 'P' . $value . 'D';
352
-                break;
353
-            case 'hours' :
354
-                $value = 'PT' . $value . 'H';
355
-                break;
356
-            case 'minutes' :
357
-                $value = 'PT' . $value . 'M';
358
-                break;
359
-            case 'seconds' :
360
-                $value = 'PT' . $value . 'S';
361
-                break;
362
-        }
363
-        switch ($operand) {
364
-            case '+':
365
-                $DateTime->add(new DateInterval($value));
366
-                break;
367
-            case '-':
368
-                $DateTime->sub(new DateInterval($value));
369
-                break;
370
-        }
371
-        return $DateTime;
372
-    }
318
+	/**
319
+	 * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
320
+	 *
321
+	 * @param  DateTime   $DateTime DateTime object
322
+	 * @param  string     $period   a value to indicate what interval is being used in the calculation. The options are
323
+	 *                              'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
324
+	 * @param  int|string $value    What you want to increment the date by
325
+	 * @param  string     $operand  What operand you wish to use for the calculation
326
+	 * @return DateTime return whatever type came in.
327
+	 * @throws Exception
328
+	 * @throws EE_Error
329
+	 */
330
+	protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
331
+	{
332
+		if (! $DateTime instanceof DateTime) {
333
+			throw new EE_Error(
334
+				sprintf(
335
+					esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
336
+					print_r($DateTime, true)
337
+				)
338
+			);
339
+		}
340
+		switch ($period) {
341
+			case 'years' :
342
+				$value = 'P' . $value . 'Y';
343
+				break;
344
+			case 'months' :
345
+				$value = 'P' . $value . 'M';
346
+				break;
347
+			case 'weeks' :
348
+				$value = 'P' . $value . 'W';
349
+				break;
350
+			case 'days' :
351
+				$value = 'P' . $value . 'D';
352
+				break;
353
+			case 'hours' :
354
+				$value = 'PT' . $value . 'H';
355
+				break;
356
+			case 'minutes' :
357
+				$value = 'PT' . $value . 'M';
358
+				break;
359
+			case 'seconds' :
360
+				$value = 'PT' . $value . 'S';
361
+				break;
362
+		}
363
+		switch ($operand) {
364
+			case '+':
365
+				$DateTime->add(new DateInterval($value));
366
+				break;
367
+			case '-':
368
+				$DateTime->sub(new DateInterval($value));
369
+				break;
370
+		}
371
+		return $DateTime;
372
+	}
373 373
 
374 374
 
375
-    /**
376
-     * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
377
-     *
378
-     * @param  int     $timestamp Unix timestamp
379
-     * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
380
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
381
-     * @param  integer $value     What you want to increment the date by
382
-     * @param  string  $operand   What operand you wish to use for the calculation
383
-     * @return int
384
-     * @throws EE_Error
385
-     */
386
-    protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
387
-    {
388
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
389
-            throw new EE_Error(
390
-                sprintf(
391
-                    esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
392
-                    print_r($timestamp, true)
393
-                )
394
-            );
395
-        }
396
-        switch ($period) {
397
-            case 'years' :
398
-                $value = YEAR_IN_SECONDS * $value;
399
-                break;
400
-            case 'months' :
401
-                $value = YEAR_IN_SECONDS / 12 * $value;
402
-                break;
403
-            case 'weeks' :
404
-                $value = WEEK_IN_SECONDS * $value;
405
-                break;
406
-            case 'days' :
407
-                $value = DAY_IN_SECONDS * $value;
408
-                break;
409
-            case 'hours' :
410
-                $value = HOUR_IN_SECONDS * $value;
411
-                break;
412
-            case 'minutes' :
413
-                $value = MINUTE_IN_SECONDS * $value;
414
-                break;
415
-        }
416
-        switch ($operand) {
417
-            case '+':
418
-                $timestamp += $value;
419
-                break;
420
-            case '-':
421
-                $timestamp -= $value;
422
-                break;
423
-        }
424
-        return $timestamp;
425
-    }
375
+	/**
376
+	 * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
377
+	 *
378
+	 * @param  int     $timestamp Unix timestamp
379
+	 * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
380
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
381
+	 * @param  integer $value     What you want to increment the date by
382
+	 * @param  string  $operand   What operand you wish to use for the calculation
383
+	 * @return int
384
+	 * @throws EE_Error
385
+	 */
386
+	protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
387
+	{
388
+		if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
389
+			throw new EE_Error(
390
+				sprintf(
391
+					esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
392
+					print_r($timestamp, true)
393
+				)
394
+			);
395
+		}
396
+		switch ($period) {
397
+			case 'years' :
398
+				$value = YEAR_IN_SECONDS * $value;
399
+				break;
400
+			case 'months' :
401
+				$value = YEAR_IN_SECONDS / 12 * $value;
402
+				break;
403
+			case 'weeks' :
404
+				$value = WEEK_IN_SECONDS * $value;
405
+				break;
406
+			case 'days' :
407
+				$value = DAY_IN_SECONDS * $value;
408
+				break;
409
+			case 'hours' :
410
+				$value = HOUR_IN_SECONDS * $value;
411
+				break;
412
+			case 'minutes' :
413
+				$value = MINUTE_IN_SECONDS * $value;
414
+				break;
415
+		}
416
+		switch ($operand) {
417
+			case '+':
418
+				$timestamp += $value;
419
+				break;
420
+			case '-':
421
+				$timestamp -= $value;
422
+				break;
423
+		}
424
+		return $timestamp;
425
+	}
426 426
 
427 427
 
428
-    /**
429
-     * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
430
-     * parameters and returns the new timestamp or DateTime.
431
-     *
432
-     * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
433
-     * @param  string         $period                a value to indicate what interval is being used in the
434
-     *                                               calculation. The options are 'years', 'months', 'days', 'hours',
435
-     *                                               'minutes', 'seconds'. Defaults to years.
436
-     * @param  integer        $value                 What you want to increment the date by
437
-     * @param  string         $operand               What operand you wish to use for the calculation
438
-     * @return mixed string|DateTime          return whatever type came in.
439
-     * @throws Exception
440
-     * @throws EE_Error
441
-     */
442
-    public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
443
-    {
444
-        if ($DateTime_or_timestamp instanceof DateTime) {
445
-            return EEH_DTT_Helper::_modify_datetime_object(
446
-                $DateTime_or_timestamp,
447
-                $period,
448
-                $value,
449
-                $operand
450
-            );
451
-        }
452
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
453
-            return EEH_DTT_Helper::_modify_timestamp(
454
-                $DateTime_or_timestamp,
455
-                $period,
456
-                $value,
457
-                $operand
458
-            );
459
-        }
460
-        //error
461
-        return $DateTime_or_timestamp;
462
-    }
428
+	/**
429
+	 * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
430
+	 * parameters and returns the new timestamp or DateTime.
431
+	 *
432
+	 * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
433
+	 * @param  string         $period                a value to indicate what interval is being used in the
434
+	 *                                               calculation. The options are 'years', 'months', 'days', 'hours',
435
+	 *                                               'minutes', 'seconds'. Defaults to years.
436
+	 * @param  integer        $value                 What you want to increment the date by
437
+	 * @param  string         $operand               What operand you wish to use for the calculation
438
+	 * @return mixed string|DateTime          return whatever type came in.
439
+	 * @throws Exception
440
+	 * @throws EE_Error
441
+	 */
442
+	public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
443
+	{
444
+		if ($DateTime_or_timestamp instanceof DateTime) {
445
+			return EEH_DTT_Helper::_modify_datetime_object(
446
+				$DateTime_or_timestamp,
447
+				$period,
448
+				$value,
449
+				$operand
450
+			);
451
+		}
452
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
453
+			return EEH_DTT_Helper::_modify_timestamp(
454
+				$DateTime_or_timestamp,
455
+				$period,
456
+				$value,
457
+				$operand
458
+			);
459
+		}
460
+		//error
461
+		return $DateTime_or_timestamp;
462
+	}
463 463
 
464 464
 
465
-    /**
466
-     * The purpose of this helper method is to receive an incoming format string in php date/time format
467
-     * and spit out the js and moment.js equivalent formats.
468
-     * Note, if no format string is given, then it is assumed the user wants what is set for WP.
469
-     * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
470
-     * time picker.
471
-     *
472
-     * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
473
-     * @param string $date_format_string
474
-     * @param string $time_format_string
475
-     * @return array
476
-     *              array(
477
-     *              'js' => array (
478
-     *              'date' => //date format
479
-     *              'time' => //time format
480
-     *              ),
481
-     *              'moment' => //date and time format.
482
-     *              )
483
-     */
484
-    public static function convert_php_to_js_and_moment_date_formats(
485
-        $date_format_string = null,
486
-        $time_format_string = null
487
-    ) {
488
-        if ($date_format_string === null) {
489
-            $date_format_string = (string) get_option('date_format');
490
-        }
491
-        if ($time_format_string === null) {
492
-            $time_format_string = (string) get_option('time_format');
493
-        }
494
-        $date_format = self::_php_to_js_moment_converter($date_format_string);
495
-        $time_format = self::_php_to_js_moment_converter($time_format_string);
496
-        return array(
497
-            'js'     => array(
498
-                'date' => $date_format['js'],
499
-                'time' => $time_format['js'],
500
-            ),
501
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
502
-        );
503
-    }
465
+	/**
466
+	 * The purpose of this helper method is to receive an incoming format string in php date/time format
467
+	 * and spit out the js and moment.js equivalent formats.
468
+	 * Note, if no format string is given, then it is assumed the user wants what is set for WP.
469
+	 * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
470
+	 * time picker.
471
+	 *
472
+	 * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
473
+	 * @param string $date_format_string
474
+	 * @param string $time_format_string
475
+	 * @return array
476
+	 *              array(
477
+	 *              'js' => array (
478
+	 *              'date' => //date format
479
+	 *              'time' => //time format
480
+	 *              ),
481
+	 *              'moment' => //date and time format.
482
+	 *              )
483
+	 */
484
+	public static function convert_php_to_js_and_moment_date_formats(
485
+		$date_format_string = null,
486
+		$time_format_string = null
487
+	) {
488
+		if ($date_format_string === null) {
489
+			$date_format_string = (string) get_option('date_format');
490
+		}
491
+		if ($time_format_string === null) {
492
+			$time_format_string = (string) get_option('time_format');
493
+		}
494
+		$date_format = self::_php_to_js_moment_converter($date_format_string);
495
+		$time_format = self::_php_to_js_moment_converter($time_format_string);
496
+		return array(
497
+			'js'     => array(
498
+				'date' => $date_format['js'],
499
+				'time' => $time_format['js'],
500
+			),
501
+			'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
502
+		);
503
+	}
504 504
 
505 505
 
506
-    /**
507
-     * This converts incoming format string into js and moment variations.
508
-     *
509
-     * @param string $format_string incoming php format string
510
-     * @return array js and moment formats.
511
-     */
512
-    protected static function _php_to_js_moment_converter($format_string)
513
-    {
514
-        /**
515
-         * This is a map of symbols for formats.
516
-         * The index is the php symbol, the equivalent values are in the array.
517
-         *
518
-         * @var array
519
-         */
520
-        $symbols_map          = array(
521
-            // Day
522
-            //01
523
-            'd' => array(
524
-                'js'     => 'dd',
525
-                'moment' => 'DD',
526
-            ),
527
-            //Mon
528
-            'D' => array(
529
-                'js'     => 'D',
530
-                'moment' => 'ddd',
531
-            ),
532
-            //1,2,...31
533
-            'j' => array(
534
-                'js'     => 'd',
535
-                'moment' => 'D',
536
-            ),
537
-            //Monday
538
-            'l' => array(
539
-                'js'     => 'DD',
540
-                'moment' => 'dddd',
541
-            ),
542
-            //ISO numeric representation of the day of the week (1-6)
543
-            'N' => array(
544
-                'js'     => '',
545
-                'moment' => 'E',
546
-            ),
547
-            //st,nd.rd
548
-            'S' => array(
549
-                'js'     => '',
550
-                'moment' => 'o',
551
-            ),
552
-            //numeric representation of day of week (0-6)
553
-            'w' => array(
554
-                'js'     => '',
555
-                'moment' => 'd',
556
-            ),
557
-            //day of year starting from 0 (0-365)
558
-            'z' => array(
559
-                'js'     => 'o',
560
-                'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1
561
-            ),
562
-            // Week
563
-            //ISO-8601 week number of year (weeks starting on monday)
564
-            'W' => array(
565
-                'js'     => '',
566
-                'moment' => 'w',
567
-            ),
568
-            // Month
569
-            // January...December
570
-            'F' => array(
571
-                'js'     => 'MM',
572
-                'moment' => 'MMMM',
573
-            ),
574
-            //01...12
575
-            'm' => array(
576
-                'js'     => 'mm',
577
-                'moment' => 'MM',
578
-            ),
579
-            //Jan...Dec
580
-            'M' => array(
581
-                'js'     => 'M',
582
-                'moment' => 'MMM',
583
-            ),
584
-            //1-12
585
-            'n' => array(
586
-                'js'     => 'm',
587
-                'moment' => 'M',
588
-            ),
589
-            //number of days in given month
590
-            't' => array(
591
-                'js'     => '',
592
-                'moment' => '',
593
-            ),
594
-            // Year
595
-            //whether leap year or not 1/0
596
-            'L' => array(
597
-                'js'     => '',
598
-                'moment' => '',
599
-            ),
600
-            //ISO-8601 year number
601
-            'o' => array(
602
-                'js'     => '',
603
-                'moment' => 'GGGG',
604
-            ),
605
-            //1999...2003
606
-            'Y' => array(
607
-                'js'     => 'yy',
608
-                'moment' => 'YYYY',
609
-            ),
610
-            //99...03
611
-            'y' => array(
612
-                'js'     => 'y',
613
-                'moment' => 'YY',
614
-            ),
615
-            // Time
616
-            // am/pm
617
-            'a' => array(
618
-                'js'     => 'tt',
619
-                'moment' => 'a',
620
-            ),
621
-            // AM/PM
622
-            'A' => array(
623
-                'js'     => 'TT',
624
-                'moment' => 'A',
625
-            ),
626
-            // Swatch Internet Time?!?
627
-            'B' => array(
628
-                'js'     => '',
629
-                'moment' => '',
630
-            ),
631
-            //1...12
632
-            'g' => array(
633
-                'js'     => 'h',
634
-                'moment' => 'h',
635
-            ),
636
-            //0...23
637
-            'G' => array(
638
-                'js'     => 'H',
639
-                'moment' => 'H',
640
-            ),
641
-            //01...12
642
-            'h' => array(
643
-                'js'     => 'hh',
644
-                'moment' => 'hh',
645
-            ),
646
-            //00...23
647
-            'H' => array(
648
-                'js'     => 'HH',
649
-                'moment' => 'HH',
650
-            ),
651
-            //00..59
652
-            'i' => array(
653
-                'js'     => 'mm',
654
-                'moment' => 'mm',
655
-            ),
656
-            //seconds... 00...59
657
-            's' => array(
658
-                'js'     => 'ss',
659
-                'moment' => 'ss',
660
-            ),
661
-            //microseconds
662
-            'u' => array(
663
-                'js'     => '',
664
-                'moment' => '',
665
-            ),
666
-        );
667
-        $jquery_ui_format     = '';
668
-        $moment_format        = '';
669
-        $escaping             = false;
670
-        $format_string_length = strlen($format_string);
671
-        for ($i = 0; $i < $format_string_length; $i++) {
672
-            $char = $format_string[ $i ];
673
-            if ($char === '\\') { // PHP date format escaping character
674
-                $i++;
675
-                if ($escaping) {
676
-                    $jquery_ui_format .= $format_string[ $i ];
677
-                    $moment_format    .= $format_string[ $i ];
678
-                } else {
679
-                    $jquery_ui_format .= '\'' . $format_string[ $i ];
680
-                    $moment_format    .= $format_string[ $i ];
681
-                }
682
-                $escaping = true;
683
-            } else {
684
-                if ($escaping) {
685
-                    $jquery_ui_format .= "'";
686
-                    $moment_format    .= "'";
687
-                    $escaping         = false;
688
-                }
689
-                if (isset($symbols_map[ $char ])) {
690
-                    $jquery_ui_format .= $symbols_map[ $char ]['js'];
691
-                    $moment_format    .= $symbols_map[ $char ]['moment'];
692
-                } else {
693
-                    $jquery_ui_format .= $char;
694
-                    $moment_format    .= $char;
695
-                }
696
-            }
697
-        }
698
-        return array('js' => $jquery_ui_format, 'moment' => $moment_format);
699
-    }
506
+	/**
507
+	 * This converts incoming format string into js and moment variations.
508
+	 *
509
+	 * @param string $format_string incoming php format string
510
+	 * @return array js and moment formats.
511
+	 */
512
+	protected static function _php_to_js_moment_converter($format_string)
513
+	{
514
+		/**
515
+		 * This is a map of symbols for formats.
516
+		 * The index is the php symbol, the equivalent values are in the array.
517
+		 *
518
+		 * @var array
519
+		 */
520
+		$symbols_map          = array(
521
+			// Day
522
+			//01
523
+			'd' => array(
524
+				'js'     => 'dd',
525
+				'moment' => 'DD',
526
+			),
527
+			//Mon
528
+			'D' => array(
529
+				'js'     => 'D',
530
+				'moment' => 'ddd',
531
+			),
532
+			//1,2,...31
533
+			'j' => array(
534
+				'js'     => 'd',
535
+				'moment' => 'D',
536
+			),
537
+			//Monday
538
+			'l' => array(
539
+				'js'     => 'DD',
540
+				'moment' => 'dddd',
541
+			),
542
+			//ISO numeric representation of the day of the week (1-6)
543
+			'N' => array(
544
+				'js'     => '',
545
+				'moment' => 'E',
546
+			),
547
+			//st,nd.rd
548
+			'S' => array(
549
+				'js'     => '',
550
+				'moment' => 'o',
551
+			),
552
+			//numeric representation of day of week (0-6)
553
+			'w' => array(
554
+				'js'     => '',
555
+				'moment' => 'd',
556
+			),
557
+			//day of year starting from 0 (0-365)
558
+			'z' => array(
559
+				'js'     => 'o',
560
+				'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1
561
+			),
562
+			// Week
563
+			//ISO-8601 week number of year (weeks starting on monday)
564
+			'W' => array(
565
+				'js'     => '',
566
+				'moment' => 'w',
567
+			),
568
+			// Month
569
+			// January...December
570
+			'F' => array(
571
+				'js'     => 'MM',
572
+				'moment' => 'MMMM',
573
+			),
574
+			//01...12
575
+			'm' => array(
576
+				'js'     => 'mm',
577
+				'moment' => 'MM',
578
+			),
579
+			//Jan...Dec
580
+			'M' => array(
581
+				'js'     => 'M',
582
+				'moment' => 'MMM',
583
+			),
584
+			//1-12
585
+			'n' => array(
586
+				'js'     => 'm',
587
+				'moment' => 'M',
588
+			),
589
+			//number of days in given month
590
+			't' => array(
591
+				'js'     => '',
592
+				'moment' => '',
593
+			),
594
+			// Year
595
+			//whether leap year or not 1/0
596
+			'L' => array(
597
+				'js'     => '',
598
+				'moment' => '',
599
+			),
600
+			//ISO-8601 year number
601
+			'o' => array(
602
+				'js'     => '',
603
+				'moment' => 'GGGG',
604
+			),
605
+			//1999...2003
606
+			'Y' => array(
607
+				'js'     => 'yy',
608
+				'moment' => 'YYYY',
609
+			),
610
+			//99...03
611
+			'y' => array(
612
+				'js'     => 'y',
613
+				'moment' => 'YY',
614
+			),
615
+			// Time
616
+			// am/pm
617
+			'a' => array(
618
+				'js'     => 'tt',
619
+				'moment' => 'a',
620
+			),
621
+			// AM/PM
622
+			'A' => array(
623
+				'js'     => 'TT',
624
+				'moment' => 'A',
625
+			),
626
+			// Swatch Internet Time?!?
627
+			'B' => array(
628
+				'js'     => '',
629
+				'moment' => '',
630
+			),
631
+			//1...12
632
+			'g' => array(
633
+				'js'     => 'h',
634
+				'moment' => 'h',
635
+			),
636
+			//0...23
637
+			'G' => array(
638
+				'js'     => 'H',
639
+				'moment' => 'H',
640
+			),
641
+			//01...12
642
+			'h' => array(
643
+				'js'     => 'hh',
644
+				'moment' => 'hh',
645
+			),
646
+			//00...23
647
+			'H' => array(
648
+				'js'     => 'HH',
649
+				'moment' => 'HH',
650
+			),
651
+			//00..59
652
+			'i' => array(
653
+				'js'     => 'mm',
654
+				'moment' => 'mm',
655
+			),
656
+			//seconds... 00...59
657
+			's' => array(
658
+				'js'     => 'ss',
659
+				'moment' => 'ss',
660
+			),
661
+			//microseconds
662
+			'u' => array(
663
+				'js'     => '',
664
+				'moment' => '',
665
+			),
666
+		);
667
+		$jquery_ui_format     = '';
668
+		$moment_format        = '';
669
+		$escaping             = false;
670
+		$format_string_length = strlen($format_string);
671
+		for ($i = 0; $i < $format_string_length; $i++) {
672
+			$char = $format_string[ $i ];
673
+			if ($char === '\\') { // PHP date format escaping character
674
+				$i++;
675
+				if ($escaping) {
676
+					$jquery_ui_format .= $format_string[ $i ];
677
+					$moment_format    .= $format_string[ $i ];
678
+				} else {
679
+					$jquery_ui_format .= '\'' . $format_string[ $i ];
680
+					$moment_format    .= $format_string[ $i ];
681
+				}
682
+				$escaping = true;
683
+			} else {
684
+				if ($escaping) {
685
+					$jquery_ui_format .= "'";
686
+					$moment_format    .= "'";
687
+					$escaping         = false;
688
+				}
689
+				if (isset($symbols_map[ $char ])) {
690
+					$jquery_ui_format .= $symbols_map[ $char ]['js'];
691
+					$moment_format    .= $symbols_map[ $char ]['moment'];
692
+				} else {
693
+					$jquery_ui_format .= $char;
694
+					$moment_format    .= $char;
695
+				}
696
+			}
697
+		}
698
+		return array('js' => $jquery_ui_format, 'moment' => $moment_format);
699
+	}
700 700
 
701 701
 
702
-    /**
703
-     * This takes an incoming format string and validates it to ensure it will work fine with PHP.
704
-     *
705
-     * @param string $format_string   Incoming format string for php date().
706
-     * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
707
-     *                                errors is returned.  So for client code calling, check for is_array() to
708
-     *                                indicate failed validations.
709
-     */
710
-    public static function validate_format_string($format_string)
711
-    {
712
-        $error_msg = array();
713
-        //time format checks
714
-        switch (true) {
715
-            case   strpos($format_string, 'h') !== false  :
716
-            case   strpos($format_string, 'g') !== false :
717
-                /**
718
-                 * if the time string has a lowercase 'h' which == 12 hour time format and there
719
-                 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
720
-                 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
721
-                 */
722
-                if (stripos($format_string, 'A') === false) {
723
-                    $error_msg[] = esc_html__(
724
-                        'There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
725
-                        'event_espresso'
726
-                    );
727
-                }
728
-                break;
729
-        }
730
-        return empty($error_msg) ? true : $error_msg;
731
-    }
702
+	/**
703
+	 * This takes an incoming format string and validates it to ensure it will work fine with PHP.
704
+	 *
705
+	 * @param string $format_string   Incoming format string for php date().
706
+	 * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
707
+	 *                                errors is returned.  So for client code calling, check for is_array() to
708
+	 *                                indicate failed validations.
709
+	 */
710
+	public static function validate_format_string($format_string)
711
+	{
712
+		$error_msg = array();
713
+		//time format checks
714
+		switch (true) {
715
+			case   strpos($format_string, 'h') !== false  :
716
+			case   strpos($format_string, 'g') !== false :
717
+				/**
718
+				 * if the time string has a lowercase 'h' which == 12 hour time format and there
719
+				 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
720
+				 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
721
+				 */
722
+				if (stripos($format_string, 'A') === false) {
723
+					$error_msg[] = esc_html__(
724
+						'There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
725
+						'event_espresso'
726
+					);
727
+				}
728
+				break;
729
+		}
730
+		return empty($error_msg) ? true : $error_msg;
731
+	}
732 732
 
733 733
 
734
-    /**
735
-     *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
736
-     *     very next day then this method will return true.
737
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
738
-     *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
739
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
740
-     *
741
-     * @param mixed $date_1
742
-     * @param mixed $date_2
743
-     * @return bool
744
-     */
745
-    public static function dates_represent_one_24_hour_date($date_1, $date_2)
746
-    {
734
+	/**
735
+	 *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
736
+	 *     very next day then this method will return true.
737
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
738
+	 *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
739
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
740
+	 *
741
+	 * @param mixed $date_1
742
+	 * @param mixed $date_2
743
+	 * @return bool
744
+	 */
745
+	public static function dates_represent_one_24_hour_date($date_1, $date_2)
746
+	{
747 747
 
748
-        if (
749
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime)
750
-            || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00'
751
-                || $date_2->format(
752
-                    EE_Datetime_Field::mysql_time_format
753
-                ) !== '00:00:00')
754
-        ) {
755
-            return false;
756
-        }
757
-        return $date_2->format('U') - $date_1->format('U') === 86400;
758
-    }
748
+		if (
749
+			(! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime)
750
+			|| ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00'
751
+				|| $date_2->format(
752
+					EE_Datetime_Field::mysql_time_format
753
+				) !== '00:00:00')
754
+		) {
755
+			return false;
756
+		}
757
+		return $date_2->format('U') - $date_1->format('U') === 86400;
758
+	}
759 759
 
760 760
 
761
-    /**
762
-     * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
763
-     * Functions.
764
-     *
765
-     * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
766
-     * @param string $field_for_interval The Database field that is the interval is applied to in the query.
767
-     * @return string
768
-     */
769
-    public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
770
-    {
771
-        try {
772
-            /** need to account for timezone offset on the selects */
773
-            $DateTimeZone = new DateTimeZone($timezone_string);
774
-        } catch (Exception $e) {
775
-            $DateTimeZone = null;
776
-        }
777
-        /**
778
-         * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
779
-         * Hence we do the calc for DateTimeZone::getOffset.
780
-         */
781
-        $offset         = $DateTimeZone instanceof DateTimeZone
782
-            ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS
783
-            : (float) get_option('gmt_offset');
784
-        $query_interval = $offset < 0
785
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
786
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
787
-        return $query_interval;
788
-    }
761
+	/**
762
+	 * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
763
+	 * Functions.
764
+	 *
765
+	 * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
766
+	 * @param string $field_for_interval The Database field that is the interval is applied to in the query.
767
+	 * @return string
768
+	 */
769
+	public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
770
+	{
771
+		try {
772
+			/** need to account for timezone offset on the selects */
773
+			$DateTimeZone = new DateTimeZone($timezone_string);
774
+		} catch (Exception $e) {
775
+			$DateTimeZone = null;
776
+		}
777
+		/**
778
+		 * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
779
+		 * Hence we do the calc for DateTimeZone::getOffset.
780
+		 */
781
+		$offset         = $DateTimeZone instanceof DateTimeZone
782
+			? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS
783
+			: (float) get_option('gmt_offset');
784
+		$query_interval = $offset < 0
785
+			? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
786
+			: 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
787
+		return $query_interval;
788
+	}
789 789
 
790 790
 
791
-    /**
792
-     * Retrieves the site's default timezone and returns it formatted so it's ready for display
793
-     * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
794
-     * and 'gmt_offset' WordPress options directly; or use the filter
795
-     * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
796
-     * (although note that we remove any HTML that may be added)
797
-     *
798
-     * @return string
799
-     */
800
-    public static function get_timezone_string_for_display()
801
-    {
802
-        $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
803
-        if (! empty($pretty_timezone)) {
804
-            return esc_html($pretty_timezone);
805
-        }
806
-        $timezone_string = get_option('timezone_string');
807
-        if ($timezone_string) {
808
-            static $mo_loaded = false;
809
-            // Load translations for continents and cities just like wp_timezone_choice does
810
-            if (! $mo_loaded) {
811
-                $locale = get_locale();
812
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
813
-                load_textdomain('continents-cities', $mofile);
814
-                $mo_loaded = true;
815
-            }
816
-            //well that was easy.
817
-            $parts = explode('/', $timezone_string);
818
-            //remove the continent
819
-            unset($parts[0]);
820
-            $t_parts = array();
821
-            foreach ($parts as $part) {
822
-                $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
823
-            }
824
-            return implode(' - ', $t_parts);
825
-        }
826
-        //they haven't set the timezone string, so let's return a string like "UTC+1"
827
-        $gmt_offset = get_option('gmt_offset');
828
-        $prefix     = (int) $gmt_offset >= 0 ? '+' : '';
829
-        $parts      = explode('.', (string) $gmt_offset);
830
-        if (count($parts) === 1) {
831
-            $parts[1] = '00';
832
-        } else {
833
-            //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
834
-            //to minutes, eg 30 or 15, respectively
835
-            $hour_fraction = (float) ('0.' . $parts[1]);
836
-            $parts[1]      = (string) $hour_fraction * 60;
837
-        }
838
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
839
-    }
791
+	/**
792
+	 * Retrieves the site's default timezone and returns it formatted so it's ready for display
793
+	 * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
794
+	 * and 'gmt_offset' WordPress options directly; or use the filter
795
+	 * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
796
+	 * (although note that we remove any HTML that may be added)
797
+	 *
798
+	 * @return string
799
+	 */
800
+	public static function get_timezone_string_for_display()
801
+	{
802
+		$pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
803
+		if (! empty($pretty_timezone)) {
804
+			return esc_html($pretty_timezone);
805
+		}
806
+		$timezone_string = get_option('timezone_string');
807
+		if ($timezone_string) {
808
+			static $mo_loaded = false;
809
+			// Load translations for continents and cities just like wp_timezone_choice does
810
+			if (! $mo_loaded) {
811
+				$locale = get_locale();
812
+				$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
813
+				load_textdomain('continents-cities', $mofile);
814
+				$mo_loaded = true;
815
+			}
816
+			//well that was easy.
817
+			$parts = explode('/', $timezone_string);
818
+			//remove the continent
819
+			unset($parts[0]);
820
+			$t_parts = array();
821
+			foreach ($parts as $part) {
822
+				$t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
823
+			}
824
+			return implode(' - ', $t_parts);
825
+		}
826
+		//they haven't set the timezone string, so let's return a string like "UTC+1"
827
+		$gmt_offset = get_option('gmt_offset');
828
+		$prefix     = (int) $gmt_offset >= 0 ? '+' : '';
829
+		$parts      = explode('.', (string) $gmt_offset);
830
+		if (count($parts) === 1) {
831
+			$parts[1] = '00';
832
+		} else {
833
+			//convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
834
+			//to minutes, eg 30 or 15, respectively
835
+			$hour_fraction = (float) ('0.' . $parts[1]);
836
+			$parts[1]      = (string) $hour_fraction * 60;
837
+		}
838
+		return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
839
+	}
840 840
 
841 841
 
842 842
 
843
-    /**
844
-     * So PHP does this awesome thing where if you are trying to get a timestamp
845
-     * for a month using a string like "February" or "February 2017",
846
-     * and you don't specify a day as part of your string,
847
-     * then PHP will use whatever the current day of the month is.
848
-     * IF the current day of the month happens to be the 30th or 31st,
849
-     * then PHP gets really confused by a date like February 30,
850
-     * so instead of saying
851
-     *      "Hey February only has 28 days (this year)...
852
-     *      ...you must have meant the last day of the month!"
853
-     * PHP does the next most logical thing, and bumps the date up to March 2nd,
854
-     * because someone requesting February 30th obviously meant March 1st!
855
-     * The way around this is to always set the day to the first,
856
-     * so that the month will stay on the month you wanted.
857
-     * this method will add that "1" into your date regardless of the format.
858
-     *
859
-     * @param string $month
860
-     * @return string
861
-     */
862
-    public static function first_of_month_timestamp($month = '')
863
-    {
864
-        $month = (string) $month;
865
-        $year  = '';
866
-        // check if the incoming string has a year in it or not
867
-        if (preg_match('/\b\d{4}\b/', $month, $matches)) {
868
-            $year = $matches[0];
869
-            // ten remove that from the month string as well as any spaces
870
-            $month = trim(str_replace($year, '', $month));
871
-            // add a space before the year
872
-            $year = " {$year}";
873
-        }
874
-        // return timestamp for something like "February 1 2017"
875
-        return strtotime("{$month} 1{$year}");
876
-    }
843
+	/**
844
+	 * So PHP does this awesome thing where if you are trying to get a timestamp
845
+	 * for a month using a string like "February" or "February 2017",
846
+	 * and you don't specify a day as part of your string,
847
+	 * then PHP will use whatever the current day of the month is.
848
+	 * IF the current day of the month happens to be the 30th or 31st,
849
+	 * then PHP gets really confused by a date like February 30,
850
+	 * so instead of saying
851
+	 *      "Hey February only has 28 days (this year)...
852
+	 *      ...you must have meant the last day of the month!"
853
+	 * PHP does the next most logical thing, and bumps the date up to March 2nd,
854
+	 * because someone requesting February 30th obviously meant March 1st!
855
+	 * The way around this is to always set the day to the first,
856
+	 * so that the month will stay on the month you wanted.
857
+	 * this method will add that "1" into your date regardless of the format.
858
+	 *
859
+	 * @param string $month
860
+	 * @return string
861
+	 */
862
+	public static function first_of_month_timestamp($month = '')
863
+	{
864
+		$month = (string) $month;
865
+		$year  = '';
866
+		// check if the incoming string has a year in it or not
867
+		if (preg_match('/\b\d{4}\b/', $month, $matches)) {
868
+			$year = $matches[0];
869
+			// ten remove that from the month string as well as any spaces
870
+			$month = trim(str_replace($year, '', $month));
871
+			// add a space before the year
872
+			$year = " {$year}";
873
+		}
874
+		// return timestamp for something like "February 1 2017"
875
+		return strtotime("{$month} 1{$year}");
876
+	}
877 877
 
878 878
 
879
-    /**
880
-     * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
881
-     * for this sites timezone, but the timestamp could be some other time GMT.
882
-     */
883
-    public static function tomorrow()
884
-    {
885
-        //The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive
886
-        //before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
887
-        //not an offset from midnight in UTC.  So if we're starting with UTC 00:00:00, then we want to make sure the
888
-        //final timestamp is equivalent to midnight in this timezone as represented in GMT.
889
-        return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1);
890
-    }
879
+	/**
880
+	 * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
881
+	 * for this sites timezone, but the timestamp could be some other time GMT.
882
+	 */
883
+	public static function tomorrow()
884
+	{
885
+		//The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive
886
+		//before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
887
+		//not an offset from midnight in UTC.  So if we're starting with UTC 00:00:00, then we want to make sure the
888
+		//final timestamp is equivalent to midnight in this timezone as represented in GMT.
889
+		return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1);
890
+	}
891 891
 
892 892
 
893
-    /**
894
-     * **
895
-     * Gives a nicely-formatted list of timezone strings.
896
-     * Copied from the core wp function by the same name so we could customize to remove UTC offsets.
897
-     *
898
-     * @since     4.9.40.rc.008
899
-     * @staticvar bool $mo_loaded
900
-     * @staticvar string $locale_loaded
901
-     * @param string $selected_zone Selected timezone.
902
-     * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
903
-     * @return string
904
-     */
905
-    public static function wp_timezone_choice($selected_zone, $locale = null)
906
-    {
907
-        static $mo_loaded = false, $locale_loaded = null;
908
-        $continents = array(
909
-            'Africa',
910
-            'America',
911
-            'Antarctica',
912
-            'Arctic',
913
-            'Asia',
914
-            'Atlantic',
915
-            'Australia',
916
-            'Europe',
917
-            'Indian',
918
-            'Pacific',
919
-        );
920
-        // Load translations for continents and cities.
921
-        if (! $mo_loaded || $locale !== $locale_loaded) {
922
-            $locale_loaded = $locale ? $locale : get_locale();
923
-            $mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
924
-            unload_textdomain('continents-cities');
925
-            load_textdomain('continents-cities', $mofile);
926
-            $mo_loaded = true;
927
-        }
928
-        $zone_data = array();
929
-        foreach (timezone_identifiers_list() as $zone) {
930
-            $zone = explode('/', $zone);
931
-            if (! in_array($zone[0], $continents, true)) {
932
-                continue;
933
-            }
934
-            // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
935
-            $exists      = array(
936
-                0 => isset($zone[0]) && $zone[0],
937
-                1 => isset($zone[1]) && $zone[1],
938
-                2 => isset($zone[2]) && $zone[2],
939
-            );
940
-            $exists[3]   = $exists[0] && $zone[0] !== 'Etc';
941
-            $exists[4]   = $exists[1] && $exists[3];
942
-            $exists[5]   = $exists[2] && $exists[3];
943
-            $zone_data[] = array(
944
-                'continent'   => $exists[0] ? $zone[0] : '',
945
-                'city'        => $exists[1] ? $zone[1] : '',
946
-                'subcity'     => $exists[2] ? $zone[2] : '',
947
-                't_continent' => $exists[3]
948
-                    ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities')
949
-                    : '',
950
-                't_city'      => $exists[4]
951
-                    ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities')
952
-                    : '',
953
-                't_subcity'   => $exists[5]
954
-                    ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities')
955
-                    : '',
956
-            );
957
-        }
958
-        usort($zone_data, '_wp_timezone_choice_usort_callback');
959
-        $structure = array();
960
-        if (empty($selected_zone)) {
961
-            $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>';
962
-        }
963
-        foreach ($zone_data as $key => $zone) {
964
-            // Build value in an array to join later
965
-            $value = array($zone['continent']);
966
-            if (empty($zone['city'])) {
967
-                // It's at the continent level (generally won't happen)
968
-                $display = $zone['t_continent'];
969
-            } else {
970
-                // It's inside a continent group
971
-                // Continent optgroup
972
-                if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) {
973
-                    $label       = $zone['t_continent'];
974
-                    $structure[] = '<optgroup label="' . esc_attr($label) . '">';
975
-                }
976
-                // Add the city to the value
977
-                $value[] = $zone['city'];
978
-                $display = $zone['t_city'];
979
-                if (! empty($zone['subcity'])) {
980
-                    // Add the subcity to the value
981
-                    $value[] = $zone['subcity'];
982
-                    $display .= ' - ' . $zone['t_subcity'];
983
-                }
984
-            }
985
-            // Build the value
986
-            $value       = implode('/', $value);
987
-            $selected    = $value === $selected_zone ? ' selected="selected"' : '';
988
-            $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>'
989
-                           . esc_html($display)
990
-                           . '</option>';
991
-            // Close continent optgroup
992
-            if (! empty($zone['city'])
993
-                && (
994
-                    ! isset($zone_data[ $key + 1 ])
995
-                    || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent'])
996
-                )
997
-            ) {
998
-                $structure[] = '</optgroup>';
999
-            }
1000
-        }
1001
-        return implode("\n", $structure);
1002
-    }
893
+	/**
894
+	 * **
895
+	 * Gives a nicely-formatted list of timezone strings.
896
+	 * Copied from the core wp function by the same name so we could customize to remove UTC offsets.
897
+	 *
898
+	 * @since     4.9.40.rc.008
899
+	 * @staticvar bool $mo_loaded
900
+	 * @staticvar string $locale_loaded
901
+	 * @param string $selected_zone Selected timezone.
902
+	 * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
903
+	 * @return string
904
+	 */
905
+	public static function wp_timezone_choice($selected_zone, $locale = null)
906
+	{
907
+		static $mo_loaded = false, $locale_loaded = null;
908
+		$continents = array(
909
+			'Africa',
910
+			'America',
911
+			'Antarctica',
912
+			'Arctic',
913
+			'Asia',
914
+			'Atlantic',
915
+			'Australia',
916
+			'Europe',
917
+			'Indian',
918
+			'Pacific',
919
+		);
920
+		// Load translations for continents and cities.
921
+		if (! $mo_loaded || $locale !== $locale_loaded) {
922
+			$locale_loaded = $locale ? $locale : get_locale();
923
+			$mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
924
+			unload_textdomain('continents-cities');
925
+			load_textdomain('continents-cities', $mofile);
926
+			$mo_loaded = true;
927
+		}
928
+		$zone_data = array();
929
+		foreach (timezone_identifiers_list() as $zone) {
930
+			$zone = explode('/', $zone);
931
+			if (! in_array($zone[0], $continents, true)) {
932
+				continue;
933
+			}
934
+			// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
935
+			$exists      = array(
936
+				0 => isset($zone[0]) && $zone[0],
937
+				1 => isset($zone[1]) && $zone[1],
938
+				2 => isset($zone[2]) && $zone[2],
939
+			);
940
+			$exists[3]   = $exists[0] && $zone[0] !== 'Etc';
941
+			$exists[4]   = $exists[1] && $exists[3];
942
+			$exists[5]   = $exists[2] && $exists[3];
943
+			$zone_data[] = array(
944
+				'continent'   => $exists[0] ? $zone[0] : '',
945
+				'city'        => $exists[1] ? $zone[1] : '',
946
+				'subcity'     => $exists[2] ? $zone[2] : '',
947
+				't_continent' => $exists[3]
948
+					? translate(str_replace('_', ' ', $zone[0]), 'continents-cities')
949
+					: '',
950
+				't_city'      => $exists[4]
951
+					? translate(str_replace('_', ' ', $zone[1]), 'continents-cities')
952
+					: '',
953
+				't_subcity'   => $exists[5]
954
+					? translate(str_replace('_', ' ', $zone[2]), 'continents-cities')
955
+					: '',
956
+			);
957
+		}
958
+		usort($zone_data, '_wp_timezone_choice_usort_callback');
959
+		$structure = array();
960
+		if (empty($selected_zone)) {
961
+			$structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>';
962
+		}
963
+		foreach ($zone_data as $key => $zone) {
964
+			// Build value in an array to join later
965
+			$value = array($zone['continent']);
966
+			if (empty($zone['city'])) {
967
+				// It's at the continent level (generally won't happen)
968
+				$display = $zone['t_continent'];
969
+			} else {
970
+				// It's inside a continent group
971
+				// Continent optgroup
972
+				if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) {
973
+					$label       = $zone['t_continent'];
974
+					$structure[] = '<optgroup label="' . esc_attr($label) . '">';
975
+				}
976
+				// Add the city to the value
977
+				$value[] = $zone['city'];
978
+				$display = $zone['t_city'];
979
+				if (! empty($zone['subcity'])) {
980
+					// Add the subcity to the value
981
+					$value[] = $zone['subcity'];
982
+					$display .= ' - ' . $zone['t_subcity'];
983
+				}
984
+			}
985
+			// Build the value
986
+			$value       = implode('/', $value);
987
+			$selected    = $value === $selected_zone ? ' selected="selected"' : '';
988
+			$structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>'
989
+						   . esc_html($display)
990
+						   . '</option>';
991
+			// Close continent optgroup
992
+			if (! empty($zone['city'])
993
+				&& (
994
+					! isset($zone_data[ $key + 1 ])
995
+					|| (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent'])
996
+				)
997
+			) {
998
+				$structure[] = '</optgroup>';
999
+			}
1000
+		}
1001
+		return implode("\n", $structure);
1002
+	}
1003 1003
 
1004 1004
 
1005
-    /**
1006
-     * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1007
-     *
1008
-     * @param int|WP_User $user_id
1009
-     * @return string
1010
-     */
1011
-    public static function get_user_locale($user_id = 0)
1012
-    {
1013
-        if (function_exists('get_user_locale')) {
1014
-            return get_user_locale($user_id);
1015
-        }
1016
-        return get_locale();
1017
-    }
1005
+	/**
1006
+	 * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1007
+	 *
1008
+	 * @param int|WP_User $user_id
1009
+	 * @return string
1010
+	 */
1011
+	public static function get_user_locale($user_id = 0)
1012
+	{
1013
+		if (function_exists('get_user_locale')) {
1014
+			return get_user_locale($user_id);
1015
+		}
1016
+		return get_locale();
1017
+	}
1018 1018
 
1019 1019
 
1020
-    /**
1021
-     * Return the appropriate helper adapter for DTT related things.
1022
-     *
1023
-     * @return HelperInterface
1024
-     * @throws InvalidArgumentException
1025
-     * @throws InvalidDataTypeException
1026
-     * @throws InvalidInterfaceException
1027
-     */
1028
-    private static function getHelperAdapter() {
1029
-        $dtt_helper_fqcn = PHP_VERSION_ID < 50600
1030
-            ? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper'
1031
-            : 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper';
1032
-        return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn);
1033
-    }
1020
+	/**
1021
+	 * Return the appropriate helper adapter for DTT related things.
1022
+	 *
1023
+	 * @return HelperInterface
1024
+	 * @throws InvalidArgumentException
1025
+	 * @throws InvalidDataTypeException
1026
+	 * @throws InvalidInterfaceException
1027
+	 */
1028
+	private static function getHelperAdapter() {
1029
+		$dtt_helper_fqcn = PHP_VERSION_ID < 50600
1030
+			? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper'
1031
+			: 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper';
1032
+		return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn);
1033
+	}
1034 1034
 }
1035 1035
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Datetime_Field.php 1 patch
Indentation   +755 added lines, -755 removed lines patch added patch discarded remove patch
@@ -17,760 +17,760 @@
 block discarded – undo
17 17
 class EE_Datetime_Field extends EE_Model_Field_Base
18 18
 {
19 19
 
20
-    /**
21
-     * The pattern we're looking for is if only the characters 0-9 are found and there are only
22
-     * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
23
-     *
24
-     * @type string unix_timestamp_regex
25
-     */
26
-    const unix_timestamp_regex = '/[0-9]{10,}/';
27
-
28
-    /**
29
-     * @type string mysql_timestamp_format
30
-     */
31
-    const mysql_timestamp_format = 'Y-m-d H:i:s';
32
-
33
-    /**
34
-     * @type string mysql_date_format
35
-     */
36
-    const mysql_date_format = 'Y-m-d';
37
-
38
-    /**
39
-     * @type string mysql_time_format
40
-     */
41
-    const mysql_time_format = 'H:i:s';
42
-
43
-    /**
44
-     * Const for using in the default value. If the field's default is set to this,
45
-     * then we will return the time of calling `get_default_value()`, not
46
-     * just the current time at construction
47
-     */
48
-    const now = 'now';
49
-
50
-    /**
51
-     * The following properties hold the default formats for date and time.
52
-     * Defaults are set via the constructor and can be overridden on class instantiation.
53
-     * However they can also be overridden later by the set_format() method
54
-     * (and corresponding set_date_format, set_time_format methods);
55
-     */
56
-    /**
57
-     * @type string $_date_format
58
-     */
59
-    protected $_date_format = '';
60
-
61
-    /**
62
-     * @type string $_time_format
63
-     */
64
-    protected $_time_format = '';
65
-
66
-    /**
67
-     * @type string $_pretty_date_format
68
-     */
69
-    protected $_pretty_date_format = '';
70
-
71
-    /**
72
-     * @type string $_pretty_time_format
73
-     */
74
-    protected $_pretty_time_format = '';
75
-
76
-    /**
77
-     * @type DateTimeZone $_DateTimeZone
78
-     */
79
-    protected $_DateTimeZone;
80
-
81
-    /**
82
-     * @type DateTimeZone $_UTC_DateTimeZone
83
-     */
84
-    protected $_UTC_DateTimeZone;
85
-
86
-    /**
87
-     * @type DateTimeZone $_blog_DateTimeZone
88
-     */
89
-    protected $_blog_DateTimeZone;
90
-
91
-
92
-    /**
93
-     * This property holds how we want the output returned when getting a datetime string.  It is set for the
94
-     * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
95
-     * and time returned via getters.
96
-     *
97
-     * @var mixed (null|string)
98
-     */
99
-    protected $_date_time_output;
100
-
101
-
102
-    /**
103
-     * timezone string
104
-     * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
105
-     * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
106
-     * coming out of the object to be in.  Default timezone is the current WP timezone option setting
107
-     *
108
-     * @var string
109
-     */
110
-    protected $_timezone_string;
111
-
112
-
113
-    /**
114
-     * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
115
-     * offsets for comparison purposes).
116
-     *
117
-     * @var int
118
-     */
119
-    protected $_blog_offset;
120
-
121
-
122
-
123
-    /**
124
-     * @param string $table_column
125
-     * @param string $nice_name
126
-     * @param bool   $nullable
127
-     * @param string $default_value
128
-     * @param string $timezone_string
129
-     * @param string $date_format
130
-     * @param string $time_format
131
-     * @param string $pretty_date_format
132
-     * @param string $pretty_time_format
133
-     * @throws EE_Error
134
-     * @throws InvalidArgumentException
135
-     */
136
-    public function __construct(
137
-        $table_column,
138
-        $nice_name,
139
-        $nullable,
140
-        $default_value,
141
-        $timezone_string = '',
142
-        $date_format = '',
143
-        $time_format = '',
144
-        $pretty_date_format = '',
145
-        $pretty_time_format = ''
146
-    ) {
147
-
148
-        $this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
149
-        $this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
150
-        $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
151
-        $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
152
-
153
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
154
-        $this->set_timezone($timezone_string);
155
-        $this->setSchemaFormat('date-time');
156
-    }
157
-
158
-
159
-    /**
160
-     * @return DateTimeZone
161
-     * @throws \EE_Error
162
-     */
163
-    public function get_UTC_DateTimeZone()
164
-    {
165
-        return $this->_UTC_DateTimeZone instanceof DateTimeZone
166
-            ? $this->_UTC_DateTimeZone
167
-            : $this->_create_timezone_object_from_timezone_string('UTC');
168
-    }
169
-
170
-
171
-    /**
172
-     * @return DateTimeZone
173
-     * @throws \EE_Error
174
-     */
175
-    public function get_blog_DateTimeZone()
176
-    {
177
-        return $this->_blog_DateTimeZone instanceof DateTimeZone
178
-            ? $this->_blog_DateTimeZone
179
-            : $this->_create_timezone_object_from_timezone_string('');
180
-    }
181
-
182
-
183
-    /**
184
-     * this prepares any incoming date data and make sure its converted to a utc unix timestamp
185
-     *
186
-     * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
187
-     *                                                              timestamp
188
-     * @return DateTime
189
-     */
190
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
191
-    {
192
-        return $this->_get_date_object($value_inputted_for_field_on_model_object);
193
-    }
194
-
195
-
196
-    /**
197
-     * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
198
-     * getters need to know whether we're just returning the date or the time or both.  By default we return both.
199
-     *
200
-     * @param bool $pretty If we're returning the pretty formats or standard format string.
201
-     * @return string    The final assembled format string.
202
-     */
203
-    protected function _get_date_time_output($pretty = false)
204
-    {
205
-
206
-        switch ($this->_date_time_output) {
207
-            case 'time' :
208
-                return $pretty ? $this->_pretty_time_format : $this->_time_format;
209
-                break;
210
-
211
-            case 'date' :
212
-                return $pretty ? $this->_pretty_date_format : $this->_date_format;
213
-                break;
214
-
215
-            default :
216
-                return $pretty
217
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
218
-                    : $this->_date_format . ' ' . $this->_time_format;
219
-        }
220
-    }
221
-
222
-
223
-    /**
224
-     * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
225
-     * returned (using the format properties)
226
-     *
227
-     * @param string $what acceptable values are 'time' or 'date'.
228
-     *                     Any other value will be set but will always result
229
-     *                     in both 'date' and 'time' being returned.
230
-     * @return void
231
-     */
232
-    public function set_date_time_output($what = null)
233
-    {
234
-        $this->_date_time_output = $what;
235
-    }
236
-
237
-
238
-    /**
239
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
240
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
241
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
242
-     * We also set some other properties in this method.
243
-     *
244
-     * @param string $timezone_string A valid timezone string as described by @link
245
-     *                                http://www.php.net/manual/en/timezones.php
246
-     * @return void
247
-     * @throws InvalidArgumentException
248
-     * @throws InvalidDataTypeException
249
-     * @throws InvalidInterfaceException
250
-     */
251
-    public function set_timezone($timezone_string)
252
-    {
253
-        if (empty($timezone_string) && $this->_timezone_string !== null) {
254
-            // leave the timezone AS-IS if we already have one and
255
-            // the function arg didn't provide one
256
-            return;
257
-        }
258
-        $timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
259
-        $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
260
-        $this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
261
-    }
262
-
263
-
264
-    /**
265
-     * _create_timezone_object_from_timezone_name
266
-     *
267
-     * @access protected
268
-     * @param string $timezone_string
269
-     * @return \DateTimeZone
270
-     * @throws InvalidArgumentException
271
-     * @throws InvalidDataTypeException
272
-     * @throws InvalidInterfaceException
273
-     */
274
-    protected function _create_timezone_object_from_timezone_string($timezone_string = '')
275
-    {
276
-        return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
277
-    }
278
-
279
-
280
-    /**
281
-     * This just returns whatever is set for the current timezone.
282
-     *
283
-     * @access public
284
-     * @return string timezone string
285
-     */
286
-    public function get_timezone()
287
-    {
288
-        return $this->_timezone_string;
289
-    }
290
-
291
-
292
-    /**
293
-     * set the $_date_format property
294
-     *
295
-     * @access public
296
-     * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
297
-     * @param bool   $pretty Whether to set pretty format or not.
298
-     * @return void
299
-     */
300
-    public function set_date_format($format, $pretty = false)
301
-    {
302
-        if ($pretty) {
303
-            $this->_pretty_date_format = $format;
304
-        } else {
305
-            $this->_date_format = $format;
306
-        }
307
-    }
308
-
309
-
310
-    /**
311
-     * return the $_date_format property value.
312
-     *
313
-     * @param bool $pretty Whether to get pretty format or not.
314
-     * @return string
315
-     */
316
-    public function get_date_format($pretty = false)
317
-    {
318
-        return $pretty ? $this->_pretty_date_format : $this->_date_format;
319
-    }
320
-
321
-
322
-    /**
323
-     * set the $_time_format property
324
-     *
325
-     * @access public
326
-     * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
327
-     * @param bool   $pretty Whether to set pretty format or not.
328
-     * @return void
329
-     */
330
-    public function set_time_format($format, $pretty = false)
331
-    {
332
-        if ($pretty) {
333
-            $this->_pretty_time_format = $format;
334
-        } else {
335
-            $this->_time_format = $format;
336
-        }
337
-    }
338
-
339
-
340
-    /**
341
-     * return the $_time_format property value.
342
-     *
343
-     * @param bool $pretty Whether to get pretty format or not.
344
-     * @return string
345
-     */
346
-    public function get_time_format($pretty = false)
347
-    {
348
-        return $pretty ? $this->_pretty_time_format : $this->_time_format;
349
-    }
350
-
351
-
352
-    /**
353
-     * set the $_pretty_date_format property
354
-     *
355
-     * @access public
356
-     * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
357
-     * @return void
358
-     */
359
-    public function set_pretty_date_format($format)
360
-    {
361
-        $this->_pretty_date_format = $format;
362
-    }
363
-
364
-
365
-    /**
366
-     * set the $_pretty_time_format property
367
-     *
368
-     * @access public
369
-     * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
370
-     * @return void
371
-     */
372
-    public function set_pretty_time_format($format)
373
-    {
374
-        $this->_pretty_time_format = $format;
375
-    }
376
-
377
-
378
-    /**
379
-     * Only sets the time portion of the datetime.
380
-     *
381
-     * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
382
-     * @param DateTime        $current            current DateTime object for the datetime field
383
-     * @return DateTime
384
-     */
385
-    public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
386
-    {
387
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
388
-        // Otherwise parse the string.
389
-        if ($time_to_set_string instanceof DateTime) {
390
-            $parsed = array(
391
-                'hour'   => $time_to_set_string->format('H'),
392
-                'minute' => $time_to_set_string->format('i'),
393
-                'second' => $time_to_set_string->format('s'),
394
-            );
395
-        } else {
396
-            //parse incoming string
397
-            $parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
398
-        }
399
-
400
-        //make sure $current is in the correct timezone.
401
-        $current->setTimezone($this->_DateTimeZone);
402
-
403
-        return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
404
-    }
405
-
406
-
407
-    /**
408
-     * Only sets the date portion of the datetime.
409
-     *
410
-     * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
411
-     * @param DateTime        $current            current DateTime object for the datetime field
412
-     * @return DateTime
413
-     */
414
-    public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
415
-    {
416
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
417
-        // Otherwise parse the string.
418
-        if ($date_to_set_string instanceof DateTime) {
419
-            $parsed = array(
420
-                'year'  => $date_to_set_string->format('Y'),
421
-                'month' => $date_to_set_string->format('m'),
422
-                'day'   => $date_to_set_string->format('d'),
423
-            );
424
-        } else {
425
-            //parse incoming string
426
-            $parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
427
-        }
428
-
429
-        //make sure $current is in the correct timezone
430
-        $current->setTimezone($this->_DateTimeZone);
431
-
432
-        return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
433
-    }
434
-
435
-
436
-    /**
437
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
438
-     * datetime gets to this stage it should ALREADY be in UTC time
439
-     *
440
-     * @param  DateTime $DateTime
441
-     * @return string formatted date time for given timezone
442
-     * @throws \EE_Error
443
-     */
444
-    public function prepare_for_get($DateTime)
445
-    {
446
-        return $this->_prepare_for_display($DateTime);
447
-    }
448
-
449
-
450
-    /**
451
-     * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
452
-     * from the set wp timezone.  If so, then it returns the datetime string formatted via
453
-     * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
454
-     * abbreviation to the date_string.
455
-     *
456
-     * @param mixed $DateTime
457
-     * @param null  $schema
458
-     * @return string
459
-     * @throws \EE_Error
460
-     */
461
-    public function prepare_for_pretty_echoing($DateTime, $schema = null)
462
-    {
463
-        return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
464
-    }
465
-
466
-
467
-    /**
468
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
469
-     * timezone).
470
-     *
471
-     * @param DateTime    $DateTime
472
-     * @param bool|string $schema
473
-     * @return string
474
-     * @throws \EE_Error
475
-     */
476
-    protected function _prepare_for_display($DateTime, $schema = false)
477
-    {
478
-        if (! $DateTime instanceof DateTime) {
479
-            if ($this->_nullable) {
480
-                return '';
481
-            } else {
482
-                if (WP_DEBUG) {
483
-                    throw new EE_Error(
484
-                        sprintf(
485
-                            __(
486
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
487
-                                'event_espresso'
488
-                            ),
489
-                            $this->_nicename
490
-                        )
491
-                    );
492
-                } else {
493
-                    $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
494
-                    EE_Error::add_error(
495
-                        sprintf(
496
-                            __(
497
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
498
-                                'event_espresso'
499
-                            ),
500
-                            $this->_nicename
501
-                        )
502
-                    );
503
-                }
504
-            }
505
-        }
506
-        $format_string = $this->_get_date_time_output($schema);
507
-        //make sure datetime_value is in the correct timezone (in case that's been updated).
508
-        $DateTime->setTimezone($this->_DateTimeZone);
509
-        if ($schema) {
510
-            if ($this->_display_timezone()) {
511
-                //must be explicit because schema could equal true.
512
-                if ($schema === 'no_html') {
513
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
514
-                } else {
515
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
516
-                }
517
-            } else {
518
-                $timezone_string = '';
519
-            }
520
-
521
-            return $DateTime->format($format_string) . $timezone_string;
522
-        } else {
523
-            return $DateTime->format($format_string);
524
-        }
525
-    }
526
-
527
-
528
-    /**
529
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
530
-     * timezone).
531
-     *
532
-     * @param  mixed $datetime_value u
533
-     * @return string mysql timestamp in UTC
534
-     * @throws \EE_Error
535
-     */
536
-    public function prepare_for_use_in_db($datetime_value)
537
-    {
538
-        //we allow an empty value or DateTime object, but nothing else.
539
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
540
-            throw new EE_Error(
541
-            	sprintf(
542
-            	    __(
543
-            		    'The incoming value being prepared for setting in the database must either be empty or a php 
20
+	/**
21
+	 * The pattern we're looking for is if only the characters 0-9 are found and there are only
22
+	 * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
23
+	 *
24
+	 * @type string unix_timestamp_regex
25
+	 */
26
+	const unix_timestamp_regex = '/[0-9]{10,}/';
27
+
28
+	/**
29
+	 * @type string mysql_timestamp_format
30
+	 */
31
+	const mysql_timestamp_format = 'Y-m-d H:i:s';
32
+
33
+	/**
34
+	 * @type string mysql_date_format
35
+	 */
36
+	const mysql_date_format = 'Y-m-d';
37
+
38
+	/**
39
+	 * @type string mysql_time_format
40
+	 */
41
+	const mysql_time_format = 'H:i:s';
42
+
43
+	/**
44
+	 * Const for using in the default value. If the field's default is set to this,
45
+	 * then we will return the time of calling `get_default_value()`, not
46
+	 * just the current time at construction
47
+	 */
48
+	const now = 'now';
49
+
50
+	/**
51
+	 * The following properties hold the default formats for date and time.
52
+	 * Defaults are set via the constructor and can be overridden on class instantiation.
53
+	 * However they can also be overridden later by the set_format() method
54
+	 * (and corresponding set_date_format, set_time_format methods);
55
+	 */
56
+	/**
57
+	 * @type string $_date_format
58
+	 */
59
+	protected $_date_format = '';
60
+
61
+	/**
62
+	 * @type string $_time_format
63
+	 */
64
+	protected $_time_format = '';
65
+
66
+	/**
67
+	 * @type string $_pretty_date_format
68
+	 */
69
+	protected $_pretty_date_format = '';
70
+
71
+	/**
72
+	 * @type string $_pretty_time_format
73
+	 */
74
+	protected $_pretty_time_format = '';
75
+
76
+	/**
77
+	 * @type DateTimeZone $_DateTimeZone
78
+	 */
79
+	protected $_DateTimeZone;
80
+
81
+	/**
82
+	 * @type DateTimeZone $_UTC_DateTimeZone
83
+	 */
84
+	protected $_UTC_DateTimeZone;
85
+
86
+	/**
87
+	 * @type DateTimeZone $_blog_DateTimeZone
88
+	 */
89
+	protected $_blog_DateTimeZone;
90
+
91
+
92
+	/**
93
+	 * This property holds how we want the output returned when getting a datetime string.  It is set for the
94
+	 * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
95
+	 * and time returned via getters.
96
+	 *
97
+	 * @var mixed (null|string)
98
+	 */
99
+	protected $_date_time_output;
100
+
101
+
102
+	/**
103
+	 * timezone string
104
+	 * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
105
+	 * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
106
+	 * coming out of the object to be in.  Default timezone is the current WP timezone option setting
107
+	 *
108
+	 * @var string
109
+	 */
110
+	protected $_timezone_string;
111
+
112
+
113
+	/**
114
+	 * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
115
+	 * offsets for comparison purposes).
116
+	 *
117
+	 * @var int
118
+	 */
119
+	protected $_blog_offset;
120
+
121
+
122
+
123
+	/**
124
+	 * @param string $table_column
125
+	 * @param string $nice_name
126
+	 * @param bool   $nullable
127
+	 * @param string $default_value
128
+	 * @param string $timezone_string
129
+	 * @param string $date_format
130
+	 * @param string $time_format
131
+	 * @param string $pretty_date_format
132
+	 * @param string $pretty_time_format
133
+	 * @throws EE_Error
134
+	 * @throws InvalidArgumentException
135
+	 */
136
+	public function __construct(
137
+		$table_column,
138
+		$nice_name,
139
+		$nullable,
140
+		$default_value,
141
+		$timezone_string = '',
142
+		$date_format = '',
143
+		$time_format = '',
144
+		$pretty_date_format = '',
145
+		$pretty_time_format = ''
146
+	) {
147
+
148
+		$this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
149
+		$this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
150
+		$this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
151
+		$this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
152
+
153
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
154
+		$this->set_timezone($timezone_string);
155
+		$this->setSchemaFormat('date-time');
156
+	}
157
+
158
+
159
+	/**
160
+	 * @return DateTimeZone
161
+	 * @throws \EE_Error
162
+	 */
163
+	public function get_UTC_DateTimeZone()
164
+	{
165
+		return $this->_UTC_DateTimeZone instanceof DateTimeZone
166
+			? $this->_UTC_DateTimeZone
167
+			: $this->_create_timezone_object_from_timezone_string('UTC');
168
+	}
169
+
170
+
171
+	/**
172
+	 * @return DateTimeZone
173
+	 * @throws \EE_Error
174
+	 */
175
+	public function get_blog_DateTimeZone()
176
+	{
177
+		return $this->_blog_DateTimeZone instanceof DateTimeZone
178
+			? $this->_blog_DateTimeZone
179
+			: $this->_create_timezone_object_from_timezone_string('');
180
+	}
181
+
182
+
183
+	/**
184
+	 * this prepares any incoming date data and make sure its converted to a utc unix timestamp
185
+	 *
186
+	 * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
187
+	 *                                                              timestamp
188
+	 * @return DateTime
189
+	 */
190
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
191
+	{
192
+		return $this->_get_date_object($value_inputted_for_field_on_model_object);
193
+	}
194
+
195
+
196
+	/**
197
+	 * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
198
+	 * getters need to know whether we're just returning the date or the time or both.  By default we return both.
199
+	 *
200
+	 * @param bool $pretty If we're returning the pretty formats or standard format string.
201
+	 * @return string    The final assembled format string.
202
+	 */
203
+	protected function _get_date_time_output($pretty = false)
204
+	{
205
+
206
+		switch ($this->_date_time_output) {
207
+			case 'time' :
208
+				return $pretty ? $this->_pretty_time_format : $this->_time_format;
209
+				break;
210
+
211
+			case 'date' :
212
+				return $pretty ? $this->_pretty_date_format : $this->_date_format;
213
+				break;
214
+
215
+			default :
216
+				return $pretty
217
+					? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
218
+					: $this->_date_format . ' ' . $this->_time_format;
219
+		}
220
+	}
221
+
222
+
223
+	/**
224
+	 * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
225
+	 * returned (using the format properties)
226
+	 *
227
+	 * @param string $what acceptable values are 'time' or 'date'.
228
+	 *                     Any other value will be set but will always result
229
+	 *                     in both 'date' and 'time' being returned.
230
+	 * @return void
231
+	 */
232
+	public function set_date_time_output($what = null)
233
+	{
234
+		$this->_date_time_output = $what;
235
+	}
236
+
237
+
238
+	/**
239
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
240
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
241
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
242
+	 * We also set some other properties in this method.
243
+	 *
244
+	 * @param string $timezone_string A valid timezone string as described by @link
245
+	 *                                http://www.php.net/manual/en/timezones.php
246
+	 * @return void
247
+	 * @throws InvalidArgumentException
248
+	 * @throws InvalidDataTypeException
249
+	 * @throws InvalidInterfaceException
250
+	 */
251
+	public function set_timezone($timezone_string)
252
+	{
253
+		if (empty($timezone_string) && $this->_timezone_string !== null) {
254
+			// leave the timezone AS-IS if we already have one and
255
+			// the function arg didn't provide one
256
+			return;
257
+		}
258
+		$timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
259
+		$this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
260
+		$this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
261
+	}
262
+
263
+
264
+	/**
265
+	 * _create_timezone_object_from_timezone_name
266
+	 *
267
+	 * @access protected
268
+	 * @param string $timezone_string
269
+	 * @return \DateTimeZone
270
+	 * @throws InvalidArgumentException
271
+	 * @throws InvalidDataTypeException
272
+	 * @throws InvalidInterfaceException
273
+	 */
274
+	protected function _create_timezone_object_from_timezone_string($timezone_string = '')
275
+	{
276
+		return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
277
+	}
278
+
279
+
280
+	/**
281
+	 * This just returns whatever is set for the current timezone.
282
+	 *
283
+	 * @access public
284
+	 * @return string timezone string
285
+	 */
286
+	public function get_timezone()
287
+	{
288
+		return $this->_timezone_string;
289
+	}
290
+
291
+
292
+	/**
293
+	 * set the $_date_format property
294
+	 *
295
+	 * @access public
296
+	 * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
297
+	 * @param bool   $pretty Whether to set pretty format or not.
298
+	 * @return void
299
+	 */
300
+	public function set_date_format($format, $pretty = false)
301
+	{
302
+		if ($pretty) {
303
+			$this->_pretty_date_format = $format;
304
+		} else {
305
+			$this->_date_format = $format;
306
+		}
307
+	}
308
+
309
+
310
+	/**
311
+	 * return the $_date_format property value.
312
+	 *
313
+	 * @param bool $pretty Whether to get pretty format or not.
314
+	 * @return string
315
+	 */
316
+	public function get_date_format($pretty = false)
317
+	{
318
+		return $pretty ? $this->_pretty_date_format : $this->_date_format;
319
+	}
320
+
321
+
322
+	/**
323
+	 * set the $_time_format property
324
+	 *
325
+	 * @access public
326
+	 * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
327
+	 * @param bool   $pretty Whether to set pretty format or not.
328
+	 * @return void
329
+	 */
330
+	public function set_time_format($format, $pretty = false)
331
+	{
332
+		if ($pretty) {
333
+			$this->_pretty_time_format = $format;
334
+		} else {
335
+			$this->_time_format = $format;
336
+		}
337
+	}
338
+
339
+
340
+	/**
341
+	 * return the $_time_format property value.
342
+	 *
343
+	 * @param bool $pretty Whether to get pretty format or not.
344
+	 * @return string
345
+	 */
346
+	public function get_time_format($pretty = false)
347
+	{
348
+		return $pretty ? $this->_pretty_time_format : $this->_time_format;
349
+	}
350
+
351
+
352
+	/**
353
+	 * set the $_pretty_date_format property
354
+	 *
355
+	 * @access public
356
+	 * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
357
+	 * @return void
358
+	 */
359
+	public function set_pretty_date_format($format)
360
+	{
361
+		$this->_pretty_date_format = $format;
362
+	}
363
+
364
+
365
+	/**
366
+	 * set the $_pretty_time_format property
367
+	 *
368
+	 * @access public
369
+	 * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
370
+	 * @return void
371
+	 */
372
+	public function set_pretty_time_format($format)
373
+	{
374
+		$this->_pretty_time_format = $format;
375
+	}
376
+
377
+
378
+	/**
379
+	 * Only sets the time portion of the datetime.
380
+	 *
381
+	 * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
382
+	 * @param DateTime        $current            current DateTime object for the datetime field
383
+	 * @return DateTime
384
+	 */
385
+	public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
386
+	{
387
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
388
+		// Otherwise parse the string.
389
+		if ($time_to_set_string instanceof DateTime) {
390
+			$parsed = array(
391
+				'hour'   => $time_to_set_string->format('H'),
392
+				'minute' => $time_to_set_string->format('i'),
393
+				'second' => $time_to_set_string->format('s'),
394
+			);
395
+		} else {
396
+			//parse incoming string
397
+			$parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
398
+		}
399
+
400
+		//make sure $current is in the correct timezone.
401
+		$current->setTimezone($this->_DateTimeZone);
402
+
403
+		return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
404
+	}
405
+
406
+
407
+	/**
408
+	 * Only sets the date portion of the datetime.
409
+	 *
410
+	 * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
411
+	 * @param DateTime        $current            current DateTime object for the datetime field
412
+	 * @return DateTime
413
+	 */
414
+	public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
415
+	{
416
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
417
+		// Otherwise parse the string.
418
+		if ($date_to_set_string instanceof DateTime) {
419
+			$parsed = array(
420
+				'year'  => $date_to_set_string->format('Y'),
421
+				'month' => $date_to_set_string->format('m'),
422
+				'day'   => $date_to_set_string->format('d'),
423
+			);
424
+		} else {
425
+			//parse incoming string
426
+			$parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
427
+		}
428
+
429
+		//make sure $current is in the correct timezone
430
+		$current->setTimezone($this->_DateTimeZone);
431
+
432
+		return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
433
+	}
434
+
435
+
436
+	/**
437
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
438
+	 * datetime gets to this stage it should ALREADY be in UTC time
439
+	 *
440
+	 * @param  DateTime $DateTime
441
+	 * @return string formatted date time for given timezone
442
+	 * @throws \EE_Error
443
+	 */
444
+	public function prepare_for_get($DateTime)
445
+	{
446
+		return $this->_prepare_for_display($DateTime);
447
+	}
448
+
449
+
450
+	/**
451
+	 * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
452
+	 * from the set wp timezone.  If so, then it returns the datetime string formatted via
453
+	 * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
454
+	 * abbreviation to the date_string.
455
+	 *
456
+	 * @param mixed $DateTime
457
+	 * @param null  $schema
458
+	 * @return string
459
+	 * @throws \EE_Error
460
+	 */
461
+	public function prepare_for_pretty_echoing($DateTime, $schema = null)
462
+	{
463
+		return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
464
+	}
465
+
466
+
467
+	/**
468
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
469
+	 * timezone).
470
+	 *
471
+	 * @param DateTime    $DateTime
472
+	 * @param bool|string $schema
473
+	 * @return string
474
+	 * @throws \EE_Error
475
+	 */
476
+	protected function _prepare_for_display($DateTime, $schema = false)
477
+	{
478
+		if (! $DateTime instanceof DateTime) {
479
+			if ($this->_nullable) {
480
+				return '';
481
+			} else {
482
+				if (WP_DEBUG) {
483
+					throw new EE_Error(
484
+						sprintf(
485
+							__(
486
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
487
+								'event_espresso'
488
+							),
489
+							$this->_nicename
490
+						)
491
+					);
492
+				} else {
493
+					$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
494
+					EE_Error::add_error(
495
+						sprintf(
496
+							__(
497
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
498
+								'event_espresso'
499
+							),
500
+							$this->_nicename
501
+						)
502
+					);
503
+				}
504
+			}
505
+		}
506
+		$format_string = $this->_get_date_time_output($schema);
507
+		//make sure datetime_value is in the correct timezone (in case that's been updated).
508
+		$DateTime->setTimezone($this->_DateTimeZone);
509
+		if ($schema) {
510
+			if ($this->_display_timezone()) {
511
+				//must be explicit because schema could equal true.
512
+				if ($schema === 'no_html') {
513
+					$timezone_string = ' (' . $DateTime->format('T') . ')';
514
+				} else {
515
+					$timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
516
+				}
517
+			} else {
518
+				$timezone_string = '';
519
+			}
520
+
521
+			return $DateTime->format($format_string) . $timezone_string;
522
+		} else {
523
+			return $DateTime->format($format_string);
524
+		}
525
+	}
526
+
527
+
528
+	/**
529
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
530
+	 * timezone).
531
+	 *
532
+	 * @param  mixed $datetime_value u
533
+	 * @return string mysql timestamp in UTC
534
+	 * @throws \EE_Error
535
+	 */
536
+	public function prepare_for_use_in_db($datetime_value)
537
+	{
538
+		//we allow an empty value or DateTime object, but nothing else.
539
+		if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
540
+			throw new EE_Error(
541
+				sprintf(
542
+					__(
543
+						'The incoming value being prepared for setting in the database must either be empty or a php 
544 544
             		    DateTime object, instead of: %1$s %2$s',
545
-                        'event_espresso'
546
-	                ),
547
-                    '<br />',
548
-                    print_r($datetime_value, true)
549
-                )
550
-            );
551
-        }
552
-
553
-        if ($datetime_value instanceof DateTime) {
554
-            if ( ! $datetime_value instanceof DbSafeDateTime) {
555
-                $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
556
-            }
557
-
558
-            return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
559
-                EE_Datetime_Field::mysql_timestamp_format
560
-            );
561
-        }
562
-
563
-        // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
564
-        return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
565
-    }
566
-
567
-
568
-    /**
569
-     * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
570
-     * allowed)
571
-     *
572
-     * @param string $datetime_string mysql timestamp in UTC
573
-     * @return  mixed null | DateTime
574
-     * @throws \EE_Error
575
-     */
576
-    public function prepare_for_set_from_db($datetime_string)
577
-    {
578
-        //if $datetime_value is empty, and ! $this->_nullable, just use time()
579
-        if (empty($datetime_string) && $this->_nullable) {
580
-            return null;
581
-        }
582
-        // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
583
-        if (empty($datetime_string)) {
584
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
585
-        } else {
586
-            $DateTime = DateTime::createFromFormat(
587
-                EE_Datetime_Field::mysql_timestamp_format,
588
-                $datetime_string,
589
-                $this->get_UTC_DateTimeZone()
590
-            );
591
-            if ($DateTime instanceof \DateTime) {
592
-                $DateTime = new DbSafeDateTime(
593
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
594
-                    $this->get_UTC_DateTimeZone()
595
-                );
596
-            }
597
-        }
598
-
599
-        if (! $DateTime instanceof DbSafeDateTime) {
600
-            // if still no datetime object, then let's just use now
601
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
602
-        }
603
-        // THEN apply the field's set DateTimeZone
604
-        $DateTime->setTimezone($this->_DateTimeZone);
605
-        //apparently in PHP5.6 this is needed to ensure the correct timestamp is internal on this object.  This fixes
606
-        //failing tests against PHP5.6 for the `Read_Test::test_handle_request_get_one__event` test.
607
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/11233
608
-        $DateTime->getTimestamp();
609
-        return $DateTime;
610
-    }
611
-
612
-
613
-    /**
614
-     * All this method does is determine if we're going to display the timezone string or not on any output.
615
-     * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
616
-     * If so, then true.
617
-     *
618
-     * @return bool true for yes false for no
619
-     * @throws \EE_Error
620
-     */
621
-    protected function _display_timezone()
622
-    {
623
-
624
-        // first let's do a comparison of timezone strings.
625
-        // If they match then we can get out without any further calculations
626
-        $blog_string = get_option('timezone_string');
627
-        if ($blog_string === $this->_timezone_string) {
628
-            return false;
629
-        }
630
-        // now we need to calc the offset for the timezone string so we can compare with the blog offset.
631
-        $this_offset = $this->get_timezone_offset($this->_DateTimeZone);
632
-        $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
633
-        // now compare
634
-        return $blog_offset !== $this_offset;
635
-    }
636
-
637
-
638
-    /**
639
-     * This method returns a php DateTime object for setting on the EE_Base_Class model.
640
-     * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
641
-     * with.
642
-     *
643
-     * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
644
-     *                                                    in the format that is set on the date_field (or DateTime
645
-     *                                                    object)!
646
-     * @return DateTime
647
-     */
648
-    protected function _get_date_object($date_string)
649
-    {
650
-        //first if this is an empty date_string and nullable is allowed, just return null.
651
-        if ($this->_nullable && empty($date_string)) {
652
-            return null;
653
-        }
654
-
655
-        // if incoming date
656
-        if ($date_string instanceof DateTime) {
657
-            $date_string->setTimezone($this->_DateTimeZone);
658
-
659
-            return $date_string;
660
-        }
661
-        // if empty date_string and made it here.
662
-        // Return a datetime object for now in the given timezone.
663
-        if (empty($date_string)) {
664
-            return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
665
-        }
666
-        // if $date_string is matches something that looks like a Unix timestamp let's just use it.
667
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
668
-            try {
669
-                // This is operating under the assumption that the incoming Unix timestamp
670
-                // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
671
-                $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
672
-                $DateTime->setTimestamp($date_string);
673
-
674
-                return $DateTime;
675
-            } catch (Exception $e) {
676
-                // should be rare, but if things got fooled then let's just continue
677
-            }
678
-        }
679
-        //not a unix timestamp.  So we will use the set format on this object and set timezone to
680
-        //create the DateTime object.
681
-        $format = $this->_date_format . ' ' . $this->_time_format;
682
-        try {
683
-            $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
684
-            if ($DateTime instanceof DateTime) {
685
-                $DateTime = new DbSafeDateTime(
686
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
687
-                    $this->_DateTimeZone
688
-                );
689
-            }
690
-            if (! $DateTime instanceof DbSafeDateTime) {
691
-                throw new EE_Error(
692
-                    sprintf(
693
-                        __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
694
-                        $date_string,
695
-                        $format
696
-                    )
697
-                );
698
-            }
699
-        } catch (Exception $e) {
700
-            // if we made it here then likely then something went really wrong.
701
-            // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
702
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
703
-        }
704
-
705
-        return $DateTime;
706
-    }
707
-
708
-
709
-
710
-    /**
711
-     * get_timezone_transitions
712
-     *
713
-     * @param \DateTimeZone $DateTimeZone
714
-     * @param int           $time
715
-     * @param bool          $first_only
716
-     * @return mixed
717
-     */
718
-    public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
719
-    {
720
-        return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only);
721
-    }
722
-
723
-
724
-
725
-    /**
726
-     * get_timezone_offset
727
-     *
728
-     * @param \DateTimeZone $DateTimeZone
729
-     * @param int           $time
730
-     * @return mixed
731
-     * @throws \DomainException
732
-     */
733
-    public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
734
-    {
735
-        return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time);
736
-    }
737
-
738
-
739
-    /**
740
-     * This will take an incoming timezone string and return the abbreviation for that timezone
741
-     *
742
-     * @param  string $timezone_string
743
-     * @return string           abbreviation
744
-     * @throws \EE_Error
745
-     */
746
-    public function get_timezone_abbrev($timezone_string)
747
-    {
748
-        $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
749
-        $dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
750
-
751
-        return $dateTime->format('T');
752
-    }
753
-
754
-    /**
755
-     * Overrides the parent to allow for having a dynamic "now" value
756
-     *
757
-     * @return mixed
758
-     */
759
-    public function get_default_value()
760
-    {
761
-        if ($this->_default_value === EE_Datetime_Field::now) {
762
-            return time();
763
-        } else {
764
-            return parent::get_default_value();
765
-        }
766
-    }
767
-
768
-
769
-    public function getSchemaDescription()
770
-    {
771
-        return sprintf(
772
-            esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
773
-            $this->get_nicename()
774
-        );
775
-    }
545
+						'event_espresso'
546
+					),
547
+					'<br />',
548
+					print_r($datetime_value, true)
549
+				)
550
+			);
551
+		}
552
+
553
+		if ($datetime_value instanceof DateTime) {
554
+			if ( ! $datetime_value instanceof DbSafeDateTime) {
555
+				$datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
556
+			}
557
+
558
+			return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
559
+				EE_Datetime_Field::mysql_timestamp_format
560
+			);
561
+		}
562
+
563
+		// if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
564
+		return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
565
+	}
566
+
567
+
568
+	/**
569
+	 * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
570
+	 * allowed)
571
+	 *
572
+	 * @param string $datetime_string mysql timestamp in UTC
573
+	 * @return  mixed null | DateTime
574
+	 * @throws \EE_Error
575
+	 */
576
+	public function prepare_for_set_from_db($datetime_string)
577
+	{
578
+		//if $datetime_value is empty, and ! $this->_nullable, just use time()
579
+		if (empty($datetime_string) && $this->_nullable) {
580
+			return null;
581
+		}
582
+		// datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
583
+		if (empty($datetime_string)) {
584
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
585
+		} else {
586
+			$DateTime = DateTime::createFromFormat(
587
+				EE_Datetime_Field::mysql_timestamp_format,
588
+				$datetime_string,
589
+				$this->get_UTC_DateTimeZone()
590
+			);
591
+			if ($DateTime instanceof \DateTime) {
592
+				$DateTime = new DbSafeDateTime(
593
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
594
+					$this->get_UTC_DateTimeZone()
595
+				);
596
+			}
597
+		}
598
+
599
+		if (! $DateTime instanceof DbSafeDateTime) {
600
+			// if still no datetime object, then let's just use now
601
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
602
+		}
603
+		// THEN apply the field's set DateTimeZone
604
+		$DateTime->setTimezone($this->_DateTimeZone);
605
+		//apparently in PHP5.6 this is needed to ensure the correct timestamp is internal on this object.  This fixes
606
+		//failing tests against PHP5.6 for the `Read_Test::test_handle_request_get_one__event` test.
607
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/11233
608
+		$DateTime->getTimestamp();
609
+		return $DateTime;
610
+	}
611
+
612
+
613
+	/**
614
+	 * All this method does is determine if we're going to display the timezone string or not on any output.
615
+	 * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
616
+	 * If so, then true.
617
+	 *
618
+	 * @return bool true for yes false for no
619
+	 * @throws \EE_Error
620
+	 */
621
+	protected function _display_timezone()
622
+	{
623
+
624
+		// first let's do a comparison of timezone strings.
625
+		// If they match then we can get out without any further calculations
626
+		$blog_string = get_option('timezone_string');
627
+		if ($blog_string === $this->_timezone_string) {
628
+			return false;
629
+		}
630
+		// now we need to calc the offset for the timezone string so we can compare with the blog offset.
631
+		$this_offset = $this->get_timezone_offset($this->_DateTimeZone);
632
+		$blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
633
+		// now compare
634
+		return $blog_offset !== $this_offset;
635
+	}
636
+
637
+
638
+	/**
639
+	 * This method returns a php DateTime object for setting on the EE_Base_Class model.
640
+	 * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
641
+	 * with.
642
+	 *
643
+	 * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
644
+	 *                                                    in the format that is set on the date_field (or DateTime
645
+	 *                                                    object)!
646
+	 * @return DateTime
647
+	 */
648
+	protected function _get_date_object($date_string)
649
+	{
650
+		//first if this is an empty date_string and nullable is allowed, just return null.
651
+		if ($this->_nullable && empty($date_string)) {
652
+			return null;
653
+		}
654
+
655
+		// if incoming date
656
+		if ($date_string instanceof DateTime) {
657
+			$date_string->setTimezone($this->_DateTimeZone);
658
+
659
+			return $date_string;
660
+		}
661
+		// if empty date_string and made it here.
662
+		// Return a datetime object for now in the given timezone.
663
+		if (empty($date_string)) {
664
+			return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
665
+		}
666
+		// if $date_string is matches something that looks like a Unix timestamp let's just use it.
667
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
668
+			try {
669
+				// This is operating under the assumption that the incoming Unix timestamp
670
+				// is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
671
+				$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
672
+				$DateTime->setTimestamp($date_string);
673
+
674
+				return $DateTime;
675
+			} catch (Exception $e) {
676
+				// should be rare, but if things got fooled then let's just continue
677
+			}
678
+		}
679
+		//not a unix timestamp.  So we will use the set format on this object and set timezone to
680
+		//create the DateTime object.
681
+		$format = $this->_date_format . ' ' . $this->_time_format;
682
+		try {
683
+			$DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
684
+			if ($DateTime instanceof DateTime) {
685
+				$DateTime = new DbSafeDateTime(
686
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
687
+					$this->_DateTimeZone
688
+				);
689
+			}
690
+			if (! $DateTime instanceof DbSafeDateTime) {
691
+				throw new EE_Error(
692
+					sprintf(
693
+						__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
694
+						$date_string,
695
+						$format
696
+					)
697
+				);
698
+			}
699
+		} catch (Exception $e) {
700
+			// if we made it here then likely then something went really wrong.
701
+			// Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
702
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
703
+		}
704
+
705
+		return $DateTime;
706
+	}
707
+
708
+
709
+
710
+	/**
711
+	 * get_timezone_transitions
712
+	 *
713
+	 * @param \DateTimeZone $DateTimeZone
714
+	 * @param int           $time
715
+	 * @param bool          $first_only
716
+	 * @return mixed
717
+	 */
718
+	public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
719
+	{
720
+		return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only);
721
+	}
722
+
723
+
724
+
725
+	/**
726
+	 * get_timezone_offset
727
+	 *
728
+	 * @param \DateTimeZone $DateTimeZone
729
+	 * @param int           $time
730
+	 * @return mixed
731
+	 * @throws \DomainException
732
+	 */
733
+	public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
734
+	{
735
+		return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time);
736
+	}
737
+
738
+
739
+	/**
740
+	 * This will take an incoming timezone string and return the abbreviation for that timezone
741
+	 *
742
+	 * @param  string $timezone_string
743
+	 * @return string           abbreviation
744
+	 * @throws \EE_Error
745
+	 */
746
+	public function get_timezone_abbrev($timezone_string)
747
+	{
748
+		$timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
749
+		$dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
750
+
751
+		return $dateTime->format('T');
752
+	}
753
+
754
+	/**
755
+	 * Overrides the parent to allow for having a dynamic "now" value
756
+	 *
757
+	 * @return mixed
758
+	 */
759
+	public function get_default_value()
760
+	{
761
+		if ($this->_default_value === EE_Datetime_Field::now) {
762
+			return time();
763
+		} else {
764
+			return parent::get_default_value();
765
+		}
766
+	}
767
+
768
+
769
+	public function getSchemaDescription()
770
+	{
771
+		return sprintf(
772
+			esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
773
+			$this->get_nicename()
774
+		);
775
+	}
776 776
 }
Please login to merge, or discard this patch.
core/services/helpers/datetime/HelperInterface.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -16,94 +16,94 @@
 block discarded – undo
16 16
 interface HelperInterface
17 17
 {
18 18
 
19
-    /**
20
-     * Ensures that a valid timezone string is returned.
21
-     *
22
-     * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
23
-     *                                 settings (or derive from set UTC offset).
24
-     * @return string
25
-     */
26
-    public function getValidTimezoneString($timezone_string = '');
27
-
28
-
29
-    /**
30
-     * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
31
-     *
32
-     * @param string $timezone_string
33
-     * @param bool   $throw_error
34
-     * @return bool
35
-     */
36
-    public function validateTimezone($timezone_string, $throw_error = true);
37
-
38
-
39
-    /**
40
-     * Returns a timezone string for the provided gmt_offset.
41
-     * @param float|string $gmt_offset
42
-     * @return string
43
-     */
44
-    public function getTimezoneStringFromGmtOffset($gmt_offset = '');
45
-
46
-
47
-    /**
48
-     * Gets the site's GMT offset based on either the timezone string
49
-     * (in which case the gmt offset will vary depending on the location's
50
-     * observance of daylight savings time) or the gmt_offset wp option
51
-     *
52
-     * @return int  seconds offset
53
-     */
54
-    public function getSiteTimezoneGmtOffset();
55
-
56
-
57
-    /**
58
-     * Get timezone transitions
59
-     * @param DateTimeZone $date_time_zone
60
-     * @param int|null     $time
61
-     * @param bool         $first_only
62
-     * @return array
63
-     */
64
-    public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true);
65
-
66
-
67
-    /**
68
-     * Get Timezone offset for given timezone object
69
-     * @param DateTimeZone $date_time_zone
70
-     * @param null|int         $time
71
-     * @return int
72
-     */
73
-    public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null);
74
-
75
-
76
-    /**
77
-     * Provide a timezone select input
78
-     * @param string $timezone_string
79
-     * @return string
80
-     */
81
-    public function timezoneSelectInput($timezone_string = '');
82
-
83
-
84
-    /**
85
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
86
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
87
-     * the site is used.
88
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
89
-     * computed timestamp (i.e. date_i18n() )
90
-     *
91
-     * @param int    $unix_timestamp    if 0, then time() will be used.
92
-     * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
93
-     *                                site will be used.
94
-     * @return int      unix_timestamp value with the offset applied for the given timezone.
95
-     */
96
-    public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '');
97
-
98
-
99
-    /**
100
-     * Depending on PHP version,
101
-     * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
102
-     * To get around that, for these fringe timezones we bump them to a known valid offset.
103
-     * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
104
-     *
105
-     * @param int $gmt_offset
106
-     * @return int
107
-     */
108
-    public function adjustInvalidGmtOffsets($gmt_offset);
19
+	/**
20
+	 * Ensures that a valid timezone string is returned.
21
+	 *
22
+	 * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
23
+	 *                                 settings (or derive from set UTC offset).
24
+	 * @return string
25
+	 */
26
+	public function getValidTimezoneString($timezone_string = '');
27
+
28
+
29
+	/**
30
+	 * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
31
+	 *
32
+	 * @param string $timezone_string
33
+	 * @param bool   $throw_error
34
+	 * @return bool
35
+	 */
36
+	public function validateTimezone($timezone_string, $throw_error = true);
37
+
38
+
39
+	/**
40
+	 * Returns a timezone string for the provided gmt_offset.
41
+	 * @param float|string $gmt_offset
42
+	 * @return string
43
+	 */
44
+	public function getTimezoneStringFromGmtOffset($gmt_offset = '');
45
+
46
+
47
+	/**
48
+	 * Gets the site's GMT offset based on either the timezone string
49
+	 * (in which case the gmt offset will vary depending on the location's
50
+	 * observance of daylight savings time) or the gmt_offset wp option
51
+	 *
52
+	 * @return int  seconds offset
53
+	 */
54
+	public function getSiteTimezoneGmtOffset();
55
+
56
+
57
+	/**
58
+	 * Get timezone transitions
59
+	 * @param DateTimeZone $date_time_zone
60
+	 * @param int|null     $time
61
+	 * @param bool         $first_only
62
+	 * @return array
63
+	 */
64
+	public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true);
65
+
66
+
67
+	/**
68
+	 * Get Timezone offset for given timezone object
69
+	 * @param DateTimeZone $date_time_zone
70
+	 * @param null|int         $time
71
+	 * @return int
72
+	 */
73
+	public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null);
74
+
75
+
76
+	/**
77
+	 * Provide a timezone select input
78
+	 * @param string $timezone_string
79
+	 * @return string
80
+	 */
81
+	public function timezoneSelectInput($timezone_string = '');
82
+
83
+
84
+	/**
85
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
86
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
87
+	 * the site is used.
88
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
89
+	 * computed timestamp (i.e. date_i18n() )
90
+	 *
91
+	 * @param int    $unix_timestamp    if 0, then time() will be used.
92
+	 * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
93
+	 *                                site will be used.
94
+	 * @return int      unix_timestamp value with the offset applied for the given timezone.
95
+	 */
96
+	public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '');
97
+
98
+
99
+	/**
100
+	 * Depending on PHP version,
101
+	 * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
102
+	 * To get around that, for these fringe timezones we bump them to a known valid offset.
103
+	 * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
104
+	 *
105
+	 * @param int $gmt_offset
106
+	 * @return int
107
+	 */
108
+	public function adjustInvalidGmtOffsets($gmt_offset);
109 109
 }
Please login to merge, or discard this patch.
core/services/helpers/datetime/AbstractHelper.php 2 patches
Indentation   +242 added lines, -242 removed lines patch added patch discarded remove patch
@@ -12,136 +12,136 @@  discard block
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * Ensures that a valid timezone string is returned.
17
-     *
18
-     * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
19
-     *                                 settings (or derive from set UTC offset).
20
-     * @return string
21
-     * @throws EE_Error
22
-     */
23
-    public function getValidTimezoneString($timezone_string = '')
24
-    {
25
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
26
-        $timezone_string = ! empty($timezone_string)
27
-            ? $timezone_string
28
-            : $this->getTimezoneStringFromGmtOffset();
29
-        $this->validateTimezone($timezone_string);
30
-        return $timezone_string;
31
-    }
15
+	/**
16
+	 * Ensures that a valid timezone string is returned.
17
+	 *
18
+	 * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
19
+	 *                                 settings (or derive from set UTC offset).
20
+	 * @return string
21
+	 * @throws EE_Error
22
+	 */
23
+	public function getValidTimezoneString($timezone_string = '')
24
+	{
25
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
26
+		$timezone_string = ! empty($timezone_string)
27
+			? $timezone_string
28
+			: $this->getTimezoneStringFromGmtOffset();
29
+		$this->validateTimezone($timezone_string);
30
+		return $timezone_string;
31
+	}
32 32
 
33 33
 
34 34
 
35
-    /**
36
-     * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
37
-     *
38
-     * @param string $timezone_string
39
-     * @param bool   $throw_error
40
-     * @return bool
41
-     * @throws EE_Error
42
-     */
43
-    public function validateTimezone($timezone_string, $throw_error = true)
44
-    {
45
-        // easiest way to test a timezone string is just see if it throws an error when you try to create a
46
-        // DateTimeZone object with it
47
-        try {
48
-            new DateTimeZone($timezone_string);
49
-        } catch (Exception $e) {
50
-            // sometimes we take exception to exceptions
51
-            if (! $throw_error) {
52
-                return false;
53
-            }
54
-            throw new EE_Error(
55
-                sprintf(
56
-                    esc_html__(
57
-                        'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
58
-                        'event_espresso'
59
-                    ),
60
-                    $timezone_string,
61
-                    '<a href="http://www.php.net/manual/en/timezones.php">',
62
-                    '</a>'
63
-                )
64
-            );
65
-        }
66
-        return true;
67
-    }
35
+	/**
36
+	 * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
37
+	 *
38
+	 * @param string $timezone_string
39
+	 * @param bool   $throw_error
40
+	 * @return bool
41
+	 * @throws EE_Error
42
+	 */
43
+	public function validateTimezone($timezone_string, $throw_error = true)
44
+	{
45
+		// easiest way to test a timezone string is just see if it throws an error when you try to create a
46
+		// DateTimeZone object with it
47
+		try {
48
+			new DateTimeZone($timezone_string);
49
+		} catch (Exception $e) {
50
+			// sometimes we take exception to exceptions
51
+			if (! $throw_error) {
52
+				return false;
53
+			}
54
+			throw new EE_Error(
55
+				sprintf(
56
+					esc_html__(
57
+						'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
58
+						'event_espresso'
59
+					),
60
+					$timezone_string,
61
+					'<a href="http://www.php.net/manual/en/timezones.php">',
62
+					'</a>'
63
+				)
64
+			);
65
+		}
66
+		return true;
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * Gets the site's GMT offset based on either the timezone string
72
-     * (in which case the gmt offset will vary depending on the location's
73
-     * observance of daylight savings time) or the gmt_offset wp option
74
-     *
75
-     * @return int  seconds offset
76
-     */
77
-    public function getSiteTimezoneGmtOffset()
78
-    {
79
-        $timezone_string = (string)get_option('timezone_string');
80
-        if ($timezone_string) {
81
-            try {
82
-                $timezone = new DateTimeZone($timezone_string);
83
-                return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC
84
-            } catch (Exception $e) {
85
-            }
86
-        }
87
-        $offset = get_option('gmt_offset');
88
-        return (int) ($offset * HOUR_IN_SECONDS);
89
-    }
70
+	/**
71
+	 * Gets the site's GMT offset based on either the timezone string
72
+	 * (in which case the gmt offset will vary depending on the location's
73
+	 * observance of daylight savings time) or the gmt_offset wp option
74
+	 *
75
+	 * @return int  seconds offset
76
+	 */
77
+	public function getSiteTimezoneGmtOffset()
78
+	{
79
+		$timezone_string = (string)get_option('timezone_string');
80
+		if ($timezone_string) {
81
+			try {
82
+				$timezone = new DateTimeZone($timezone_string);
83
+				return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC
84
+			} catch (Exception $e) {
85
+			}
86
+		}
87
+		$offset = get_option('gmt_offset');
88
+		return (int) ($offset * HOUR_IN_SECONDS);
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * Get Timezone offset for given timezone object
94
-     *
95
-     * @param DateTimeZone $date_time_zone
96
-     * @param null|int     $time
97
-     * @return int
98
-     * @throws DomainException
99
-     */
100
-    public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
101
-    {
102
-        $transition = $this->getTimezoneTransitions($date_time_zone, $time);
103
-        if (! isset($transition['offset'])) {
104
-            throw new DomainException(
105
-                sprintf(
106
-                    esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
107
-                    print_r($transition, true)
108
-                )
109
-            );
110
-        }
111
-        return $transition['offset'];
112
-    }
92
+	/**
93
+	 * Get Timezone offset for given timezone object
94
+	 *
95
+	 * @param DateTimeZone $date_time_zone
96
+	 * @param null|int     $time
97
+	 * @return int
98
+	 * @throws DomainException
99
+	 */
100
+	public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
101
+	{
102
+		$transition = $this->getTimezoneTransitions($date_time_zone, $time);
103
+		if (! isset($transition['offset'])) {
104
+			throw new DomainException(
105
+				sprintf(
106
+					esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
107
+					print_r($transition, true)
108
+				)
109
+			);
110
+		}
111
+		return $transition['offset'];
112
+	}
113 113
 
114 114
 
115
-    /**
116
-     * Provide a timezone select input
117
-     *
118
-     * @param string $timezone_string
119
-     * @return string
120
-     * @throws EE_Error
121
-     */
122
-    public function timezoneSelectInput($timezone_string = '')
123
-    {
124
-        // get WP date time format
125
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
126
-        // if passed a value, then use that, else get WP option
127
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : (string)get_option('timezone_string');
128
-        // check if the timezone is valid but don't throw any errors if it isn't
129
-        $timezone_string = $this->validateTimezone($timezone_string, false)
130
-            ? $timezone_string
131
-            : '';
132
-        $gmt_offset      = get_option('gmt_offset');
133
-        $check_zone_info = true;
134
-        if (empty($timezone_string)) {
135
-            // Create a UTC+- zone if no timezone string exists
136
-            $timezone_string = 'UTC';
137
-            $check_zone_info = false;
138
-            if ($gmt_offset > 0) {
139
-                $timezone_string = 'UTC+' . $gmt_offset;
140
-            } elseif ($gmt_offset < 0) {
141
-                $timezone_string = 'UTC' . $gmt_offset;
142
-            }
143
-        }
144
-        ?>
115
+	/**
116
+	 * Provide a timezone select input
117
+	 *
118
+	 * @param string $timezone_string
119
+	 * @return string
120
+	 * @throws EE_Error
121
+	 */
122
+	public function timezoneSelectInput($timezone_string = '')
123
+	{
124
+		// get WP date time format
125
+		$datetime_format = get_option('date_format') . ' ' . get_option('time_format');
126
+		// if passed a value, then use that, else get WP option
127
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : (string)get_option('timezone_string');
128
+		// check if the timezone is valid but don't throw any errors if it isn't
129
+		$timezone_string = $this->validateTimezone($timezone_string, false)
130
+			? $timezone_string
131
+			: '';
132
+		$gmt_offset      = get_option('gmt_offset');
133
+		$check_zone_info = true;
134
+		if (empty($timezone_string)) {
135
+			// Create a UTC+- zone if no timezone string exists
136
+			$timezone_string = 'UTC';
137
+			$check_zone_info = false;
138
+			if ($gmt_offset > 0) {
139
+				$timezone_string = 'UTC+' . $gmt_offset;
140
+			} elseif ($gmt_offset < 0) {
141
+				$timezone_string = 'UTC' . $gmt_offset;
142
+			}
143
+		}
144
+		?>
145 145
         <p>
146 146
             <label for="timezone_string"><?php _e('timezone'); ?></label>
147 147
             <select id="timezone_string" name="timezone_string">
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
 
154 154
         <p>
155 155
         <span><?php
156
-            printf(
157
-                __('%1$sUTC%2$s time is %3$s'),
158
-                '<abbr title="Coordinated Universal Time">',
159
-                '</abbr>',
160
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
161
-            );
162
-            ?></span>
156
+			printf(
157
+				__('%1$sUTC%2$s time is %3$s'),
158
+				'<abbr title="Coordinated Universal Time">',
159
+				'</abbr>',
160
+				'<code>' . date_i18n($datetime_format, false, true) . '</code>'
161
+			);
162
+			?></span>
163 163
         <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
164 164
         <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
165 165
     <?php endif; ?>
@@ -168,132 +168,132 @@  discard block
 block discarded – undo
168 168
         <br/>
169 169
         <span>
170 170
                 <?php
171
-                // Set TZ so localtime works.
172
-                date_default_timezone_set($timezone_string);
173
-                $now = localtime(time(), true);
174
-                if ($now['tm_isdst']) {
175
-                    _e('This timezone is currently in daylight saving time.');
176
-                } else {
177
-                    _e('This timezone is currently in standard time.');
178
-                }
179
-                ?>
171
+				// Set TZ so localtime works.
172
+				date_default_timezone_set($timezone_string);
173
+				$now = localtime(time(), true);
174
+				if ($now['tm_isdst']) {
175
+					_e('This timezone is currently in daylight saving time.');
176
+				} else {
177
+					_e('This timezone is currently in standard time.');
178
+				}
179
+				?>
180 180
             <br/>
181 181
             <?php
182
-            if (function_exists('timezone_transitions_get')) {
183
-                $found                   = false;
184
-                $date_time_zone_selected = new DateTimeZone($timezone_string);
185
-                $tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
186
-                $right_now               = time();
187
-                $tr['isdst']             = false;
188
-                foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
189
-                    if ($tr['ts'] > $right_now) {
190
-                        $found = true;
191
-                        break;
192
-                    }
193
-                }
194
-                if ($found) {
195
-                    $message = $tr['isdst']
196
-                        ? __(' Daylight saving time begins on: %s.')
197
-                        : __(' Standard time begins  on: %s.');
198
-                    // Add the difference between the current offset and the new offset to ts to get the correct
199
-                    // transition time from date_i18n().
200
-                    printf(
201
-                        $message,
202
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
203
-                    );
204
-                } else {
205
-                    _e('This timezone does not observe daylight saving time.');
206
-                }
207
-            }
208
-            // Set back to UTC.
209
-            date_default_timezone_set('UTC');
210
-            ?>
182
+			if (function_exists('timezone_transitions_get')) {
183
+				$found                   = false;
184
+				$date_time_zone_selected = new DateTimeZone($timezone_string);
185
+				$tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
186
+				$right_now               = time();
187
+				$tr['isdst']             = false;
188
+				foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
189
+					if ($tr['ts'] > $right_now) {
190
+						$found = true;
191
+						break;
192
+					}
193
+				}
194
+				if ($found) {
195
+					$message = $tr['isdst']
196
+						? __(' Daylight saving time begins on: %s.')
197
+						: __(' Standard time begins  on: %s.');
198
+					// Add the difference between the current offset and the new offset to ts to get the correct
199
+					// transition time from date_i18n().
200
+					printf(
201
+						$message,
202
+						'<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
203
+					);
204
+				} else {
205
+					_e('This timezone does not observe daylight saving time.');
206
+				}
207
+			}
208
+			// Set back to UTC.
209
+			date_default_timezone_set('UTC');
210
+			?>
211 211
         </span></p>
212 212
     <?php
213
-    endif;
214
-    }
213
+	endif;
214
+	}
215 215
 
216 216
 
217
-    /**
218
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
219
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
220
-     * the site is used.
221
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
222
-     * computed timestamp (i.e. date_i18n() )
223
-     *
224
-     * @param int    $unix_timestamp  if 0, then time() will be used.
225
-     * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
226
-     *                                site will be used.
227
-     * @return int      unix_timestamp value with the offset applied for the given timezone.
228
-     * @throws EE_Error
229
-     */
230
-    public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '')
231
-    {
232
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
233
-        $timezone_string = $this->getValidTimezoneString($timezone_string);
234
-        $TimeZone        = new DateTimeZone($timezone_string);
235
-        $DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
236
-        $offset          = timezone_offset_get($TimeZone, $DateTime);
237
-        return (int) $DateTime->format('U') + (int) $offset;
238
-    }
217
+	/**
218
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
219
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
220
+	 * the site is used.
221
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
222
+	 * computed timestamp (i.e. date_i18n() )
223
+	 *
224
+	 * @param int    $unix_timestamp  if 0, then time() will be used.
225
+	 * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
226
+	 *                                site will be used.
227
+	 * @return int      unix_timestamp value with the offset applied for the given timezone.
228
+	 * @throws EE_Error
229
+	 */
230
+	public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '')
231
+	{
232
+		$unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
233
+		$timezone_string = $this->getValidTimezoneString($timezone_string);
234
+		$TimeZone        = new DateTimeZone($timezone_string);
235
+		$DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
236
+		$offset          = timezone_offset_get($TimeZone, $DateTime);
237
+		return (int) $DateTime->format('U') + (int) $offset;
238
+	}
239 239
 
240 240
 
241
-    /**
242
-     * Get Timezone Transitions
243
-     *
244
-     * @param DateTimeZone $date_time_zone
245
-     * @param int|null     $time
246
-     * @param bool         $first_only
247
-     * @return array|mixed
248
-     */
249
-    public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
250
-    {
251
-        $time        = is_int($time) || $time === null ? $time : (int) strtotime($time);
252
-        $time        = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
253
-        $transitions = $date_time_zone->getTransitions($time);
254
-        return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
255
-    }
241
+	/**
242
+	 * Get Timezone Transitions
243
+	 *
244
+	 * @param DateTimeZone $date_time_zone
245
+	 * @param int|null     $time
246
+	 * @param bool         $first_only
247
+	 * @return array|mixed
248
+	 */
249
+	public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
250
+	{
251
+		$time        = is_int($time) || $time === null ? $time : (int) strtotime($time);
252
+		$time        = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
253
+		$transitions = $date_time_zone->getTransitions($time);
254
+		return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
255
+	}
256 256
 
257 257
 
258 258
 
259
-    /**
260
-     * Default to just returning the provided $gmt_offset.  Children can override if adjustment needed.
261
-     *
262
-     * @param int $gmt_offset
263
-     * @return int
264
-     */
265
-    public function adjustInvalidGmtOffsets($gmt_offset = 0)
266
-    {
267
-        return $gmt_offset;
268
-    }
259
+	/**
260
+	 * Default to just returning the provided $gmt_offset.  Children can override if adjustment needed.
261
+	 *
262
+	 * @param int $gmt_offset
263
+	 * @return int
264
+	 */
265
+	public function adjustInvalidGmtOffsets($gmt_offset = 0)
266
+	{
267
+		return $gmt_offset;
268
+	}
269 269
 
270 270
 
271 271
 
272
-    /**
273
-     * This receives an incoming gmt_offset and santizes it.  If the provide value is an empty string, then this will
274
-     * attempt to get the offset from the timezone string.  If this returns a string, then a timezone string was
275
-     * successfully derived from existing timezone_string in the db.  If not, then a float is returned for the provided
276
-     * offset.
277
-     * @param  float|string $gmt_offset
278
-     * @return float|string
279
-     */
280
-    protected function sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset)
281
-    {
282
-        //if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is
283
-        //set because it will override `gmt_offset` via `pre_get_option` filter.  If that's set, then let's just use
284
-        //that!  Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic.
285
-        if ($gmt_offset === '') {
286
-            //autoloaded so no need to set to a variable.  There will not be multiple hits to the db.
287
-            if (get_option('timezone_string')) {
288
-                return (string) get_option('timezone_string');
289
-            }
290
-        }
291
-        $gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset');
292
-        $gmt_offset = (float) $gmt_offset;
293
-        //if $gmt_offset is 0 or is still an empty string, then just return UTC
294
-        if ($gmt_offset === (float) 0) {
295
-            return 'UTC';
296
-        }
297
-        return $gmt_offset;
298
-    }
272
+	/**
273
+	 * This receives an incoming gmt_offset and santizes it.  If the provide value is an empty string, then this will
274
+	 * attempt to get the offset from the timezone string.  If this returns a string, then a timezone string was
275
+	 * successfully derived from existing timezone_string in the db.  If not, then a float is returned for the provided
276
+	 * offset.
277
+	 * @param  float|string $gmt_offset
278
+	 * @return float|string
279
+	 */
280
+	protected function sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset)
281
+	{
282
+		//if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is
283
+		//set because it will override `gmt_offset` via `pre_get_option` filter.  If that's set, then let's just use
284
+		//that!  Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic.
285
+		if ($gmt_offset === '') {
286
+			//autoloaded so no need to set to a variable.  There will not be multiple hits to the db.
287
+			if (get_option('timezone_string')) {
288
+				return (string) get_option('timezone_string');
289
+			}
290
+		}
291
+		$gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset');
292
+		$gmt_offset = (float) $gmt_offset;
293
+		//if $gmt_offset is 0 or is still an empty string, then just return UTC
294
+		if ($gmt_offset === (float) 0) {
295
+			return 'UTC';
296
+		}
297
+		return $gmt_offset;
298
+	}
299 299
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
             new DateTimeZone($timezone_string);
28 28
         } catch (Exception $e) {
29 29
             // sometimes we take exception to exceptions
30
-            if (! $throw_error) {
30
+            if ( ! $throw_error) {
31 31
                 return false;
32 32
             }
33 33
             throw new EE_Error(
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public function getSiteTimezoneGmtOffset()
57 57
     {
58
-        $timezone_string = (string)get_option('timezone_string');
58
+        $timezone_string = (string) get_option('timezone_string');
59 59
         if ($timezone_string) {
60 60
             try {
61 61
                 $timezone = new DateTimeZone($timezone_string);
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
80 80
     {
81 81
         $transition = $this->getTimezoneTransitions($date_time_zone, $time);
82
-        if (! isset($transition['offset'])) {
82
+        if ( ! isset($transition['offset'])) {
83 83
             throw new DomainException(
84 84
                 sprintf(
85 85
                     esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
     public function timezoneSelectInput($timezone_string = '')
102 102
     {
103 103
         // get WP date time format
104
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
104
+        $datetime_format = get_option('date_format').' '.get_option('time_format');
105 105
         // if passed a value, then use that, else get WP option
106
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : (string)get_option('timezone_string');
106
+        $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
107 107
         // check if the timezone is valid but don't throw any errors if it isn't
108 108
         $timezone_string = $this->validateTimezone($timezone_string, false)
109 109
             ? $timezone_string
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
             $timezone_string = 'UTC';
116 116
             $check_zone_info = false;
117 117
             if ($gmt_offset > 0) {
118
-                $timezone_string = 'UTC+' . $gmt_offset;
118
+                $timezone_string = 'UTC+'.$gmt_offset;
119 119
             } elseif ($gmt_offset < 0) {
120
-                $timezone_string = 'UTC' . $gmt_offset;
120
+                $timezone_string = 'UTC'.$gmt_offset;
121 121
             }
122 122
         }
123 123
         ?>
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
                 __('%1$sUTC%2$s time is %3$s'),
137 137
                 '<abbr title="Coordinated Universal Time">',
138 138
                 '</abbr>',
139
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
139
+                '<code>'.date_i18n($datetime_format, false, true).'</code>'
140 140
             );
141 141
             ?></span>
142
-        <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
143
-        <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
142
+        <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?>
143
+        <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span>
144 144
     <?php endif; ?>
145 145
 
146 146
         <?php if ($check_zone_info && $timezone_string) : ?>
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
                     // transition time from date_i18n().
179 179
                     printf(
180 180
                         $message,
181
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
181
+                        '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >'
182 182
                     );
183 183
                 } else {
184 184
                     _e('This timezone does not observe daylight saving time.');
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
211 211
         $timezone_string = $this->getValidTimezoneString($timezone_string);
212 212
         $TimeZone        = new DateTimeZone($timezone_string);
213
-        $DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
213
+        $DateTime        = new DateTime('@'.$unix_timestamp, $TimeZone);
214 214
         $offset          = timezone_offset_get($TimeZone, $DateTime);
215 215
         return (int) $DateTime->format('U') + (int) $offset;
216 216
     }
Please login to merge, or discard this patch.
core/services/helpers/datetime/PhpCompatGreaterFiveSixHelper.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -8,91 +8,91 @@
 block discarded – undo
8 8
 
9 9
 class PhpCompatGreaterFiveSixHelper extends AbstractHelper
10 10
 {
11
-    /**
12
-     * PhpCompatLessFiveSixHelper constructor.
13
-     *
14
-     * @throws DomainException
15
-     */
16
-    public function __construct()
17
-    {
18
-        if (PHP_VERSION_ID < 50600) {
19
-            throw new DomainException(
20
-                sprintf(
21
-                    esc_html__(
22
-                        'The %1$s is only usable on php versions greater than 5.6.  You\'ll want to use %2$s instead.',
23
-                        'event_espresso'
24
-                    ),
25
-                    __CLASS__,
26
-                    'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper'
27
-                )
28
-            );
29
-        }
30
-    }
11
+	/**
12
+	 * PhpCompatLessFiveSixHelper constructor.
13
+	 *
14
+	 * @throws DomainException
15
+	 */
16
+	public function __construct()
17
+	{
18
+		if (PHP_VERSION_ID < 50600) {
19
+			throw new DomainException(
20
+				sprintf(
21
+					esc_html__(
22
+						'The %1$s is only usable on php versions greater than 5.6.  You\'ll want to use %2$s instead.',
23
+						'event_espresso'
24
+					),
25
+					__CLASS__,
26
+					'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper'
27
+				)
28
+			);
29
+		}
30
+	}
31 31
 
32
-    /**
33
-     * Returns a timezone string for the provided gmt_offset.
34
-     * This is a valid timezone string that can be sent into DateTimeZone
35
-     *
36
-     * @param float|string $gmt_offset
37
-     * @return string
38
-     */
39
-    public function getTimezoneStringFromGmtOffset($gmt_offset = '')
40
-    {
41
-        $gmt_offset_or_timezone_string = $this->sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset);
42
-        return is_float($gmt_offset_or_timezone_string)
43
-            ? $this->convertWpGmtOffsetForDateTimeZone($gmt_offset_or_timezone_string)
44
-            : $gmt_offset_or_timezone_string;
45
-    }
32
+	/**
33
+	 * Returns a timezone string for the provided gmt_offset.
34
+	 * This is a valid timezone string that can be sent into DateTimeZone
35
+	 *
36
+	 * @param float|string $gmt_offset
37
+	 * @return string
38
+	 */
39
+	public function getTimezoneStringFromGmtOffset($gmt_offset = '')
40
+	{
41
+		$gmt_offset_or_timezone_string = $this->sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset);
42
+		return is_float($gmt_offset_or_timezone_string)
43
+			? $this->convertWpGmtOffsetForDateTimeZone($gmt_offset_or_timezone_string)
44
+			: $gmt_offset_or_timezone_string;
45
+	}
46 46
 
47 47
 
48 48
 
49
-    /**
50
-     * Returns a formatted offset for use as an argument for constructing DateTimeZone
51
-     * @param float $gmt_offset This should be a float representing the gmt_offset.
52
-     * @return string
53
-     */
54
-    protected function convertWpGmtOffsetForDateTimeZone($gmt_offset)
55
-    {
56
-        $gmt_offset = (float) $gmt_offset;
57
-        $is_negative = $gmt_offset < 0;
58
-        $gmt_offset *= 100;
59
-        $gmt_offset = absint($gmt_offset);
60
-        //negative and need zero padding?
61
-        if (strlen($gmt_offset) < 4) {
62
-            $gmt_offset = str_pad($gmt_offset, 4, '0', STR_PAD_LEFT);
63
-        }
64
-        $gmt_offset = $this->convertToTimeFraction($gmt_offset);
65
-        //return something like -1300, -0200 or +1300, +0200
66
-        return $is_negative ? '-' . $gmt_offset : '+' . $gmt_offset;
67
-    }
49
+	/**
50
+	 * Returns a formatted offset for use as an argument for constructing DateTimeZone
51
+	 * @param float $gmt_offset This should be a float representing the gmt_offset.
52
+	 * @return string
53
+	 */
54
+	protected function convertWpGmtOffsetForDateTimeZone($gmt_offset)
55
+	{
56
+		$gmt_offset = (float) $gmt_offset;
57
+		$is_negative = $gmt_offset < 0;
58
+		$gmt_offset *= 100;
59
+		$gmt_offset = absint($gmt_offset);
60
+		//negative and need zero padding?
61
+		if (strlen($gmt_offset) < 4) {
62
+			$gmt_offset = str_pad($gmt_offset, 4, '0', STR_PAD_LEFT);
63
+		}
64
+		$gmt_offset = $this->convertToTimeFraction($gmt_offset);
65
+		//return something like -1300, -0200 or +1300, +0200
66
+		return $is_negative ? '-' . $gmt_offset : '+' . $gmt_offset;
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * Converts something like `1550` to `1530` or `0275` to `0245`
72
-     * Incoming offset should be a positive value, this will mutate negative values. Be aware!
73
-     * @param int $offset
74
-     * @return mixed
75
-     */
76
-    protected function convertToTimeFraction($offset)
77
-    {
78
-        $first_part = substr($offset, 0, 2);
79
-        $second_part = substr($offset, 2, 2);
80
-        $second_part = str_replace(array('25', '50', '75'), array('15', '30', '45'), $second_part);
81
-        return $first_part . $second_part;
82
-    }
70
+	/**
71
+	 * Converts something like `1550` to `1530` or `0275` to `0245`
72
+	 * Incoming offset should be a positive value, this will mutate negative values. Be aware!
73
+	 * @param int $offset
74
+	 * @return mixed
75
+	 */
76
+	protected function convertToTimeFraction($offset)
77
+	{
78
+		$first_part = substr($offset, 0, 2);
79
+		$second_part = substr($offset, 2, 2);
80
+		$second_part = str_replace(array('25', '50', '75'), array('15', '30', '45'), $second_part);
81
+		return $first_part . $second_part;
82
+	}
83 83
 
84 84
 
85
-    /**
86
-     * Get Timezone offset for given timezone object
87
-     *
88
-     * @param DateTimeZone $date_time_zone
89
-     * @param null|int     $time
90
-     * @return int
91
-     */
92
-    public function getTimezoneOffset(DateTimezone $date_time_zone, $time = NULL)
93
-    {
94
-        $time = is_int($time) || $time === null ? $time : (int) strtotime($time);
95
-        $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
96
-        return $date_time_zone->getOffset(new DateTime('@' . $time));
97
-    }
85
+	/**
86
+	 * Get Timezone offset for given timezone object
87
+	 *
88
+	 * @param DateTimeZone $date_time_zone
89
+	 * @param null|int     $time
90
+	 * @return int
91
+	 */
92
+	public function getTimezoneOffset(DateTimezone $date_time_zone, $time = NULL)
93
+	{
94
+		$time = is_int($time) || $time === null ? $time : (int) strtotime($time);
95
+		$time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
96
+		return $date_time_zone->getOffset(new DateTime('@' . $time));
97
+	}
98 98
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         }
64 64
         $gmt_offset = $this->convertToTimeFraction($gmt_offset);
65 65
         //return something like -1300, -0200 or +1300, +0200
66
-        return $is_negative ? '-' . $gmt_offset : '+' . $gmt_offset;
66
+        return $is_negative ? '-'.$gmt_offset : '+'.$gmt_offset;
67 67
     }
68 68
 
69 69
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         $first_part = substr($offset, 0, 2);
79 79
         $second_part = substr($offset, 2, 2);
80 80
         $second_part = str_replace(array('25', '50', '75'), array('15', '30', '45'), $second_part);
81
-        return $first_part . $second_part;
81
+        return $first_part.$second_part;
82 82
     }
83 83
 
84 84
 
@@ -93,6 +93,6 @@  discard block
 block discarded – undo
93 93
     {
94 94
         $time = is_int($time) || $time === null ? $time : (int) strtotime($time);
95 95
         $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
96
-        return $date_time_zone->getOffset(new DateTime('@' . $time));
96
+        return $date_time_zone->getOffset(new DateTime('@'.$time));
97 97
     }
98 98
 }
Please login to merge, or discard this patch.
core/services/helpers/datetime/PhpCompatLessFiveSixHelper.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -18,221 +18,221 @@
 block discarded – undo
18 18
 class PhpCompatLessFiveSixHelper extends AbstractHelper
19 19
 {
20 20
 
21
-    /**
22
-     * PhpCompatLessFiveSixHelper constructor.
23
-     *
24
-     * @throws DomainException
25
-     */
26
-    public function __construct()
27
-    {
28
-        if (PHP_VERSION_ID >= 50600) {
29
-            throw new DomainException(
30
-                sprintf(
31
-                    esc_html__(
32
-                        'The %1$s is only usable on php versions less than 5.6.  You\'ll want to use %2$s instead.',
33
-                        'event_espresso'
34
-                    ),
35
-                    __CLASS__,
36
-                    'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper'
37
-                )
38
-            );
39
-        }
40
-    }
21
+	/**
22
+	 * PhpCompatLessFiveSixHelper constructor.
23
+	 *
24
+	 * @throws DomainException
25
+	 */
26
+	public function __construct()
27
+	{
28
+		if (PHP_VERSION_ID >= 50600) {
29
+			throw new DomainException(
30
+				sprintf(
31
+					esc_html__(
32
+						'The %1$s is only usable on php versions less than 5.6.  You\'ll want to use %2$s instead.',
33
+						'event_espresso'
34
+					),
35
+					__CLASS__,
36
+					'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper'
37
+				)
38
+			);
39
+		}
40
+	}
41 41
 
42
-    /**
43
-     * Returns a timezone string for the provided gmt_offset.
44
-     *
45
-     * @param float|string $gmt_offset
46
-     * @return string
47
-     * @throws EE_Error
48
-     */
49
-    public function getTimezoneStringFromGmtOffset($gmt_offset = '')
50
-    {
51
-        $gmt_offset_or_timezone_string = $this->sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset);
52
-        if (is_string($gmt_offset_or_timezone_string)) {
53
-            return $gmt_offset_or_timezone_string;
54
-        }
55
-        //well we know its a float, so let's roll with it.
56
-        $gmt_offset = $gmt_offset_or_timezone_string;
57
-        // convert GMT offset to seconds
58
-        $gmt_offset *= HOUR_IN_SECONDS;
59
-        // although we don't know the TZ abbreviation, we know the UTC offset
60
-        $timezone_string = timezone_name_from_abbr(null, $gmt_offset);
61
-        //only use this timezone_string IF it's current offset matches the given offset
62
-        if (! empty($timezone_string)) {
63
-            $offset = null;
64
-            try {
65
-                $offset = $this->getTimezoneOffset(new DateTimeZone($timezone_string));
66
-                if ($offset !== $gmt_offset) {
67
-                    $timezone_string = false;
68
-                }
69
-            } catch (Exception $e) {
70
-                $timezone_string = false;
71
-            }
72
-        }
73
-        // better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()
74
-        //...
75
-        $timezone_string = $timezone_string !== false
76
-            ? $timezone_string
77
-            : $this->getTimezoneStringFromAbbreviationsList($gmt_offset);
78
-        return $timezone_string;
79
-    }
42
+	/**
43
+	 * Returns a timezone string for the provided gmt_offset.
44
+	 *
45
+	 * @param float|string $gmt_offset
46
+	 * @return string
47
+	 * @throws EE_Error
48
+	 */
49
+	public function getTimezoneStringFromGmtOffset($gmt_offset = '')
50
+	{
51
+		$gmt_offset_or_timezone_string = $this->sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset);
52
+		if (is_string($gmt_offset_or_timezone_string)) {
53
+			return $gmt_offset_or_timezone_string;
54
+		}
55
+		//well we know its a float, so let's roll with it.
56
+		$gmt_offset = $gmt_offset_or_timezone_string;
57
+		// convert GMT offset to seconds
58
+		$gmt_offset *= HOUR_IN_SECONDS;
59
+		// although we don't know the TZ abbreviation, we know the UTC offset
60
+		$timezone_string = timezone_name_from_abbr(null, $gmt_offset);
61
+		//only use this timezone_string IF it's current offset matches the given offset
62
+		if (! empty($timezone_string)) {
63
+			$offset = null;
64
+			try {
65
+				$offset = $this->getTimezoneOffset(new DateTimeZone($timezone_string));
66
+				if ($offset !== $gmt_offset) {
67
+					$timezone_string = false;
68
+				}
69
+			} catch (Exception $e) {
70
+				$timezone_string = false;
71
+			}
72
+		}
73
+		// better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()
74
+		//...
75
+		$timezone_string = $timezone_string !== false
76
+			? $timezone_string
77
+			: $this->getTimezoneStringFromAbbreviationsList($gmt_offset);
78
+		return $timezone_string;
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * @param int  $gmt_offset
84
-     * @param bool $coerce If true, we attempt to coerce with our adjustment table
85
-     * @see self::adjustInvalidGmtOffset
86
-     * @return string
87
-     * @throws EE_Error
88
-     */
89
-    protected function getTimezoneStringFromAbbreviationsList($gmt_offset = 0, $coerce = true)
90
-    {
91
-        $gmt_offset = (int)$gmt_offset;
92
-        /** @var array[] $abbreviations */
93
-        $abbreviations = DateTimeZone::listAbbreviations();
94
-        foreach ($abbreviations as $abbreviation) {
95
-            foreach ($abbreviation as $timezone) {
96
-                if ((int)$timezone['offset'] === $gmt_offset && (bool)$timezone['dst'] === false) {
97
-                    try {
98
-                        $offset = $this->getTimezoneOffset(new DateTimeZone($timezone['timezone_id']));
99
-                        if ($offset !== $gmt_offset) {
100
-                            continue;
101
-                        }
102
-                        return $timezone['timezone_id'];
103
-                    } catch (Exception $e) {
104
-                        continue;
105
-                    }
106
-                }
107
-            }
108
-        }
109
-        //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
110
-        if ($coerce === true) {
111
-            $timezone_string = $this->getTimezoneStringFromAbbreviationsList(
112
-                $this->adjustInvalidGmtOffsets($gmt_offset),
113
-                false
114
-            );
115
-            if ($timezone_string) {
116
-                return $timezone_string;
117
-            }
118
-        }
119
-        throw new EE_Error(
120
-            sprintf(
121
-                esc_html__(
122
-                    'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
123
-                    'event_espresso'
124
-                ),
125
-                $gmt_offset / HOUR_IN_SECONDS,
126
-                '<a href="http://www.php.net/manual/en/timezones.php">',
127
-                '</a>'
128
-            )
129
-        );
130
-    }
82
+	/**
83
+	 * @param int  $gmt_offset
84
+	 * @param bool $coerce If true, we attempt to coerce with our adjustment table
85
+	 * @see self::adjustInvalidGmtOffset
86
+	 * @return string
87
+	 * @throws EE_Error
88
+	 */
89
+	protected function getTimezoneStringFromAbbreviationsList($gmt_offset = 0, $coerce = true)
90
+	{
91
+		$gmt_offset = (int)$gmt_offset;
92
+		/** @var array[] $abbreviations */
93
+		$abbreviations = DateTimeZone::listAbbreviations();
94
+		foreach ($abbreviations as $abbreviation) {
95
+			foreach ($abbreviation as $timezone) {
96
+				if ((int)$timezone['offset'] === $gmt_offset && (bool)$timezone['dst'] === false) {
97
+					try {
98
+						$offset = $this->getTimezoneOffset(new DateTimeZone($timezone['timezone_id']));
99
+						if ($offset !== $gmt_offset) {
100
+							continue;
101
+						}
102
+						return $timezone['timezone_id'];
103
+					} catch (Exception $e) {
104
+						continue;
105
+					}
106
+				}
107
+			}
108
+		}
109
+		//if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
110
+		if ($coerce === true) {
111
+			$timezone_string = $this->getTimezoneStringFromAbbreviationsList(
112
+				$this->adjustInvalidGmtOffsets($gmt_offset),
113
+				false
114
+			);
115
+			if ($timezone_string) {
116
+				return $timezone_string;
117
+			}
118
+		}
119
+		throw new EE_Error(
120
+			sprintf(
121
+				esc_html__(
122
+					'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
123
+					'event_espresso'
124
+				),
125
+				$gmt_offset / HOUR_IN_SECONDS,
126
+				'<a href="http://www.php.net/manual/en/timezones.php">',
127
+				'</a>'
128
+			)
129
+		);
130
+	}
131 131
 
132 132
 
133
-    /**
134
-     * Depending on PHP version,
135
-     * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
136
-     * To get around that, for these fringe timezones we bump them to a known valid offset.
137
-     * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
138
-     *
139
-     * @param int $gmt_offset
140
-     * @return int
141
-     */
142
-    public function adjustInvalidGmtOffsets($gmt_offset = 0)
143
-    {
144
-        //make sure $gmt_offset is int
145
-        $gmt_offset = (int) $gmt_offset;
146
-        switch ($gmt_offset) {
147
-            //-12
148
-            case -43200:
149
-                $gmt_offset = -39600;
150
-                break;
151
-            //-11.5
152
-            case -41400:
153
-                $gmt_offset = -39600;
154
-                break;
155
-            //-10.5
156
-            case -37800:
157
-                $gmt_offset = -39600;
158
-                break;
159
-            //-8.5
160
-            case -30600:
161
-                $gmt_offset = -28800;
162
-                break;
163
-            //-7.5
164
-            case -27000:
165
-                $gmt_offset = -25200;
166
-                break;
167
-            //-6.5
168
-            case -23400:
169
-                $gmt_offset = -21600;
170
-                break;
171
-            //-5.5
172
-            case -19800:
173
-                $gmt_offset = -18000;
174
-                break;
175
-            //-4.5
176
-            case -16200:
177
-                $gmt_offset = -14400;
178
-                break;
179
-            //-3.5
180
-            case -12600:
181
-                $gmt_offset = -10800;
182
-                break;
183
-            //-2.5
184
-            case -9000:
185
-                $gmt_offset = -7200;
186
-                break;
187
-            //-1.5
188
-            case -5400:
189
-                $gmt_offset = -3600;
190
-                break;
191
-            //-0.5
192
-            case -1800:
193
-                $gmt_offset = 0;
194
-                break;
195
-            //.5
196
-            case 1800:
197
-                $gmt_offset = 3600;
198
-                break;
199
-            //1.5
200
-            case 5400:
201
-                $gmt_offset = 7200;
202
-                break;
203
-            //2.5
204
-            case 9000:
205
-                $gmt_offset = 10800;
206
-                break;
207
-            //3.5
208
-            case 12600:
209
-                $gmt_offset = 14400;
210
-                break;
211
-            //7.5
212
-            case 27000:
213
-                $gmt_offset = 28800;
214
-                break;
215
-            //8.5
216
-            case 30600:
217
-                $gmt_offset = 31500;
218
-                break;
219
-            //10.5
220
-            case 37800:
221
-                $gmt_offset = 39600;
222
-                break;
223
-            //11.5
224
-            case 41400:
225
-                $gmt_offset = 43200;
226
-                break;
227
-            //12.75
228
-            case 45900:
229
-                $gmt_offset = 46800;
230
-                break;
231
-            //13.75
232
-            case 49500:
233
-                $gmt_offset = 50400;
234
-                break;
235
-        }
236
-        return $gmt_offset;
237
-    }
133
+	/**
134
+	 * Depending on PHP version,
135
+	 * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
136
+	 * To get around that, for these fringe timezones we bump them to a known valid offset.
137
+	 * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
138
+	 *
139
+	 * @param int $gmt_offset
140
+	 * @return int
141
+	 */
142
+	public function adjustInvalidGmtOffsets($gmt_offset = 0)
143
+	{
144
+		//make sure $gmt_offset is int
145
+		$gmt_offset = (int) $gmt_offset;
146
+		switch ($gmt_offset) {
147
+			//-12
148
+			case -43200:
149
+				$gmt_offset = -39600;
150
+				break;
151
+			//-11.5
152
+			case -41400:
153
+				$gmt_offset = -39600;
154
+				break;
155
+			//-10.5
156
+			case -37800:
157
+				$gmt_offset = -39600;
158
+				break;
159
+			//-8.5
160
+			case -30600:
161
+				$gmt_offset = -28800;
162
+				break;
163
+			//-7.5
164
+			case -27000:
165
+				$gmt_offset = -25200;
166
+				break;
167
+			//-6.5
168
+			case -23400:
169
+				$gmt_offset = -21600;
170
+				break;
171
+			//-5.5
172
+			case -19800:
173
+				$gmt_offset = -18000;
174
+				break;
175
+			//-4.5
176
+			case -16200:
177
+				$gmt_offset = -14400;
178
+				break;
179
+			//-3.5
180
+			case -12600:
181
+				$gmt_offset = -10800;
182
+				break;
183
+			//-2.5
184
+			case -9000:
185
+				$gmt_offset = -7200;
186
+				break;
187
+			//-1.5
188
+			case -5400:
189
+				$gmt_offset = -3600;
190
+				break;
191
+			//-0.5
192
+			case -1800:
193
+				$gmt_offset = 0;
194
+				break;
195
+			//.5
196
+			case 1800:
197
+				$gmt_offset = 3600;
198
+				break;
199
+			//1.5
200
+			case 5400:
201
+				$gmt_offset = 7200;
202
+				break;
203
+			//2.5
204
+			case 9000:
205
+				$gmt_offset = 10800;
206
+				break;
207
+			//3.5
208
+			case 12600:
209
+				$gmt_offset = 14400;
210
+				break;
211
+			//7.5
212
+			case 27000:
213
+				$gmt_offset = 28800;
214
+				break;
215
+			//8.5
216
+			case 30600:
217
+				$gmt_offset = 31500;
218
+				break;
219
+			//10.5
220
+			case 37800:
221
+				$gmt_offset = 39600;
222
+				break;
223
+			//11.5
224
+			case 41400:
225
+				$gmt_offset = 43200;
226
+				break;
227
+			//12.75
228
+			case 45900:
229
+				$gmt_offset = 46800;
230
+				break;
231
+			//13.75
232
+			case 49500:
233
+				$gmt_offset = 50400;
234
+				break;
235
+		}
236
+		return $gmt_offset;
237
+	}
238 238
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
         // although we don't know the TZ abbreviation, we know the UTC offset
60 60
         $timezone_string = timezone_name_from_abbr(null, $gmt_offset);
61 61
         //only use this timezone_string IF it's current offset matches the given offset
62
-        if (! empty($timezone_string)) {
62
+        if ( ! empty($timezone_string)) {
63 63
             $offset = null;
64 64
             try {
65 65
                 $offset = $this->getTimezoneOffset(new DateTimeZone($timezone_string));
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
      */
89 89
     protected function getTimezoneStringFromAbbreviationsList($gmt_offset = 0, $coerce = true)
90 90
     {
91
-        $gmt_offset = (int)$gmt_offset;
91
+        $gmt_offset = (int) $gmt_offset;
92 92
         /** @var array[] $abbreviations */
93 93
         $abbreviations = DateTimeZone::listAbbreviations();
94 94
         foreach ($abbreviations as $abbreviation) {
95 95
             foreach ($abbreviation as $timezone) {
96
-                if ((int)$timezone['offset'] === $gmt_offset && (bool)$timezone['dst'] === false) {
96
+                if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) {
97 97
                     try {
98 98
                         $offset = $this->getTimezoneOffset(new DateTimeZone($timezone['timezone_id']));
99 99
                         if ($offset !== $gmt_offset) {
Please login to merge, or discard this patch.
core/domain/values/Url.php 2 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -21,196 +21,196 @@
 block discarded – undo
21 21
 class Url
22 22
 {
23 23
 
24
-    /**
25
-     * @var string $scheme
26
-     */
27
-    private $scheme;
28
-
29
-    /**
30
-     * @var string $host
31
-     */
32
-    private $host;
33
-
34
-    /**
35
-     * @var string $path
36
-     */
37
-    private $path;
38
-
39
-    /**
40
-     * @var string $query
41
-     */
42
-    private $query;
43
-
44
-    /**
45
-     * @var string $fragment
46
-     */
47
-    private $fragment;
48
-
49
-
50
-    /**
51
-     * Url constructor.
52
-     *
53
-     * @param $url
54
-     * @throws InvalidArgumentException
55
-     */
56
-    public function __construct($url)
57
-    {
58
-        if (
59
-            ! filter_var(
60
-                $url,
61
-                FILTER_VALIDATE_URL,
62
-                array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED)
63
-            )
64
-        ) {
65
-            throw new InvalidArgumentException(esc_html__('Invalid URL. Both the "Scheme" and "Host" are required.',
66
-                'event_espresso'));
67
-        }
68
-        $url = parse_url($url);
69
-        $this->setScheme($url);
70
-        $this->setHost($url);
71
-        $this->setPath($url);
72
-        $this->setQuery($url);
73
-        $this->setFragment($url);
74
-    }
75
-
76
-
77
-    /**
78
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
79
-     * will return a string like: 'abc://'
80
-     *
81
-     * @return string
82
-     */
83
-    public function scheme()
84
-    {
85
-        return $this->scheme;
86
-    }
87
-
88
-
89
-    /**
90
-     * @param array $url
91
-     */
92
-    private function setScheme($url)
93
-    {
94
-        $this->scheme = $url['scheme'] . '://';
95
-    }
96
-
97
-
98
-    /**
99
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
100
-     * will return a string like: 'example.com'
101
-     *
102
-     * @return string
103
-     */
104
-    public function host()
105
-    {
106
-        return $this->host;
107
-    }
108
-
109
-
110
-    /**
111
-     * @param array $url
112
-     */
113
-    private function setHost($url)
114
-    {
115
-        $this->host = $url['host'];
116
-    }
117
-
118
-
119
-    /**
120
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
121
-     * will return a string like: '/path/data'
122
-     *
123
-     * @return string
124
-     */
125
-    public function path()
126
-    {
127
-        return $this->path;
128
-    }
129
-
130
-
131
-    /**
132
-     * @param array $url
133
-     */
134
-    private function setPath($url)
135
-    {
136
-        $this->path = isset($url['path']) ? $url['path'] : '';
137
-    }
138
-
139
-
140
-    /**
141
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
142
-     * will return a string like: '?key=value'
143
-     *
144
-     * @return string
145
-     */
146
-    public function queryString()
147
-    {
148
-        return $this->query !== '' ? '?' . $this->query : '';
149
-    }
150
-
151
-
152
-    /**
153
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
154
-     * will return an array like: array('key' => 'value')
155
-     *
156
-     * @return array
157
-     */
158
-    public function queryParams()
159
-    {
160
-        return wp_parse_args($this->query);
161
-    }
162
-
163
-
164
-    /**
165
-     * @param array $url
166
-     */
167
-    private function setQuery($url)
168
-    {
169
-        $this->query = isset($url['query']) ? $url['query'] : '';
170
-    }
171
-
172
-
173
-    /**
174
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
175
-     * will return a string like: '#id'
176
-     *
177
-     * @return string
178
-     */
179
-    public function fragment()
180
-    {
181
-        return $this->fragment !== '' ? '#' . $this->fragment : '';
182
-    }
183
-
184
-
185
-    /**
186
-     * @param array $url
187
-     */
188
-    private function setFragment($url)
189
-    {
190
-        $this->fragment = isset($url['fragment']) ? $url['fragment'] : '';
191
-    }
192
-
193
-
194
-    /**
195
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
196
-     * will return a string like: 'abc://example.com/path/data?key=value#id'
197
-     *
198
-     * @return string
199
-     */
200
-    public function getFullUrl()
201
-    {
202
-        return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment();
203
-    }
204
-
205
-
206
-    /**
207
-     * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
208
-     * will return a string like: 'abc://example.com/path/data?key=value#id'
209
-     *
210
-     * @return string
211
-     */
212
-    public function __toString()
213
-    {
214
-        return $this->getFullUrl();
215
-    }
24
+	/**
25
+	 * @var string $scheme
26
+	 */
27
+	private $scheme;
28
+
29
+	/**
30
+	 * @var string $host
31
+	 */
32
+	private $host;
33
+
34
+	/**
35
+	 * @var string $path
36
+	 */
37
+	private $path;
38
+
39
+	/**
40
+	 * @var string $query
41
+	 */
42
+	private $query;
43
+
44
+	/**
45
+	 * @var string $fragment
46
+	 */
47
+	private $fragment;
48
+
49
+
50
+	/**
51
+	 * Url constructor.
52
+	 *
53
+	 * @param $url
54
+	 * @throws InvalidArgumentException
55
+	 */
56
+	public function __construct($url)
57
+	{
58
+		if (
59
+			! filter_var(
60
+				$url,
61
+				FILTER_VALIDATE_URL,
62
+				array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED)
63
+			)
64
+		) {
65
+			throw new InvalidArgumentException(esc_html__('Invalid URL. Both the "Scheme" and "Host" are required.',
66
+				'event_espresso'));
67
+		}
68
+		$url = parse_url($url);
69
+		$this->setScheme($url);
70
+		$this->setHost($url);
71
+		$this->setPath($url);
72
+		$this->setQuery($url);
73
+		$this->setFragment($url);
74
+	}
75
+
76
+
77
+	/**
78
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
79
+	 * will return a string like: 'abc://'
80
+	 *
81
+	 * @return string
82
+	 */
83
+	public function scheme()
84
+	{
85
+		return $this->scheme;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @param array $url
91
+	 */
92
+	private function setScheme($url)
93
+	{
94
+		$this->scheme = $url['scheme'] . '://';
95
+	}
96
+
97
+
98
+	/**
99
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
100
+	 * will return a string like: 'example.com'
101
+	 *
102
+	 * @return string
103
+	 */
104
+	public function host()
105
+	{
106
+		return $this->host;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @param array $url
112
+	 */
113
+	private function setHost($url)
114
+	{
115
+		$this->host = $url['host'];
116
+	}
117
+
118
+
119
+	/**
120
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
121
+	 * will return a string like: '/path/data'
122
+	 *
123
+	 * @return string
124
+	 */
125
+	public function path()
126
+	{
127
+		return $this->path;
128
+	}
129
+
130
+
131
+	/**
132
+	 * @param array $url
133
+	 */
134
+	private function setPath($url)
135
+	{
136
+		$this->path = isset($url['path']) ? $url['path'] : '';
137
+	}
138
+
139
+
140
+	/**
141
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
142
+	 * will return a string like: '?key=value'
143
+	 *
144
+	 * @return string
145
+	 */
146
+	public function queryString()
147
+	{
148
+		return $this->query !== '' ? '?' . $this->query : '';
149
+	}
150
+
151
+
152
+	/**
153
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
154
+	 * will return an array like: array('key' => 'value')
155
+	 *
156
+	 * @return array
157
+	 */
158
+	public function queryParams()
159
+	{
160
+		return wp_parse_args($this->query);
161
+	}
162
+
163
+
164
+	/**
165
+	 * @param array $url
166
+	 */
167
+	private function setQuery($url)
168
+	{
169
+		$this->query = isset($url['query']) ? $url['query'] : '';
170
+	}
171
+
172
+
173
+	/**
174
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
175
+	 * will return a string like: '#id'
176
+	 *
177
+	 * @return string
178
+	 */
179
+	public function fragment()
180
+	{
181
+		return $this->fragment !== '' ? '#' . $this->fragment : '';
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param array $url
187
+	 */
188
+	private function setFragment($url)
189
+	{
190
+		$this->fragment = isset($url['fragment']) ? $url['fragment'] : '';
191
+	}
192
+
193
+
194
+	/**
195
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
196
+	 * will return a string like: 'abc://example.com/path/data?key=value#id'
197
+	 *
198
+	 * @return string
199
+	 */
200
+	public function getFullUrl()
201
+	{
202
+		return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment();
203
+	}
204
+
205
+
206
+	/**
207
+	 * For a URL like: abc://username:[email protected]:123/path/data?key=value#id
208
+	 * will return a string like: 'abc://example.com/path/data?key=value#id'
209
+	 *
210
+	 * @return string
211
+	 */
212
+	public function __toString()
213
+	{
214
+		return $this->getFullUrl();
215
+	}
216 216
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     private function setScheme($url)
93 93
     {
94
-        $this->scheme = $url['scheme'] . '://';
94
+        $this->scheme = $url['scheme'].'://';
95 95
     }
96 96
 
97 97
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
      */
146 146
     public function queryString()
147 147
     {
148
-        return $this->query !== '' ? '?' . $this->query : '';
148
+        return $this->query !== '' ? '?'.$this->query : '';
149 149
     }
150 150
 
151 151
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      */
179 179
     public function fragment()
180 180
     {
181
-        return $this->fragment !== '' ? '#' . $this->fragment : '';
181
+        return $this->fragment !== '' ? '#'.$this->fragment : '';
182 182
     }
183 183
 
184 184
 
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     public function getFullUrl()
201 201
     {
202
-        return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment();
202
+        return $this->scheme().$this->host().$this->path().$this->queryString().$this->fragment();
203 203
     }
204 204
 
205 205
 
Please login to merge, or discard this patch.
core/db_models/EEM_Question.model.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
      * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
365 365
      * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city');
366 366
      * @param $QST_system
367
-     * @return int of QST_ID for the question that corresponds to that QST_system
367
+     * @return string of QST_ID for the question that corresponds to that QST_system
368 368
      */
369 369
     public function get_Question_ID_from_system_string($QST_system)
370 370
     {
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 
426 426
 
427 427
     /**
428
-     * @return array
428
+     * @return EEM_Question
429 429
      */
430 430
     public function question_descriptions()
431 431
     {
Please login to merge, or discard this patch.
Indentation   +401 added lines, -401 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (!defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php');
5 5
 require_once(EE_CLASSES . 'EE_Question.class.php');
@@ -16,406 +16,406 @@  discard block
 block discarded – undo
16 16
 class EEM_Question extends EEM_Soft_Delete_Base
17 17
 {
18 18
 
19
-    // constant used to indicate that the question type is COUNTRY
20
-    const QST_type_country = 'COUNTRY';
21
-
22
-    // constant used to indicate that the question type is DATE
23
-    const QST_type_date = 'DATE';
24
-
25
-    // constant used to indicate that the question type is DROPDOWN
26
-    const QST_type_dropdown = 'DROPDOWN';
27
-
28
-    // constant used to indicate that the question type is CHECKBOX
29
-    const QST_type_checkbox = 'CHECKBOX';
30
-
31
-    // constant used to indicate that the question type is RADIO_BTN
32
-    const QST_type_radio = 'RADIO_BTN';
33
-
34
-    // constant used to indicate that the question type is STATE
35
-    const QST_type_state = 'STATE';
36
-
37
-    // constant used to indicate that the question type is TEXT
38
-    const QST_type_text = 'TEXT';
39
-
40
-    // constant used to indicate that the question type is TEXTAREA
41
-    const QST_type_textarea = 'TEXTAREA';
42
-
43
-    // constant used to indicate that the question type is a TEXTAREA that allows simple html
44
-    const QST_type_html_textarea = 'HTML_TEXTAREA';
45
-
46
-    // constant used to indicate that the question type is an email input
47
-    const QST_type_email = 'EMAIL';
48
-
49
-    // constant used to indicate that the question type is a US-formatted phone number
50
-    const QST_type_us_phone = 'US_PHONE';
51
-
52
-    // constant used to indicate that the question type is an integer (whole number)
53
-    const QST_type_int = 'INTEGER';
54
-
55
-    // constant used to indicate that the question type is a decimal (float)
56
-    const QST_type_decimal = 'DECIMAL';
57
-
58
-    // constant used to indicate that the question type is a valid URL
59
-    const QST_type_url = 'URL';
60
-
61
-    // constant used to indicate that the question type is a YEAR
62
-    const QST_type_year = 'YEAR';
63
-
64
-    // constant used to indicate that the question type is a multi-select
65
-    const QST_type_multi_select = 'MULTI_SELECT';
66
-
67
-    /**
68
-     * Question types that are interchangeable, even after answers have been provided for them.
69
-     * Top-level keys are category slugs, next level is an array of question types. If question types
70
-     * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
71
-     *
72
-     * @access protected
73
-     * @var array $_question_type_categories {
74
-     * @type string $text
75
-     * @type string $single -answer-enum
76
-     * @type string $multi -answer-enum
77
-     *                    }
78
-     */
79
-    protected $_question_type_categories = array();
80
-
81
-    /**
82
-     * lists all the question types which should be allowed. Ideally, this will be extensible.
83
-     *
84
-     * @access protected
85
-     * @var array $_allowed_question_types
86
-     */
87
-    protected $_allowed_question_types = array();
88
-
89
-    /**
90
-     * brief descriptions for all the question types
91
-     *
92
-     * @access protected
93
-     * @var EEM_Question $_instance
94
-     */
95
-    protected $_question_descriptions;
96
-
97
-
98
-    // private instance of the Attendee object
99
-    protected static $_instance = NULL;
100
-
101
-
102
-    /**
103
-     * EEM_Question constructor.
104
-     *
105
-     * @param null $timezone
106
-     */
107
-    protected function __construct($timezone = NULL)
108
-    {
109
-        $this->singular_item = __('Question', 'event_espresso');
110
-        $this->plural_item = __('Questions', 'event_espresso');
111
-        $this->_allowed_question_types = apply_filters(
112
-            'FHEE__EEM_Question__construct__allowed_question_types',
113
-            array(
114
-                EEM_Question::QST_type_text => __('Text', 'event_espresso'),
115
-                EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'),
116
-                EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'),
117
-                EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'),
118
-                EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'),
119
-                EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'),
120
-                EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'),
121
-                EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'),
122
-                EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'),
123
-                EEM_Question::QST_type_email => __('Email', 'event_espresso'),
124
-                EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'),
125
-                EEM_Question::QST_type_decimal => __('Number', 'event_espresso'),
126
-                EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'),
127
-                EEM_Question::QST_type_url => __('URL', 'event_espresso'),
128
-                EEM_Question::QST_type_year => __('Year', 'event_espresso'),
129
-                EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso')
130
-            )
131
-        );
132
-        $this->_question_descriptions = apply_filters(
133
-            'FHEE__EEM_Question__construct__allowed_question_types',
134
-            array(
135
-                EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'),
136
-                EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'),
137
-                EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'),
138
-                EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'),
139
-                EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'),
140
-                EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'),
141
-                EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'),
142
-                EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'),
143
-                EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'),
144
-                EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'),
145
-                EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'),
146
-                EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'),
147
-                EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'),
148
-                EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'),
149
-                EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'),
150
-                EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso')
151
-            )
152
-        );
153
-        $this->_question_type_categories = (array)apply_filters(
154
-            'FHEE__EEM_Question__construct__question_type_categories',
155
-            array(
156
-                'text' => array(
157
-                    EEM_Question::QST_type_text,
158
-                    EEM_Question::QST_type_textarea,
159
-                    EEM_Question::QST_type_date,
160
-                    EEM_Question::QST_type_html_textarea,
161
-                    EEM_Question::QST_type_email,
162
-                    EEM_Question::QST_type_us_phone,
163
-                    EEM_Question::QST_type_decimal,
164
-                    EEM_Question::QST_type_int,
165
-                    EEM_Question::QST_type_url,
166
-                    EEM_Question::QST_type_year
167
-                ),
168
-                'single-answer-enum' => array(
169
-                    EEM_Question::QST_type_radio,
170
-                    EEM_Question::QST_type_dropdown
171
-                ),
172
-                'multi-answer-enum' => array(
173
-                    EEM_Question::QST_type_checkbox,
174
-                    EEM_Question::QST_type_multi_select
175
-                )
176
-            )
177
-        );
178
-
179
-        $this->_tables = array(
180
-            'Question' => new EE_Primary_Table('esp_question', 'QST_ID')
181
-        );
182
-        $this->_fields = array(
183
-            'Question' => array(
184
-                'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')),
185
-                'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''),
186
-                'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''),
187
-                'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''),
188
-                'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types),
189
-                'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false),
190
-                'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''),
191
-                'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0),
192
-                'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false),
193
-                'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF),
194
-                'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false),
195
-                'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false)
196
-            )
197
-        );
198
-        $this->_model_relations = array(
199
-            'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'),
200
-            'Question_Option' => new EE_Has_Many_Relation(),
201
-            'Answer' => new EE_Has_Many_Relation(),
202
-            'WP_User' => new EE_Belongs_To_Relation(),
203
-            //for QST_order column
204
-            'Question_Group_Question' => new EE_Has_Many_Relation()
205
-        );
206
-        //this model is generally available for reading
207
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
208
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system');
209
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system');
210
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system');
211
-        parent::__construct($timezone);
212
-    }
213
-
214
-    /**
215
-     * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE'
216
-     * but they can be extended
217
-     * @return string[]
218
-     */
219
-    public function allowed_question_types()
220
-    {
221
-        return $this->_allowed_question_types;
222
-    }
223
-
224
-    /**
225
-     * Gets all the question types in the same category
226
-     * @param string $question_type one of EEM_Question::allowed_question_types(
227
-     * @return string[] like EEM_Question::allowed_question_types()
228
-     */
229
-    public function question_types_in_same_category($question_type)
230
-    {
231
-        $question_types = array($question_type);
232
-        foreach ($this->_question_type_categories as $category => $question_types_in_category) {
233
-            if (in_array($question_type, $question_types_in_category)) {
234
-                $question_types = $question_types_in_category;
235
-                break;
236
-            }
237
-        }
238
-
239
-        return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
240
-    }
241
-
242
-    /**
243
-     * Determines if the given question type is in the given question type category
244
-     * @param string $question_type one of EEM_Question::allowed_question_types()
245
-     * @param string $category one of the top-level keys of EEM_Question::question_type_categories()
246
-     * @return boolean
247
-     */
248
-    public function question_type_is_in_category($question_type, $category)
249
-    {
250
-        if (!isset($this->_question_type_categories[$category])) {
251
-            return false;
252
-        }
253
-        return in_array($question_type, $this->_question_type_categories[$category]);
254
-    }
255
-
256
-
257
-    /**
258
-     * Returns all the question types in the given category
259
-     * @param string $category
260
-     * @return array|mixed
261
-     */
262
-    public function question_types_in_category($category)
263
-    {
264
-        if (isset($this->_question_type_categories[$category])) {
265
-            return $this->_question_type_categories[$category];
266
-        }
267
-        return array();
268
-    }
269
-
270
-
271
-    /**
272
-     * Returns all the question types that should have question options
273
-     * @return array
274
-     */
275
-    public function question_types_with_options()
276
-    {
277
-        return array_merge(
278
-            $this->question_types_in_category('single-answer-enum'),
279
-            $this->question_types_in_category('multi-answer-enum')
280
-        );
281
-    }
282
-
283
-    /**
284
-     * Returns the question type categories 2d array
285
-     * @return array see EEM_Question::_question_type_categories
286
-     */
287
-    public function question_type_categories()
288
-    {
289
-        return $this->_question_type_categories;
290
-    }
291
-
292
-    /**
293
-     * Returns an array of all the QST_system values that can be allowed in the system question group
294
-     * identified by $system_question_group_id
295
-     * @param string $system_question_group_id QSG_system
296
-     * @return array of system question names (QST_system)
297
-     */
298
-    public function allowed_system_questions_in_system_question_group($system_question_group_id)
299
-    {
300
-        $question_system_ids = array();
301
-        switch ($system_question_group_id) {
302
-            case EEM_Question_Group::system_personal:
303
-                $question_system_ids = array(
304
-                    EEM_Attendee::system_question_fname,
305
-                    EEM_Attendee::system_question_lname,
306
-                    EEM_Attendee::system_question_email,
307
-                    EEM_Attendee::system_question_phone
308
-                );
309
-                break;
310
-            case EEM_Question_Group::system_address:
311
-                $question_system_ids = array(
312
-                    EEM_Attendee::system_question_address,
313
-                    EEM_Attendee::system_question_address2,
314
-                    EEM_Attendee::system_question_city,
315
-                    EEM_Attendee::system_question_state,
316
-                    EEM_Attendee::system_question_country,
317
-                    EEM_Attendee::system_question_zip,
318
-                    EEM_Attendee::system_question_phone
319
-                );
320
-                break;
321
-        }
322
-        return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id);
323
-    }
324
-
325
-    /**
326
-     * Returns an array of all the QST_system values that are required in the system question group
327
-     * identified by $system_question_group_id
328
-     * @param string $system_question_group_id QSG_system
329
-     * @return array of system question names (QST_system)
330
-     */
331
-    public function required_system_questions_in_system_question_group($system_question_group_id)
332
-    {
333
-        $question_system_ids = null;
334
-        switch ($system_question_group_id) {
335
-            case EEM_Question_Group::system_personal:
336
-                $question_system_ids = array(
337
-                    EEM_Attendee::system_question_fname,
338
-                    EEM_Attendee::system_question_email,
339
-                );
340
-                break;
341
-            default:
342
-                $question_system_ids = array();
343
-        }
344
-        return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id);
345
-    }
346
-
347
-
348
-    /**
349
-     * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
350
-     * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city');
351
-     * @param $QST_system
352
-     * @return int of QST_ID for the question that corresponds to that QST_system
353
-     */
354
-    public function get_Question_ID_from_system_string($QST_system)
355
-    {
356
-        return $this->get_var(array(array('QST_system' => $QST_system)));
357
-    }
358
-
359
-
360
-    /**
361
-     * searches the db for the question with the latest question order and returns that value.
362
-     * @access public
363
-     * @return int
364
-     */
365
-    public function get_latest_question_order()
366
-    {
367
-        $columns_to_select = array(
368
-            'max_order' => array("MAX(QST_order)", "%d")
369
-        );
370
-        $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select);
371
-        return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
372
-    }
373
-
374
-    /**
375
-     * Returns an array where keys are system question QST_system values,
376
-     * and values are the highest question max the admin can set on the question
377
-     * (aka the "max max"; eg, a site admin can change the zip question to have a max
378
-     * of 5, but no larger than 12)
379
-     * @return array
380
-     */
381
-    public function system_question_maxes()
382
-    {
383
-        return array(
384
-            'fname' => 45,
385
-            'lname' => 45,
386
-            'address' => 255,
387
-            'address2' => 255,
388
-            'city' => 45,
389
-            'zip' => 12,
390
-            'email' => 255,
391
-            'phone' => 45,
392
-        );
393
-    }
394
-
395
-    /**
396
-     * Given a QST_system value, gets the question's largest allowable max input.
397
-     * @see Registration_Form_Admin_Page::system_question_maxes()
398
-     * @param string $system_question_value
399
-     * @return int|float
400
-     */
401
-    public function absolute_max_for_system_question($system_question_value)
402
-    {
403
-        $maxes = $this->system_question_maxes();
404
-        if (isset($maxes[$system_question_value])) {
405
-            return $maxes[$system_question_value];
406
-        } else {
407
-            return EE_INF;
408
-        }
409
-    }
410
-
411
-
412
-    /**
413
-     * @return array
414
-     */
415
-    public function question_descriptions()
416
-    {
417
-        return $this->_question_descriptions;
418
-    }
19
+	// constant used to indicate that the question type is COUNTRY
20
+	const QST_type_country = 'COUNTRY';
21
+
22
+	// constant used to indicate that the question type is DATE
23
+	const QST_type_date = 'DATE';
24
+
25
+	// constant used to indicate that the question type is DROPDOWN
26
+	const QST_type_dropdown = 'DROPDOWN';
27
+
28
+	// constant used to indicate that the question type is CHECKBOX
29
+	const QST_type_checkbox = 'CHECKBOX';
30
+
31
+	// constant used to indicate that the question type is RADIO_BTN
32
+	const QST_type_radio = 'RADIO_BTN';
33
+
34
+	// constant used to indicate that the question type is STATE
35
+	const QST_type_state = 'STATE';
36
+
37
+	// constant used to indicate that the question type is TEXT
38
+	const QST_type_text = 'TEXT';
39
+
40
+	// constant used to indicate that the question type is TEXTAREA
41
+	const QST_type_textarea = 'TEXTAREA';
42
+
43
+	// constant used to indicate that the question type is a TEXTAREA that allows simple html
44
+	const QST_type_html_textarea = 'HTML_TEXTAREA';
45
+
46
+	// constant used to indicate that the question type is an email input
47
+	const QST_type_email = 'EMAIL';
48
+
49
+	// constant used to indicate that the question type is a US-formatted phone number
50
+	const QST_type_us_phone = 'US_PHONE';
51
+
52
+	// constant used to indicate that the question type is an integer (whole number)
53
+	const QST_type_int = 'INTEGER';
54
+
55
+	// constant used to indicate that the question type is a decimal (float)
56
+	const QST_type_decimal = 'DECIMAL';
57
+
58
+	// constant used to indicate that the question type is a valid URL
59
+	const QST_type_url = 'URL';
60
+
61
+	// constant used to indicate that the question type is a YEAR
62
+	const QST_type_year = 'YEAR';
63
+
64
+	// constant used to indicate that the question type is a multi-select
65
+	const QST_type_multi_select = 'MULTI_SELECT';
66
+
67
+	/**
68
+	 * Question types that are interchangeable, even after answers have been provided for them.
69
+	 * Top-level keys are category slugs, next level is an array of question types. If question types
70
+	 * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
71
+	 *
72
+	 * @access protected
73
+	 * @var array $_question_type_categories {
74
+	 * @type string $text
75
+	 * @type string $single -answer-enum
76
+	 * @type string $multi -answer-enum
77
+	 *                    }
78
+	 */
79
+	protected $_question_type_categories = array();
80
+
81
+	/**
82
+	 * lists all the question types which should be allowed. Ideally, this will be extensible.
83
+	 *
84
+	 * @access protected
85
+	 * @var array $_allowed_question_types
86
+	 */
87
+	protected $_allowed_question_types = array();
88
+
89
+	/**
90
+	 * brief descriptions for all the question types
91
+	 *
92
+	 * @access protected
93
+	 * @var EEM_Question $_instance
94
+	 */
95
+	protected $_question_descriptions;
96
+
97
+
98
+	// private instance of the Attendee object
99
+	protected static $_instance = NULL;
100
+
101
+
102
+	/**
103
+	 * EEM_Question constructor.
104
+	 *
105
+	 * @param null $timezone
106
+	 */
107
+	protected function __construct($timezone = NULL)
108
+	{
109
+		$this->singular_item = __('Question', 'event_espresso');
110
+		$this->plural_item = __('Questions', 'event_espresso');
111
+		$this->_allowed_question_types = apply_filters(
112
+			'FHEE__EEM_Question__construct__allowed_question_types',
113
+			array(
114
+				EEM_Question::QST_type_text => __('Text', 'event_espresso'),
115
+				EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'),
116
+				EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'),
117
+				EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'),
118
+				EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'),
119
+				EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'),
120
+				EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'),
121
+				EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'),
122
+				EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'),
123
+				EEM_Question::QST_type_email => __('Email', 'event_espresso'),
124
+				EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'),
125
+				EEM_Question::QST_type_decimal => __('Number', 'event_espresso'),
126
+				EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'),
127
+				EEM_Question::QST_type_url => __('URL', 'event_espresso'),
128
+				EEM_Question::QST_type_year => __('Year', 'event_espresso'),
129
+				EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso')
130
+			)
131
+		);
132
+		$this->_question_descriptions = apply_filters(
133
+			'FHEE__EEM_Question__construct__allowed_question_types',
134
+			array(
135
+				EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'),
136
+				EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'),
137
+				EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'),
138
+				EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'),
139
+				EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'),
140
+				EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'),
141
+				EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'),
142
+				EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'),
143
+				EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'),
144
+				EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'),
145
+				EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'),
146
+				EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'),
147
+				EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'),
148
+				EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'),
149
+				EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'),
150
+				EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso')
151
+			)
152
+		);
153
+		$this->_question_type_categories = (array)apply_filters(
154
+			'FHEE__EEM_Question__construct__question_type_categories',
155
+			array(
156
+				'text' => array(
157
+					EEM_Question::QST_type_text,
158
+					EEM_Question::QST_type_textarea,
159
+					EEM_Question::QST_type_date,
160
+					EEM_Question::QST_type_html_textarea,
161
+					EEM_Question::QST_type_email,
162
+					EEM_Question::QST_type_us_phone,
163
+					EEM_Question::QST_type_decimal,
164
+					EEM_Question::QST_type_int,
165
+					EEM_Question::QST_type_url,
166
+					EEM_Question::QST_type_year
167
+				),
168
+				'single-answer-enum' => array(
169
+					EEM_Question::QST_type_radio,
170
+					EEM_Question::QST_type_dropdown
171
+				),
172
+				'multi-answer-enum' => array(
173
+					EEM_Question::QST_type_checkbox,
174
+					EEM_Question::QST_type_multi_select
175
+				)
176
+			)
177
+		);
178
+
179
+		$this->_tables = array(
180
+			'Question' => new EE_Primary_Table('esp_question', 'QST_ID')
181
+		);
182
+		$this->_fields = array(
183
+			'Question' => array(
184
+				'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')),
185
+				'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''),
186
+				'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''),
187
+				'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''),
188
+				'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types),
189
+				'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false),
190
+				'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''),
191
+				'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0),
192
+				'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false),
193
+				'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF),
194
+				'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false),
195
+				'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false)
196
+			)
197
+		);
198
+		$this->_model_relations = array(
199
+			'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'),
200
+			'Question_Option' => new EE_Has_Many_Relation(),
201
+			'Answer' => new EE_Has_Many_Relation(),
202
+			'WP_User' => new EE_Belongs_To_Relation(),
203
+			//for QST_order column
204
+			'Question_Group_Question' => new EE_Has_Many_Relation()
205
+		);
206
+		//this model is generally available for reading
207
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
208
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system');
209
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system');
210
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system');
211
+		parent::__construct($timezone);
212
+	}
213
+
214
+	/**
215
+	 * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE'
216
+	 * but they can be extended
217
+	 * @return string[]
218
+	 */
219
+	public function allowed_question_types()
220
+	{
221
+		return $this->_allowed_question_types;
222
+	}
223
+
224
+	/**
225
+	 * Gets all the question types in the same category
226
+	 * @param string $question_type one of EEM_Question::allowed_question_types(
227
+	 * @return string[] like EEM_Question::allowed_question_types()
228
+	 */
229
+	public function question_types_in_same_category($question_type)
230
+	{
231
+		$question_types = array($question_type);
232
+		foreach ($this->_question_type_categories as $category => $question_types_in_category) {
233
+			if (in_array($question_type, $question_types_in_category)) {
234
+				$question_types = $question_types_in_category;
235
+				break;
236
+			}
237
+		}
238
+
239
+		return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
240
+	}
241
+
242
+	/**
243
+	 * Determines if the given question type is in the given question type category
244
+	 * @param string $question_type one of EEM_Question::allowed_question_types()
245
+	 * @param string $category one of the top-level keys of EEM_Question::question_type_categories()
246
+	 * @return boolean
247
+	 */
248
+	public function question_type_is_in_category($question_type, $category)
249
+	{
250
+		if (!isset($this->_question_type_categories[$category])) {
251
+			return false;
252
+		}
253
+		return in_array($question_type, $this->_question_type_categories[$category]);
254
+	}
255
+
256
+
257
+	/**
258
+	 * Returns all the question types in the given category
259
+	 * @param string $category
260
+	 * @return array|mixed
261
+	 */
262
+	public function question_types_in_category($category)
263
+	{
264
+		if (isset($this->_question_type_categories[$category])) {
265
+			return $this->_question_type_categories[$category];
266
+		}
267
+		return array();
268
+	}
269
+
270
+
271
+	/**
272
+	 * Returns all the question types that should have question options
273
+	 * @return array
274
+	 */
275
+	public function question_types_with_options()
276
+	{
277
+		return array_merge(
278
+			$this->question_types_in_category('single-answer-enum'),
279
+			$this->question_types_in_category('multi-answer-enum')
280
+		);
281
+	}
282
+
283
+	/**
284
+	 * Returns the question type categories 2d array
285
+	 * @return array see EEM_Question::_question_type_categories
286
+	 */
287
+	public function question_type_categories()
288
+	{
289
+		return $this->_question_type_categories;
290
+	}
291
+
292
+	/**
293
+	 * Returns an array of all the QST_system values that can be allowed in the system question group
294
+	 * identified by $system_question_group_id
295
+	 * @param string $system_question_group_id QSG_system
296
+	 * @return array of system question names (QST_system)
297
+	 */
298
+	public function allowed_system_questions_in_system_question_group($system_question_group_id)
299
+	{
300
+		$question_system_ids = array();
301
+		switch ($system_question_group_id) {
302
+			case EEM_Question_Group::system_personal:
303
+				$question_system_ids = array(
304
+					EEM_Attendee::system_question_fname,
305
+					EEM_Attendee::system_question_lname,
306
+					EEM_Attendee::system_question_email,
307
+					EEM_Attendee::system_question_phone
308
+				);
309
+				break;
310
+			case EEM_Question_Group::system_address:
311
+				$question_system_ids = array(
312
+					EEM_Attendee::system_question_address,
313
+					EEM_Attendee::system_question_address2,
314
+					EEM_Attendee::system_question_city,
315
+					EEM_Attendee::system_question_state,
316
+					EEM_Attendee::system_question_country,
317
+					EEM_Attendee::system_question_zip,
318
+					EEM_Attendee::system_question_phone
319
+				);
320
+				break;
321
+		}
322
+		return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id);
323
+	}
324
+
325
+	/**
326
+	 * Returns an array of all the QST_system values that are required in the system question group
327
+	 * identified by $system_question_group_id
328
+	 * @param string $system_question_group_id QSG_system
329
+	 * @return array of system question names (QST_system)
330
+	 */
331
+	public function required_system_questions_in_system_question_group($system_question_group_id)
332
+	{
333
+		$question_system_ids = null;
334
+		switch ($system_question_group_id) {
335
+			case EEM_Question_Group::system_personal:
336
+				$question_system_ids = array(
337
+					EEM_Attendee::system_question_fname,
338
+					EEM_Attendee::system_question_email,
339
+				);
340
+				break;
341
+			default:
342
+				$question_system_ids = array();
343
+		}
344
+		return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id);
345
+	}
346
+
347
+
348
+	/**
349
+	 * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
350
+	 * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city');
351
+	 * @param $QST_system
352
+	 * @return int of QST_ID for the question that corresponds to that QST_system
353
+	 */
354
+	public function get_Question_ID_from_system_string($QST_system)
355
+	{
356
+		return $this->get_var(array(array('QST_system' => $QST_system)));
357
+	}
358
+
359
+
360
+	/**
361
+	 * searches the db for the question with the latest question order and returns that value.
362
+	 * @access public
363
+	 * @return int
364
+	 */
365
+	public function get_latest_question_order()
366
+	{
367
+		$columns_to_select = array(
368
+			'max_order' => array("MAX(QST_order)", "%d")
369
+		);
370
+		$max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select);
371
+		return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
372
+	}
373
+
374
+	/**
375
+	 * Returns an array where keys are system question QST_system values,
376
+	 * and values are the highest question max the admin can set on the question
377
+	 * (aka the "max max"; eg, a site admin can change the zip question to have a max
378
+	 * of 5, but no larger than 12)
379
+	 * @return array
380
+	 */
381
+	public function system_question_maxes()
382
+	{
383
+		return array(
384
+			'fname' => 45,
385
+			'lname' => 45,
386
+			'address' => 255,
387
+			'address2' => 255,
388
+			'city' => 45,
389
+			'zip' => 12,
390
+			'email' => 255,
391
+			'phone' => 45,
392
+		);
393
+	}
394
+
395
+	/**
396
+	 * Given a QST_system value, gets the question's largest allowable max input.
397
+	 * @see Registration_Form_Admin_Page::system_question_maxes()
398
+	 * @param string $system_question_value
399
+	 * @return int|float
400
+	 */
401
+	public function absolute_max_for_system_question($system_question_value)
402
+	{
403
+		$maxes = $this->system_question_maxes();
404
+		if (isset($maxes[$system_question_value])) {
405
+			return $maxes[$system_question_value];
406
+		} else {
407
+			return EE_INF;
408
+		}
409
+	}
410
+
411
+
412
+	/**
413
+	 * @return array
414
+	 */
415
+	public function question_descriptions()
416
+	{
417
+		return $this->_question_descriptions;
418
+	}
419 419
 
420 420
 
421 421
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if (!defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4
-require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php');
5
-require_once(EE_CLASSES . 'EE_Question.class.php');
4
+require_once(EE_MODELS.'EEM_Soft_Delete_Base.model.php');
5
+require_once(EE_CLASSES.'EE_Question.class.php');
6 6
 
7 7
 
8 8
 /**
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
                 EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso')
151 151
             )
152 152
         );
153
-        $this->_question_type_categories = (array)apply_filters(
153
+        $this->_question_type_categories = (array) apply_filters(
154 154
             'FHEE__EEM_Question__construct__question_type_categories',
155 155
             array(
156 156
                 'text' => array(
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function question_type_is_in_category($question_type, $category)
249 249
     {
250
-        if (!isset($this->_question_type_categories[$category])) {
250
+        if ( ! isset($this->_question_type_categories[$category])) {
251 251
             return false;
252 252
         }
253 253
         return in_array($question_type, $this->_question_type_categories[$category]);
Please login to merge, or discard this patch.
core/db_models/fields/EE_Float_Field.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
      * @param string $table_column
12 12
      * @param string $nicename
13 13
      * @param bool   $nullable
14
-     * @param null   $default_value
14
+     * @param integer|null   $default_value
15 15
      */
16 16
     public function __construct($table_column, $nicename, $nullable, $default_value = null)
17 17
     {
Please login to merge, or discard this patch.
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -8,60 +8,60 @@
 block discarded – undo
8 8
 class EE_Float_Field extends EE_Model_Field_Base
9 9
 {
10 10
 
11
-    /**
12
-     * @param string $table_column
13
-     * @param string $nicename
14
-     * @param bool   $nullable
15
-     * @param null   $default_value
16
-     */
17
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
-    {
19
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
20
-        $this->setSchemaType('number');
21
-    }
11
+	/**
12
+	 * @param string $table_column
13
+	 * @param string $nicename
14
+	 * @param bool   $nullable
15
+	 * @param null   $default_value
16
+	 */
17
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
+	{
19
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
20
+		$this->setSchemaType('number');
21
+	}
22 22
 
23 23
 
24
-    /**
25
-     * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc.
26
-     * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency.
27
-     * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
28
-     * Returns a float
29
-     *
30
-     * @param string|float|int $value_inputted_for_field_on_model_object
31
-     * @return float
32
-     */
33
-    function prepare_for_set($value_inputted_for_field_on_model_object)
34
-    {
35
-        //remove whitespaces and thousands separators
36
-        if (is_string($value_inputted_for_field_on_model_object)) {
37
-            $value_inputted_for_field_on_model_object = str_replace(array(" ", EE_Config::instance()->currency->thsnds),
38
-                "", $value_inputted_for_field_on_model_object);
39
-            //normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now)
40
-            $value_inputted_for_field_on_model_object = str_replace(EE_Config::instance()->currency->dec_mrk, ".",
41
-                $value_inputted_for_field_on_model_object);
42
-            //double-check there's absolutely nothing left on this string besides numbers
43
-            $value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "",
44
-                $value_inputted_for_field_on_model_object);
45
-        }
46
-        return (float)$value_inputted_for_field_on_model_object;
47
-    }
24
+	/**
25
+	 * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc.
26
+	 * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency.
27
+	 * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
28
+	 * Returns a float
29
+	 *
30
+	 * @param string|float|int $value_inputted_for_field_on_model_object
31
+	 * @return float
32
+	 */
33
+	function prepare_for_set($value_inputted_for_field_on_model_object)
34
+	{
35
+		//remove whitespaces and thousands separators
36
+		if (is_string($value_inputted_for_field_on_model_object)) {
37
+			$value_inputted_for_field_on_model_object = str_replace(array(" ", EE_Config::instance()->currency->thsnds),
38
+				"", $value_inputted_for_field_on_model_object);
39
+			//normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now)
40
+			$value_inputted_for_field_on_model_object = str_replace(EE_Config::instance()->currency->dec_mrk, ".",
41
+				$value_inputted_for_field_on_model_object);
42
+			//double-check there's absolutely nothing left on this string besides numbers
43
+			$value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "",
44
+				$value_inputted_for_field_on_model_object);
45
+		}
46
+		return (float)$value_inputted_for_field_on_model_object;
47
+	}
48 48
 
49
-    /**
50
-     * Returns the number formatted according to local custom (set by the country of the blog).
51
-     *
52
-     * @param float $value_on_field_to_be_outputted
53
-     * @return string
54
-     */
55
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
56
-    {
57
-        $EE = EE_Registry::instance();
58
-        return number_format($value_on_field_to_be_outputted, $EE->CFG->currency->dec_plc, $EE->CFG->currency->dec_mrk,
59
-            $EE->CFG->currency->thsnds);
60
-    }
49
+	/**
50
+	 * Returns the number formatted according to local custom (set by the country of the blog).
51
+	 *
52
+	 * @param float $value_on_field_to_be_outputted
53
+	 * @return string
54
+	 */
55
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
56
+	{
57
+		$EE = EE_Registry::instance();
58
+		return number_format($value_on_field_to_be_outputted, $EE->CFG->currency->dec_plc, $EE->CFG->currency->dec_mrk,
59
+			$EE->CFG->currency->thsnds);
60
+	}
61 61
 
62
-    function prepare_for_set_from_db($value_found_in_db_for_model_object)
63
-    {
62
+	function prepare_for_set_from_db($value_found_in_db_for_model_object)
63
+	{
64 64
 //		echo "prepare for set from db of ";d($value_found_in_db_for_model_object);
65
-        return floatval($value_found_in_db_for_model_object);
66
-    }
65
+		return floatval($value_found_in_db_for_model_object);
66
+	}
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
             $value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "",
44 44
                 $value_inputted_for_field_on_model_object);
45 45
         }
46
-        return (float)$value_inputted_for_field_on_model_object;
46
+        return (float) $value_inputted_for_field_on_model_object;
47 47
     }
48 48
 
49 49
     /**
Please login to merge, or discard this patch.