One of the tasks I had to undertake when creating my extension, was creating a function that would adjust the date, time, and other information that I collected from my collectschedule() function.  To start with I create a variable called schedule that holds all the data created from collectschedule(), so I can easily access the data by simply calling on the variable.

var schedule = collectschedule();


Next I started work on my createcsv() function.  This function takes all the data from the variable schedule and alters it as appropriate for CSV format.  Creating a file that is CSV format, means creating a file that’s values are separated by commas (thus CSV = comma separated values).  After reading up some documentation I learned that in all CSV files meant to be imported into calendars, there is a specific format.  The first line in the file must look like this: Subject,Start Date,Start Time,End Date,End Time,All Day Event,Description,Location,Private.  Each of those sections represent information to be input into the calendar.  For many who interact with Microsoft Outlook these terms will be fairly familiar.  Continuing on with the createcsv() function:

function createcsv (schedule){

 var finalcsv = "";

 var csvfileentry = "Subject,Start Date,Start Time,End Date,End Time,All Day Event,Description,Location,Private";

 finalcsv += (csvfileentry + "\r\n");

 for (var i = 0; i < schedule.length; i += 1){

   //adjusting time from dictionary 'schedule'

   //setting date

   //….there is more code here, but I will get to that later

 }

}


In order for my createcsv() function to process, it needs to take in the schedule variable so it can adjust the data as needed.  The first order of business in this function is to create an empty string, called finalcsv.  This variable will be the actual contents of the csv file.  It needs to be in string format, as that is the format needed in a csv to make it more accessible by other programs.  

The second order is to input the first line of information that goes into the csv file.  As discussed above, that is a string that consists of: Subject,Start Date,Start Time,End Date,End Time,All Day Event,Description,Location,Private.  Here we call this variable csvfileentry.  Then we add this string to the finalcsv string variable.  We don’t enter it simply as the string listed above.  We also needed to add a couple of formatting quirks.

finalcsv += (csvfileentry + "\r\n");


We have the variable finalcsv, then use += to add this entry to the variable.  On the end we tack on “\r\n”.  This ending piece has some interesting history, but we’ll discuss it in the next entry.

Up Next Time: The history and meaning of key ‘enter’