[Web4lib] Hours of Operation display

Laura Krier laura.krier at gmail.com
Thu Jun 10 16:52:38 EDT 2010


To those who wanted me to summarize the responses I received to my
question about writing a simple Hours of Operation "widget," here they
are. Please excuse the looooong email: I got a good number of
responses.

Courtney F sent me their simple javascript solution. This is what I
eventually chose to implement because it’s straightforward for a
newbie to figure out. I’d like to add in some error handling, if I can
figure that out. You can see it in action here:
http://library.belmont.edu/Reference/reference.html
The actual files live here: http://library.belmont.edu/libcal.js

Heather Tones White recommended using Google calendar, and either
using Google's widget or doing some API programming. I'm still
considering this option, as it might make keeping our calendar a
little easier for all of the librarians here, but I want to broach it
with other librarians first.

Molly McManus: At Millsap, they use a google calendar and PHP to
scrape the calendar for information. You can see it here:
http://library.millsaps.edu
She sent the PHP code, too, but in the interest of not being
overwhelming, I’m not reproducing it here. I can’t use PHP for this
solution, but if you’d like to, she’ll probably share the code with
you, too.

Jack Ammerman at Boston University shared their JS solution, which you
can see here: http://www.bu.edu/library/mugar/index.shtml
http://www.bu.edu/library/bi/hours/libhours.js
http://www.bu.edu/library/bi/hours/weekrange2.js

Kurt Wagner at William Paterson shared their website:
http://www.wpunj.edu/library/
Here is the script for their implementation:
<!-- date and open status script =========================== --><!--
first section actually appears second (today's date); second section
gives hours or closed status -->
	<script language="javascript">// <![CDATA[
	var mydate=new Date();
	var year=mydate.getFullYear();
	var day=mydate.getDay();
	var month=mydate.getMonth();
	var daym=mydate.getDate();
	var dayarray=new
Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var montharray=new
Array("January","February","March","April","May","June","July","August","September","October","November","December");
	
	var holidayarray=new Array("September 7","November 26","November
27","November 28","December 19","December 20","December 25","December
26","December 27","December 28","December 29","December 30","December
31","January 1","January 2","January 3","January 9","January
10","January 16","January 17","January 18","February 15","April
2","April 3","April 4","May 21","May 22","May 23","May 28","May
29","May 30","May 31","June 6","June 11","June 13","June 18","June
20","June 25","June 27","July 2","July 3","July 4","July 5","July
11","July 16","July 18","July 23","July 25","July 30","August 1");
	var rx=new RegExp(montharray[month]+" "+daym+";","i");
	var ex_day=(rx.test(holidayarray.join(";")+";"))?7:day;
	
	var hourarray=new Array(
	"&nbsp;&nbsp;<font size='-1' color='#009900'>Library is closed
</font><font size='-1' color='#000000'>online services
available</B></font>",
	"&nbsp;&nbsp;<font size='-1' color='#009900'>Open today </font><font
size='-1' color='#000000'>from 7:45am&nbsp;to&nbsp;10pm</font>",
	"&nbsp;&nbsp;<font size='-1' color='#009900'>Open today </font><font
size='-1' color='#000000'>from 7:45am&nbsp;to&nbsp;10pm</font>",
	"&nbsp;&nbsp;<font size='-1' color='#009900'>Open today </font><font
size='-1' color='#000000'>from 7:45am&nbsp;to&nbsp;10pm</font>",
	"&nbsp;&nbsp;<font size='-1' color='#009900'>Open today </font><font
size='-1' color='#000000'>from 7:45am&nbsp;to&nbsp;10pm</font>",
	"&nbsp;&nbsp;<font size='-1' color='#FF0000'>Closed today
</font><font size='-1' color='#000000'>-Web Services
Available</font>",
	"&nbsp;&nbsp;<font size='-1' color='#009900'>Open today </font><font
size='-1' color='#000000'>from 10:00am&nbsp;to&nbsp;4:00pm</font>",
	"&nbsp;&nbsp;<font size='-1' color='#FF0000'><B>Closed Today
</font><font size='-2' color='#000000'>-Web Services
Available</a></B></font>");
	document.write("<font face='Arial'
size=-2><B>"+hourarray[ex_day]+"&nbsp;&nbsp;&nbsp;<font
color='#000000'>"+dayarray[day]+", "+montharray[month]+" "+daym+",
"+year+"<br><font color='#000000' face='Arial'></B>");
	// ]]></script>
	<!-- The day hours are in order: Sunday through Saturday, so set the
hours according to that order. The last day is the Closed message
--></td>

Nina McHale and U Colorado shared their simple JS solution, which is here:
http://library.auraria.edu/js/timestamp.js
Our hours are pretty complicated, so I wasn’t able to use this.

Peggy Shaughnessy sent this simple ColdFusion solution:
<cfset today = Now()>

<cfif #dateformat(today, dddd)# is 'Sunday'>
Hours:
Sunday hours
<cfelseif #dateformat(today, dddd)# is Monday'>
Hours:
Monday hours
<cfelse>
Hours:
Tuesday hours
</cfif>

Again, our hours are super complicated, so this wouldn’t work for us.

Thanks to everyone who responded, again! It really helps me to see all
of these different ways to accomplish the same thing. I'm hoping
working with this will increase my JS skills a little more. Right now
they are pretty limited. :-)

Hope this is helpful to others of you lot,

laura


On Wed, Jun 9, 2010 at 1:03 PM, Laura Krier <laura.krier at gmail.com> wrote:
> Howdy folks,
> I'm feeling particularly stumped by this problem: I want to display a
> simple box on our library website that, based on today's date, will
> display the hours that we're open. Our website is built on ColdFusion,
> so I'm looking for a solution that utilizes that, or javascript. You'd
> think this would be a simple thing to do, but I'm even having a hard
> time formulating a search query that pulls up anything useful.
>
> I'm fairly new to javascript and VERY new to CF, so the simpler the
> solution, the better.
>
> Thanks in advice for any advice anyone can offer,
>
> Laura
>
> --
> Laura Krier
>
> http://www.lauraek.net
> http://kitchenilliterate.wordpress.com
>



-- 
Laura Krier

http://www.lauraek.net
http://kitchenilliterate.wordpress.com




More information about the Web4lib mailing list