Javascript Determine Daylight Savings Time
Posted by Scott in Web Development on October 27, 2009
1: var is_dst = function(){
2: var now = new Date();
3: var dst_start = new Date();
4: var dst_end = new Date();
5: // Set dst start to 2AM 2nd Sunday of March
6: dst_start.setMonth( 2 ); // March
7: dst_start.setDate( 1 ); // 1st
8: dst_start.setHours( 2 );
9: dst_start.setMinutes( 0 );
10: dst_start.setSeconds( 0 ); // 2AM
11: // Need to be on first Sunday
12: if( dst_start.getDay() )
13: dst_start.setDate( dst_start.getDate() + ( 7 - dst_start.getDay() ) );
14:
15: // Set to second Sunday
16: dst_start.setDate( dst_start.getDate() + 7 );
17: // Set dst end to 2AM 1st Sunday of November
18: dst_end.setMonth( 10 );
19: dst_end.setDate( 1 );
20: dst_end.setHours( 2 );
21: dst_end.setMinutes( 0 );
22: dst_end.setSeconds( 0 ); // 2AM
23: // Need to be on first Sunday
24: if( dst_end.getDay() )
25: dst_end.setDate( dst_end.getDate() + ( 7 - dst_end.getDay() ) );
26:
27: return ( now > dst_start && now < dst_end )
28: };// /is_dst()
Javascript Parse URL Function
Posted by Scott in Web Development on December 16, 2008
1:var parse_url = function (uri){
2: if (typeof uri == 'undefined') {
3: uri = location.href;
4: }
5: else if (uri[0] == '/'){
6: uri = location.host + uri;
7: }
8: var url = uri.match(/^([^:]*:\/\/)?([^:]*:[^@]*@)?([^\/:]*\.[^\/:]*)?(:[^\/]*)?(\/[^?#]*)?(\?[^#]*)?(#.*)?$/i);
9: delete url.input;
10: url.protocol = ((url[1])?url[1]:'http://').split('://')[0];
11: url.user = (url[2])?url[2].split(':')[0]:undefined;
12: url.password = (url[2])?url[2].split(':')[1].split('@')[0]:undefined;
13: url.host = (url[3])?url[3]:location.host;
14: url.hostname = url.host;
15: url.port = (url[4])?((isNaN(parseInt(url[4].split(':')[1])))?80:parseInt(url[4].split(':')[1])):80;
16: url.path = (url[5])?url[5]:'/';
17: url.pathname = url.path;
18: url.search = (url[6])?url[6].split('?')[1]:undefined;
19: url.query = url.search;
20: url.fragment = (url[7])?url[7].split('#')[1]:undefined;
21: url.hash = url.fragment;
22: url.href = ''
23: + url.protocol + '://'
24: + ((url.user)?url.user+':'+url.password+'@':'')
25: + url.host
26: + ((url.port != 80)?':'+url.port:'')
27: + url.path
28: + ((url.search)?'?'+url.search:'')
29: + ((url.fragment)?'#'+url.fragment:'');
30: return url;
31:}// /parse_url()
Book: Head First C#
I’ve had the need to learn more application programming other than just web-based scripts. So as one of my first adventures into Microsoft Visual Studio 2008, I chose C#(that’s pronounced ’see sharp’) and picked up the Head First C#. I must admit that Head First uses a very unique method of teaching, but while they claim to be “A Brain-Friendly Guide”, I found I got a headache after reading it.
Read the rest of this entry »
