<?php//--------------------------------------------------------------------------------------------------//ThisscriptreadseventdatafromaJSONfileandoutputsthoseeventswhicharewithintherange//suppliedbythe"start"and"end"GETparameters.////Anoptional"timeZone"GETparameterwillforceallISO8601datestingstoagiventimeZone.////RequiresPHP5.2.0orhigher.//--------------------------------------------------------------------------------------------------//RequireourEventclassanddatetimeutilitiesrequiredirname(__FILE__).'/utils.php';//Short-circuitiftheclientdidnotgiveusadaterange.if(!isset($_GET['start'])||!isset($_GET['end'])){die("Please provide a date range.");}//Parsethestart/endparameters.//TheseareassumedtobeISO8601stringswithnotimenortimeZone,like"2013-12-29".//SincenotimeZonewillbepresent,theywillparsedasUTC.$range_start=parseDateTime($_GET['start']);$range_end=parseDateTime($_GET['end']);//ParsethetimeZoneparameterifitispresent.$time_zone=null;if(isset($_GET['timeZone'])){$time_zone=newDateTimeZone($_GET['timeZone']);}//ReadandparseoureventsJSONfileintoanarrayofeventdataarrays.$json=file_get_contents(dirname(__FILE__).'/../json/events.json');$input_arrays=json_decode($json,true);//Accumulateanoutputarrayofeventdataarrays.$output_arrays=array();foreach($input_arraysas$array){//ConverttheinputarrayintoausefulEventobject$event=newEvent($array,$time_zone);//Iftheeventisin-bounds,addittotheoutputif($event->isWithinDayRange($range_start,$range_end)){$output_arrays[]=$event->toArray();}}//SendJSONtotheclient.echojson_encode($output_arrays);