Now that most of the minor functions, and other details have been explained I can show how my function extracts the necessary data from the schedule list of dictionaries.  The first section I will explain is the setting of the current start date and time.  To begin with I set three variables; ampm, endampm, and month.  The first two are simply empty strings to be adjusted later on in the code.  The last uses the getMonth() method.        

function createcsv (schedule){

 ...see former entry regarding this section

   //adjusting time from dictionary 'schedule'

   //setting date

   var ampm = "";

   var endampm = "";

   var month = schedule[i].datetime.getMonth() + 1;

   month = lessthanten(month);

   var date = schedule[i].datetime.getDate();

   date = lessthanten(date);

   var year = schedule[i].datetime.getFullYear().toString();

   year = year.slice(2);

   var startdate = month + "/" + date + "/" + year;

   var enddate = startdate;

   var hour = schedule[i].datetime.getHours();

   hourampm= adjusthour(hour);

   hour = lessthanten(hourampm[0]);

   …continuing with endtime, and other code bits

 }

 return finalcsv

};


The getMonth() method, explained on the Mozilla Developer Network, will extract the month listed in the datetime variable listed in the schedule function.  I access this piece of information by first identifying the location (schedule[i]), then the variable in that dictionary (datetime.), and then I apply the method and add 1 to the ending result.  Adding one to the end result is done because the months are returned from the getMonth() method from 0 to 11, with 0 equaling January.  After the month is extracted it’s then adjusted with the lessthanten() function explained in my last entry (Some simple functions to adjust my time formatting).  

After the month is set, I go through mostly the same process for the date and year information.  In the end I use the getMonth(), getDate(), and getFullYear() methods.  The first two methods are processed in almost the same way, however the year must be altered slightly.  The year variable, once collected, is 4 digits long.  For CSV formatting I need the year to only be listed as the last two digits.  To change my year variable to the last two digits, I need to slice it.  To make that adjustment to my variable I first change the year from an integer to a string using toString().  I must do this because you can’t slice an integer without first making it a string.  Then I slice my variable with this piece of code:

year = year.slice(2);


Once the year has been adjusted I combine all of my date variables into the startdate variable, which creates a date format of: 01/01/12.  Now I have to set the starttime of my soccer game.  To do this I use the getHours() method, which operates like the other get() methods listed above.  Then I adjust the hour variable with the adjusthour() and lessthanten() functions.  In the next entry I’ll be discussing the adjustments necessary to create the end time needed for csv calendar formatting.

Up Next Time: Adjusting and setting the end date and time for CSV format