Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. function jeff_event_pre_submission_filter($post_data, $form, $entry ) {
  2.  
  3.     if( $form["id"] != 9 )
  4.        return $post_data;
  5.  
  6.     $time_start = strtotime( $entry[2] . ' ' . $entry[3] );
  7.  
  8.     if( $entry[9] == 'Yes') {
  9.         #is multi day
  10.         $time_end = strtotime( $entry[10] . ' ' . $entry[4] );
  11.     } else {
  12.         #one day event
  13.         $time_end = strtotime( $entry[2] . ' ' . $entry[4] );
  14.     }
  15.  
  16.     #_DURATION
  17.     $_POST['input_43'] = duration( $time_start, $time_end );
  18.  
  19.     return $post_data;
  20.  
  21. }
  22.  
  23. function duration( $start, $end ) {
  24.  
  25.     $seconds = $end - $start;
  26.  
  27.     $days = floor( $seconds / 60 / 60 / 24 );
  28.     $hours = $seconds / 60 / 60 % 24;
  29.     $mins = $seconds / 60 % 60;
  30.     $secs = $seconds % 60;
  31.  
  32.     $duration = array();
  33.  
  34.     if( $days > 0 )
  35.         $duration['days'] = $days;
  36.  
  37.     if( $hours > 0 )
  38.         $duration['hours'] = $hours;
  39.  
  40.     if( $mins > 0 )
  41.         $duration['minutes'] = $mins;
  42.  
  43.     if( count($duration) == 0 )
  44.         $duration['minutes'] = 0;
  45.  
  46.     return $duration;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement