All source code in Java/ Javascript Ask a Java/ Javascript Pro Discussion Forum Categories All jobs in Java/ Javascript
info,moon,phase,given,date
   Code/Articles � |  Newest/Best � |  Community � |  Jobs � |  Other � |  Goto � | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Java/ Javascript Stats

 Code: 485,860. lines
 Jobs: 197. postings

 How to support the site

 
Sponsored by:
Quick Search for:  in language:    
You are in:
 
Login





Latest postings for Java/ Javascript.
Click here to see a screenshot of this code!automated glossary 2010 beta psychology 200 forced learning and memory restorer! rodlewis2010 beta!
By ROD LEWIS on 3/7

(Screen Shot)

Mouseover_3Imag e_Fader_Nav
By Mark Acuna on 3/7


Click here to see a screenshot of this code!NLabs' Folder Tree Generator
By nagesh borate on 2/28

(Screen Shot)

AI-TicTacToe
By Masood Fallahpoor on 3/4


Click here to see a screenshot of this code!Function
By Mr. SNMP Simamora on 3/4

(Screen Shot)

Click here to see a screenshot of this code!Median Number
By Mr. SNMP Simamora on 3/4

(Screen Shot)

Click here to see a screenshot of this code!Simple ppt viewer
By Rio Purwanggono on 3/3

(Screen Shot)

Click here to see a screenshot of this code!rain or snow your name or anything you want rod lewis2010 BETA
By ROD LEWIS on 3/1

(Screen Shot)

Click here to see a screenshot of this code!Simple jQuery Slideshow
By Bardhyl on 2/27

(Screen Shot)

Click here to see a screenshot of this code!Java JDBC Connection with SQL Server using Jtds Driver
By Nor Samsiah Sani on 2/24

(Screen Shot)

Click here to see a screenshot of this code!The Web Browser
By snowboardr on 2/24

(Screen Shot)

Click here to see a screenshot of this code!Font special effects filter for Adobe photo's + flash, dreamweaver MS editors beta producer 2010
By ROD LEWIS on 2/22

(Screen Shot)

Click here to see a screenshot of this code!new year
By highfinddale on 2/21

(Screen Shot)

Convex Hull
By Atishay Jain on 2/21


Click here to see a screenshot of this code!Java Upload Applet With Resume Facility
By Amit Kumar Gaur on 2/11

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

moon info

Print
Email
 
VB icon
Submitted on: 2/5/2010 9:15:52 AM
By: marcojetson  
Level: Beginner
User Rating: Unrated
Compatibility:JavaScript

Users have accessed this code 726 times.
 
(About the author)
 
     get info on moon phase for a given date
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

//**************************************
//     
// Name: moon info
// Description:get info on moon phase fo
//     r a given date
// By: marcojetson
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/vb/scripts/Sh
//     owCode.asp?txtCodeId=6576&lngWId=2//for details.//**************************************
//     

/*
* calc info about moon phase for a given date
* @author marco
*/


    function moon() {
    this.date = false;
    /*
    * date to milliseconds
    * @param str YYYY-MM-DD
    * @return int
    */


        this.strtotime = function(str) {
        var r = false, x = str.split('-');
        if (x.length === 3) r = Date.UTC(x[0], x[1], x[2]);
        return r;
    };

/* * milliseconds to date * @param str milliseconds * @return string */ this.parsedate = function(n) { var d = new Date(); d.setTime(n); return d.getFullYear()+'-'+d.getMonth()+'-'+d.getDate(); }
/* * set a property, only date at this time * @param prop date * @param val YYYY-MM-DD * @return bool */ this.set = function(prop, val) { switch (prop) { case 'date': var x = this.strtotime(val); if (x) this.date = x; }
return Boolean(this.date); }
/* * get percentage of moon phase * @return int */ this.get_phase_percent = function() { var r = false, x; if (this.date) { x = (this.date - 603240000) / 2551392000; x -= parseInt(x); r = Math.round(x * 100); }
return r; };
/* * get visibility of the moon * @return int */ this.get_visibility = function() { var r = false; if (this.date) r = (50 - Math.abs(50 - this.get_phase_percent())) * 2; return r; };
/* * get phase name * @return string */ this.get_phase_name = function() { var r = false, x; if (this.date) { x = Math.round(this.get_phase_percent() * 0.1) * 10; if (x == 0 ||x == 100) r = 'New'; else if (x > 0 && x < 25) r = 'Waxing crescent'; else if (x == 25) r = 'First quarter'; else if (x > 25 && x < 50) r = 'Waxing gibbous'; else if (x == 50) r = 'Full'; else if (x > 50 && x < 75) r = 'Waning gibbous'; else if (x == 75) r = 'Last quarter'; else if (x > 75) r = 'Waning crescent'; }
return r; };
/* * get date for next new moon * @param ts if true return as timestamp * @return mixed */ this.get_next_newmoon = function(ts) { if (typeof ts == 'undefined') ts = false; var r = false, x; if (this.date) { x = this.date + 2551392000 - (this.date - 603240000) % 2551392000; r = ts ? x : this.parsedate(x); }
return r; };
/* * get date for next full moon * @param ts if true return as timestamp * @return mixed */ this.get_next_fullmoon = function(ts) { if (typeof ts == 'undefined') ts = false; var r = false, x; if (this.date) { x = this.get_next_newmoon(true) + 1275696000; r = ts ? x : this.parsedate(x); }
return r; };
}
var moon_info = new moon(); moon_info.set('date', '2005-05-25'); document.write('<UL>'); document.write('<LI>phase percent: '+moon_info.get_phase_percent()+'%</LI>'); document.write('<LI>visibility: '+moon_info.get_visibility()+'%</LI>'); document.write('<LI>phase name: '+moon_info.get_phase_name()+'</LI>'); document.write('<LI>next new moon: '+moon_info.get_next_newmoon()+'</LI>'); document.write('<LI>next full moon: '+moon_info.get_next_fullmoon()+'</LI>'); document.write('<UL>');


Other 2 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments

 There are no comments on this submission.
 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Games | Feedback | Customize | Java/ Javascript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright� 1997-2010 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. Exhedra solutions has no affiliation with Sun Microsystems, Inc.. Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.