Skip to main content

Algo for getting the number of days in a month

I can’t speak about what I do in office. (ok, not yet). But I need to write something. So here goes:

 

 

A “small” algo to retrieve number of days in a month. Don’t ask me it s efficiency (modulus is never fast , an alternative would be something similar to isInt function ):

 

 

/// January = 1, February = 2 and so on.

/// year will be used only if month = 2

function daysInTheMonth(var monthNumber, var yearNumber)

{

                // if February, and year is divisible by 4 but not divisible by 100, return 28. Else return 28.

                // since years which are divisible by 100 should not be leap years

                if(monthNumber == 2)  { return (yearNumber%4 ==0 && yearNumber%100>0)? 29 : 28  }

               

return (monthNumber > 7) ?  ((monthNumber%2 ==0) ? 30 : 31) : ((monthNumber%2 ==0) ? 31: 30);

 

// another option

// if(monthNumber > 7) monthNumber++;

// return ((monthNumber%2 ==0) ? 30 : 31)

 

 

}

 

 

 

Comments

Popular posts from this blog

The fight is in the open

Been busy lately and so have not managed to post for quite long. But I just had to post this. This post is dedicated to all persons who dont know anything about the fight between MS and Google: Check out the links starting from: http://news.zdnet.com/2100-9588_22-5875433.html?tag=nl.e589 There are more links as you get thru the article. Be sure to read those too. And just as a side-note: Check out " Atlas ". These are client side and server side components, which easily (??) enable you to make Web calls. This is done by encapsulating AJAX. (please dont insult by telling me that you dont know what that is).

Finally decided

I have been having these various itch since quite some time. Both about what i am doing here (where i work) and what am i meant to do. Finally, i have decided "I need a job change". I guess IT services industry was never meant to be the right industry for me. Don't get me wrong there, it's not that i wanna quit because i am not getting any interesting work, it's just that I have ideas about life which does not match with what my company is doing. (As amatter of fact, they have some really beautiful concepts which are great to work on). But i have believed web to be the future and now i have started realising that personal dreams do become quite a pain in the neck, when they are ignoired. Huh.... now that i put it on a log, i feel much better. Back to work...

Movies common for 2 actors/actresses

One question: Which all movies did both George Clooney and Brad Pitt act in? Am sure you would be going to google. And what do you do after that? See all the links, and check each and every page, trying to find the common movies. Now why could the computer not do this? Why are you spending 5 minutes trying to find this out, when you should be able to request the computer to do this..... Enter Semantic search, a mechanism where you can query data for relationships which the human mind understands, and secondly the computer understands. There are many places where they are trying to build this semantic search. I build a small application which uses freebase . And built an application where you can provide the names of 2 actors/actresses and find the movies both worked on. Check the page http://www.nlighten.in/CommonMovies.html . Details about freebase: Freebase uses the databases provided by Wikipedia and multiple other providers, and provide all the data in OOP