PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/public/wp-content/plugins/the-events-calendar/vendor/tickets/common/src/functions/template-tags/date.php

https://gitlab.com/kath.de/cibedo_cibedo.de
PHP | 319 lines | 157 code | 43 blank | 119 comment | 47 complexity | d4255eb55e27b84d3f53649899173b02 MD5 | raw file
  1. <?php
  2. /**
  3. * Date Functions
  4. *
  5. * Display functions (template-tags) for use in WordPress templates.
  6. */
  7. // Don't load directly
  8. if ( ! defined( 'ABSPATH' ) ) {
  9. die( '-1' );
  10. }
  11. if ( ! class_exists( 'Tribe__Main' ) ) {
  12. return;
  13. }
  14. if ( ! function_exists( 'tribe_format_date' ) ) {
  15. /**
  16. * Formatted Date
  17. *
  18. * Returns formatted date
  19. *
  20. * @category Events
  21. * @param string $date String representing the datetime, assumed to be UTC (relevant if timezone conversion is used)
  22. * @param bool $display_time If true shows date and time, if false only shows date
  23. * @param string $date_format Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  24. *
  25. * @return string
  26. */
  27. function tribe_format_date( $date, $display_time = true, $date_format = '' ) {
  28. if ( ! Tribe__Date_Utils::is_timestamp( $date ) ) {
  29. $date = strtotime( $date );
  30. }
  31. if ( $date_format ) {
  32. $format = $date_format;
  33. } else {
  34. $date_year = date( 'Y', $date );
  35. $cur_year = date( 'Y', current_time( 'timestamp' ) );
  36. // only show the year in the date if it's not in the current year
  37. $with_year = $date_year == $cur_year ? false : true;
  38. if ( $display_time ) {
  39. $format = tribe_get_datetime_format( $with_year );
  40. } else {
  41. $format = tribe_get_date_format( $with_year );
  42. }
  43. }
  44. $date = date_i18n( $format, $date );
  45. /**
  46. * Deprecated tribe_event_formatted_date in 4.0 in favor of tribe_formatted_date. Remove in 5.0
  47. */
  48. $date = apply_filters( 'tribe_event_formatted_date', $date, $display_time, $date_format );
  49. return apply_filters( 'tribe_formatted_date', $date, $display_time, $date_format );
  50. }
  51. }//end if
  52. if ( ! function_exists( 'tribe_beginning_of_day' ) ) {
  53. /**
  54. * Returns formatted date for the official beginning of the day according to the Multi-day cutoff time option
  55. *
  56. * @category Events
  57. * @param string $date The date to find the beginning of the day, defaults to today
  58. * @param string $format Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  59. *
  60. * @return string
  61. */
  62. function tribe_beginning_of_day( $date = null, $format = 'Y-m-d H:i:s' ) {
  63. $multiday_cutoff = explode( ':', tribe_get_option( 'multiDayCutoff', '00:00' ) );
  64. $hours_to_add = $multiday_cutoff[0];
  65. $minutes_to_add = $multiday_cutoff[1];
  66. if ( is_null( $date ) || empty( $date ) ) {
  67. $date = date( $format, strtotime( date( 'Y-m-d' ) . ' +' . $hours_to_add . ' hours ' . $minutes_to_add . ' minutes' ) );
  68. } else {
  69. $date = date( $format, strtotime( date( 'Y-m-d', strtotime( $date ) ) . ' +' . $hours_to_add . ' hours ' . $minutes_to_add . ' minutes' ) );
  70. }
  71. /**
  72. * Deprecated filter tribe_event_beginning_of_day in 4.0 in favor of tribe_beginning_of_day. Remove in 5.0
  73. */
  74. $date = apply_filters( 'tribe_event_beginning_of_day', $date );
  75. /**
  76. * Filters the beginning of day date
  77. *
  78. * @param string $date
  79. */
  80. return apply_filters( 'tribe_beginning_of_day', $date );
  81. }
  82. }//end if
  83. if ( ! function_exists( 'tribe_end_of_day' ) ) {
  84. /**
  85. * Returns formatted date for the official end of the day according to the Multi-day cutoff time option
  86. *
  87. * @category Events
  88. * @param string $date The date to find the end of the day, defaults to today
  89. * @param string $format Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  90. *
  91. * @return string
  92. */
  93. function tribe_end_of_day( $date = null, $format = 'Y-m-d H:i:s' ) {
  94. $multiday_cutoff = explode( ':', tribe_get_option( 'multiDayCutoff', '00:00' ) );
  95. $hours_to_add = $multiday_cutoff[0];
  96. $minutes_to_add = $multiday_cutoff[1];
  97. if ( is_null( $date ) || empty( $date ) ) {
  98. $date = date( $format, strtotime( 'tomorrow +' . $hours_to_add . ' hours ' . $minutes_to_add . ' minutes' ) - 1 );
  99. } else {
  100. $date = date( $format, strtotime( date( 'Y-m-d', strtotime( $date ) ) . ' +1 day ' . $hours_to_add . ' hours ' . $minutes_to_add . ' minutes' ) - 1 );
  101. }
  102. /**
  103. * Deprecated filter tribe_event_end_of_day in 4.0 in favor of tribe_end_of_day. Remove in 5.0
  104. */
  105. $date = apply_filters( 'tribe_event_end_of_day', $date );
  106. /**
  107. * Filters the end of day date
  108. *
  109. * @param string $date
  110. */
  111. return apply_filters( 'tribe_end_of_day', $date );
  112. }
  113. }//end if
  114. if ( ! function_exists( 'tribe_get_datetime_separator' ) ) {
  115. /**
  116. * Get the datetime saparator from the database option with escaped characters or not ;)
  117. *
  118. * @param string $default Default Separator if it's blank on the Database
  119. * @param bool $esc If it's going to be used on a `date` function or method it needs to be escaped
  120. *
  121. * @filter tribe_datetime_separator
  122. *
  123. * @return string
  124. */
  125. function tribe_get_datetime_separator( $default = ' @ ', $esc = false ) {
  126. $separator = (string) tribe_get_option( 'dateTimeSeparator', $default );
  127. if ( $esc ) {
  128. $separator = (array) str_split( $separator );
  129. $separator = ( ! empty( $separator ) ? '\\' : '' ) . implode( '\\', $separator );
  130. }
  131. return apply_filters( 'tribe_datetime_separator', $separator );
  132. }
  133. }//end if
  134. if ( ! function_exists( 'tribe_get_start_time' ) ) {
  135. /**
  136. * Start Time
  137. *
  138. * Returns the event start time
  139. *
  140. * @category Events
  141. * @param int $event (optional)
  142. * @param string $date_format Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  143. * @param string $timezone Timezone in which to present the date/time (or default behaviour if not set)
  144. *
  145. * @return string|null Time
  146. */
  147. function tribe_get_start_time( $event = null, $date_format = '', $timezone = null ) {
  148. if ( is_null( $event ) ) {
  149. global $post;
  150. $event = $post;
  151. }
  152. if ( is_numeric( $event ) ) {
  153. $event = get_post( $event );
  154. }
  155. if ( ! is_object( $event ) ) {
  156. return;
  157. }
  158. if ( Tribe__Date_Utils::is_all_day( get_post_meta( $event->ID, '_EventAllDay', true ) ) ) {
  159. return;
  160. }
  161. // @todo move timezones to Common
  162. if ( class_exists( 'Tribe__Events__Timezones' ) ) {
  163. $start_date = Tribe__Events__Timezones::event_start_timestamp( $event->ID, $timezone );
  164. }
  165. if ( '' == $date_format ) {
  166. $date_format = tribe_get_time_format();
  167. }
  168. return tribe_format_date( $start_date, false, $date_format );
  169. }
  170. }
  171. if ( ! function_exists( 'tribe_get_end_time' ) ) {
  172. /**
  173. * End Time
  174. *
  175. * Returns the event end time
  176. *
  177. * @category Events
  178. * @param int $event (optional)
  179. * @param string $date_format Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  180. * @param string $timezone Timezone in which to present the date/time (or default behaviour if not set)
  181. *
  182. * @return string|null Time
  183. */
  184. function tribe_get_end_time( $event = null, $date_format = '', $timezone = null ) {
  185. if ( is_null( $event ) ) {
  186. global $post;
  187. $event = $post;
  188. }
  189. if ( is_numeric( $event ) ) {
  190. $event = get_post( $event );
  191. }
  192. if ( ! is_object( $event ) ) {
  193. return;
  194. }
  195. if ( Tribe__Date_Utils::is_all_day( get_post_meta( $event->ID, '_EventAllDay', true ) ) ) {
  196. return;
  197. }
  198. // @todo move timezones to Common
  199. if ( class_exists( 'Tribe__Events__Timezones' ) ) {
  200. $end_date = Tribe__Events__Timezones::event_end_timestamp( $event->ID, $timezone );
  201. }
  202. if ( '' == $date_format ) {
  203. $date_format = tribe_get_time_format();
  204. }
  205. return tribe_format_date( $end_date, false, $date_format );
  206. }
  207. }
  208. if ( ! function_exists( 'tribe_get_start_date' ) ) {
  209. /**
  210. * Start Date
  211. *
  212. * Returns the event start date and time
  213. *
  214. * @category Events
  215. * @param int $event (optional)
  216. * @param bool $display_time If true shows date and time, if false only shows date
  217. * @param string $date_format Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  218. * @param string $timezone Timezone in which to present the date/time (or default behaviour if not set)
  219. * @return string|null Date
  220. */
  221. function tribe_get_start_date( $event = null, $display_time = true, $date_format = '', $timezone = null ) {
  222. if ( is_null( $event ) ) {
  223. global $post;
  224. $event = $post;
  225. }
  226. if ( is_numeric( $event ) ) {
  227. $event = get_post( $event );
  228. }
  229. if ( ! is_object( $event ) ) {
  230. return '';
  231. }
  232. if ( Tribe__Date_Utils::is_all_day( get_post_meta( $event->ID, '_EventAllDay', true ) ) ) {
  233. $display_time = false;
  234. }
  235. // @todo move timezones to Common
  236. if ( class_exists( 'Tribe__Events__Timezones' ) ) {
  237. $start_date = Tribe__Events__Timezones::event_start_timestamp( $event->ID, $timezone );
  238. }
  239. return tribe_format_date( $start_date, $display_time, $date_format );
  240. }
  241. }
  242. if ( ! function_exists( 'tribe_get_end_date' ) ) {
  243. /**
  244. * End Date
  245. *
  246. * Returns the event end date
  247. *
  248. * @category Events
  249. * @param int $event (optional)
  250. * @param bool $display_time If true shows date and time, if false only shows date
  251. * @param string $date_format Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  252. * @param string $timezone Timezone in which to present the date/time (or default behaviour if not set)
  253. *
  254. * @return string|null Date
  255. */
  256. function tribe_get_end_date( $event = null, $display_time = true, $date_format = '', $timezone = null ) {
  257. if ( is_null( $event ) ) {
  258. global $post;
  259. $event = $post;
  260. }
  261. if ( is_numeric( $event ) ) {
  262. $event = get_post( $event );
  263. }
  264. if ( ! is_object( $event ) ) {
  265. return '';
  266. }
  267. if ( Tribe__Date_Utils::is_all_day( get_post_meta( $event->ID, '_EventAllDay', true ) ) ) {
  268. $display_time = false;
  269. }
  270. // @todo move timezones to Common
  271. if ( class_exists( 'Tribe__Events__Timezones' ) ) {
  272. $end_date = Tribe__Events__Timezones::event_end_timestamp( $event->ID, $timezone );
  273. }
  274. return tribe_format_date( $end_date, $display_time, $date_format );
  275. }
  276. }