Created
July 23, 2012 23:43
-
-
Save nathansearles/3166959 to your computer and use it in GitHub Desktop.
Get legal drinking age of user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Legal Drinking Age | |
Created by Nathan Searles <http://nathansearles.com> | |
Version: 1.0 | |
Updated: July 23rd, 2012 | |
(c) 2012 by Nathan Searles | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
*/ | |
/* | |
Example usage: | |
isLegalDrinkingAge.dateOfBirth('07/23/91'); | |
*/ | |
isLegalDrinkingAge = { | |
option: { | |
'age': 21 | |
}, | |
dateOfBirth: function( date ) { | |
if (this.legalAgeToday() <= this.calculateDays( date )) { | |
return true; | |
} else { | |
return false; | |
} | |
}, | |
legalAgeToday: function() { | |
var date = new Date(); | |
var month = date.getMonth() + 1; | |
var day = date.getDate(); | |
var year = date.getFullYear() - this.option.age; | |
return this.calculateDays( month + "/" + day + "/" + year ); | |
}, | |
dateToday: function() { | |
var date = new Date(); | |
var month = date.getMonth() + 1; | |
var day = date.getDate(); | |
var year = date.getFullYear(); | |
return month + "/" + day + "/" + year; | |
}, | |
calculateDays: function( date ) { | |
var difference = Date.parse( this.dateToday() ) - Date.parse( date ); | |
var totalDays = Math.floor( difference / 86400000 ); | |
return totalDays; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to know if there is a program I could use. Is this a web app?