title: fullCalendar UNIX timestamp conversion issues with selection event
body: <p>I'm using jQuery widgets DatePicker and Dialog to interact with fullCallendar by Adam Shaw <a href="http://arshaw.com/fullcalendar" rel="nofollow">http://arshaw.com/fullcalendar</a>. I have a lot of things working. I can use the DatePicker to jump to a specific date in fullcalendar. When I make a selection to book an event, the jQuery Dialog comes up and I use an ajax call to send the fields to a php script to process the data. </p>
  
  <p>My problem, however, comes from the UNIX timestamps used in fullcalendar's start and end variables. I set a global variable at the top of my html file, and set the start/end times from the selection in fullcalendar so that the data is passed around to the Dialog. From Dialog, I pass it to my PHP script. But when I convert that UNIX timestamp to a date in format 'YmjHis', I get weird results.</p>
  
  <p>Here is the relevant code from the "select" method in fullcalendar:</p>
  
  <pre><code>select: function(start, end, allDay) { 
          // need to check the day first. If the selected day/time &lt; today, throw an alert
          // otherwise allow the booking of the conference.
              var now = calendar.fullCalendar('getDate');
              if (start &lt; now )
              {
                  alert('You cannot book a conference in the past!');
                  calendar.fullCalendar( 'unselect' );
              }
              else
              {
                                      // set the global variables
                  st = start;
                  et = end;
  
                  $('#dialog-form').dialog('open'); // open the dialog form
              }
  
              },
  </code></pre>
  
  <p>Now, in the dialog does this (which is mostly taken directly from the jQuery UI examples page: </p>
  
  <pre><code>$( "#dialog-form" ).dialog({
          autoOpen: false,
          height: 300,
          width: 350,
          modal: true,
          buttons: {
              "Create Event": function() {
                  var bValid = true;
                  allFields.removeClass( "ui-state-error" );
  
                  bValid = bValid &amp;&amp; checkLength( name, "name", 3, 25 );
                  bValid = bValid &amp;&amp; checkLength( title, "title", 1, 20 );
                  bValid = bValid &amp;&amp; checkLength( email, "email", 6, 80 );
                  bValid = bValid &amp;&amp; checkLength( ports, "ports", 1, 2 );
  
                  bValid = bValid &amp;&amp; checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Name may consist of a-z, 0-9, underscores, begin with a letter." );
                  // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
                  // change to ensure a domain email address
                  bValid = bValid &amp;&amp; checkRegexp( email, /^((([a-z]|\d|[!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. ui@jquery.com" );
  
                  if ( bValid ) {
                      // code to insert into DB goes here
                      // need to somehow grab either a global variable or access
                      // full calendar start/end times from the selection phase
                      // in order to pass to the DB. 
                      $.ajax(
                      {
                          url: "bookings.php",
                          type: "POST",
                          data: {e: email.val(), t: title.val(), n: name.val(), p: ports.val(), start: +st, end: +et},                
                          dataType: "HTML",
                          success: function(data) {
                                  $('.result').html(data);
                                  // reload fullCalendar here maybe??
                              }
                      });
                      $( this ).dialog( "close" );
                  }
              },
              Cancel: function() {
                  $( this ).dialog( "close" );
              }
          },
          close: function() {
              allFields.val( "" ).removeClass( "ui-state-error" );
          }
      });
  </code></pre>
  
  <p>Ok, now my bookings.php file just has the following test code:</p>
  
  <pre><code>$file = 'variables.txt'; 
  $arr= $_REQUEST; 
  $fp = fopen($file, 'w') or die('Could not open file!');  
  fwrite($fp, "variables are:\n");
  foreach ($arr as $key =&gt; $value) { 
      $toFile = "Key: $key; Value: $value \n"; 
  // write to file  
  fwrite($fp, "$toFile") or die('Could not write to file'); 
  }
  
  // DEBUG CODE write some blank space
  fwrite($fp, "\n\n") or die('Could not write to file');
  $startTime = $_REQUEST['start'];
  $endTime = $_REQUEST['end'];
  
  $start = date('YmjHis', $startTime);
  fwrite($fp, "start time: $startTime = $start\n") or die('Could not write to file');
  $end = date('YmjHis', $endtime);
  fwrite($fp, "end time: $endTime = $end\n") or die('Could not write to file');
  
  // close file  
  fclose($fp);
  </code></pre>
  
  <p>When I look at my variables.txt file, I see this:</p>
  
  <pre><code>Key: e; Value: me@blah.com
  Key: t; Value: blah
  Key: n; Value: blah
  Key: p; Value: 2
  Key: start; Value: 1339610400000
  Key: end; Value: 1339617600000
  
  
  start time: 1339610400000 = 444200724160000
  end time: 1339617600000 = 19691231160000
  </code></pre>
  
  <p>What I would expect is for the start and end times to have a format like: 20120613113000, oh and not end with a 1969 date.</p>
  
  <p>So I'm obviously doing something wrong in my conversions. This is the last hurdle to a full implementation of fullCalendar to do what I need it to do, and I'm stumped. Any help is greatly appreciated.</p>