DonationCoder.com Forum

DonationCoder.com Software => Coding Snacks => Finished Programs => Topic started by: LuckMan212 on November 03, 2005, 10:41 PM

Title: DONE - IDEA: commandline/console program to calculate sunrise/sunset times
Post by: LuckMan212 on November 03, 2005, 10:41 PM
There are some handy utils for un*x systems that can do the task of calculating sunrise/sunset/civil twilight/etc times given a latitude and longitude input.  Unfortunately I was not able to locate any win32 console apps that can do this reliably.   I found one written by an author who is no longer reachable and his contains a daylight-savings bug (DST calculation doesn't seem to work).  Daylight savings is a very important and tricky factor.

The reason I would like to have such a program is to use it in batch files to schedule home automation tasks such as turning out outside lights, controlling thermostat settings etc, based on sunrise/sunset/twilight times which change each day.

As a starting point you might consider the following URLs for assistance with the algorithms:

http://www.codeproject.com/datetime/srss.asp

http://www.freevbcode.com/ShowCode.asp?ID=341

http://xoomer.virgilio.it/vtomezzo/sunriset/formulas/index.html

there are others but that is a start...

will anyone be so kind as to create this program?? ;)  all it needs to do is output the time in 24hour hh:mm format, no fancy GUI is needed (at least for me!).  It would be good if it can accept some commandline arguments such as specifying a date manually (default would be todays date) and also the ability to output only the time you need for example just the SUNRISE time.

example:

>suntime.exe 40.734N 73.986W -time sunrise
05:39

>suntime.exe 40.734N 73.986W -time sunset
17:33

>suntime.exe 40.734N 73.986W -time twilight
16:55


etc etc...
 :Thmbsup:
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: jazper on November 04, 2005, 12:26 AM
Give this a try:


SYNTAX: suntime.exe <latitude> <longitude> -time <sunrise|sunset|moonset|moonrise|twilight>


http://www.zaboo.net/kdunlap/suntime.zip


jazper
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: mouser on November 04, 2005, 12:30 AM
jazper - care to give us some info on the programmer of the util - is it you?
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: jazper on November 04, 2005, 02:03 AM
Sorry, I wrote the app.

And I updated it as well,.

Changed:
  - Latitude needs suffix N or S for North and South
  - Longitude needs suffix E or W for East and West
  - Output time is based on local time


SYNTAX: suntime.exe <latitude[N|S]> <longitude[E|W]> -time <sunrise|sunset|moonset|moonrise|twilight>

http://www.zaboo.net/kdunlap/suntime.zip



jazper
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: mouser on November 04, 2005, 02:10 AM
wow - wonderful!  :Thmbsup:

ps.
if you're interested in setting up a little icon under your name where people can make a donation to support your coding (don't expect much if anything but still it's the principle and we want to encourage people to donate to coders), there's a link to some instructions here: https://www.donationcoder.com/forum/index.php?topic=1283.0
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: LuckMan212 on November 05, 2005, 09:15 AM
jazper- this is fantastic! I really appreciate you creating this program!! may I ask is it possible to make a few small changes?

1) the extra :00 (seconds) at the end seems to always be "00" at least in my testing.  Can this simply be dropped?  I do not need seconds calculated, minute resolution is enough. 

2) can the time be output in 24-hour (military) notation? so instead of 5:29PM can it just output 17:29 ?  If you prefer the 12hour notation then maybe add a switch like -24h or something to allow the user to choose which format to output.

3) is it possible to allow the program to calculate the sunrise/sunset times of any arbitrary date, not just Today's date?  example:
-suntime 40.73N 73.98W -time sunrise -date 10/30/05

also, is the program compensating for daylight savings? if yes, how does it know this? (does it read time zone from current user?)
sorry for all the questions thanks again!!! :D
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: jazper on November 16, 2005, 09:35 AM
LuckMan212,
  As requested here is a new version...

SYNTAX: suntime.exe <latitude[N|S]> <longitude[E|W]> -time <sunrise|sunset|moonset|moonrise|twilight> [-24hr] [-date MM/DD/YYYY]


ADDED: Removed trailings seconds
ADDED: -date switch
ADDED: -24hr switch, if it exists, then output in 24hr time.

Download it here (http://jazper.dcmembers.com/downloads/suntime/suntime1.0.1.zip)


jazper
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: LuckMan212 on November 18, 2005, 11:48 PM
jazper-

thank you so much, this program is now almost 100% perfect!! :Thmbsup:
only problem is now Daylight Savings Time.
I unfortunately live in New York which is one place that observe the daylight savings time.
Which sets clock back 1hr on Last Sunday in October and then sets clock forward 1hr on First Sunday in April.
Would it be possible to add a "-dst" switch to compensate for this factor if dates are falling between this range?

you can see the effect of this by looking at the following link, for example:
(just look what happens between October 29 and Oct 30...)
http://tinyurl.com/dwyvc


thank you so much!!
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: jazper on November 20, 2005, 11:47 AM
ADDED: -dst switch, will compensate the output time for DST
   if -date is DST and currentdate is not, then +1 output
   else if -date is not DST and currentdate is DST then -1 output

FIXED: All cmd line switches are detected regardless of case(e.g. -date or -DATE)


Latest version HERE (http://jazper.dcmembers.com/downloads/suntime/suntime1.0.2.zip)
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: LuckMan212 on November 20, 2005, 03:35 PM
wonderful!!  :D  :Thmbsup:
this is exactly what I needed, thank you so much!
now tell me how I can donate some $ for your efforts
(https://www.donationcoder.com/forum/esmileys/gen0/Medium/you_rock.gif)
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: jazper on November 20, 2005, 07:09 PM
LuckMan212,
  Although donations personally are greatly appreciated, please put any donation that you were willing to give towards the November Fundraiser (https://www.donationcoder.com/About/fundraiser.html)


Thanks!

jazper
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: jazper on November 21, 2005, 12:48 AM
If you feel I've fulfilled your request, you may want to change the post icon to a smiley :) and the topic to DONE - <original topic>
Title: Re: IDEA: commandline/console program to calculate sunrise/sunset times
Post by: mouser on November 21, 2005, 01:03 AM
i'll change the topic and icon :)
Title: Re: DONE - IDEA: commandline/console program to calculate sunrise/sunset times
Post by: LuckMan212 on November 21, 2005, 07:24 PM
ok well thanks a lot, I have just made a donation to the November fundraiser :D, but I would still like to make a small personal donation to you jazper, just email me your paypal ID to luke.hamburg (at) gmail.com
cheers buddy :Thmbsup:

edit: and thanks mouser for updating the topic title and smiley! ;)
Title: Re: DONE - IDEA: commandline/console program to calculate sunrise/sunset times
Post by: jazper on November 22, 2005, 01:50 AM
LuckMan212,
   Here is a link to my donation (https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=kdunlap%40gmail%2ecom&item_name=jazpers%20software&amount=5%2e00&no_shipping=1&tax=0&currency_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8) info, again only donate if you want to.



jazper
Title: Re: DONE - IDEA: commandline/console program to calculate sunrise/sunset times
Post by: LuckMan212 on November 22, 2005, 11:18 AM
thanks, I just sent it  :D