topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday March 19, 2024, 5:51 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE - IDEA: commandline/console program to calculate sunrise/sunset times  (Read 31528 times)

LuckMan212

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 137
    • View Profile
    • Donate to Member
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.codeproje...om/datetime/srss.asp

http://www.freevbcod.../ShowCode.asp?ID=341

http://xoomer.virgil.../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:
« Last Edit: November 21, 2005, 01:04 AM by mouser »

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • View Profile
    • Jazper's Software
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #1 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

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #2 on: November 04, 2005, 12:30 AM »
jazper - care to give us some info on the programmer of the util - is it you?

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • View Profile
    • Jazper's Software
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #3 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
« Last Edit: November 04, 2005, 02:07 AM by jazper »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #4 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.donation...dex.php?topic=1283.0

LuckMan212

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 137
    • View Profile
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #5 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

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • View Profile
    • Jazper's Software
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #6 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


jazper

LuckMan212

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 137
    • View Profile
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #7 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!!

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • View Profile
    • Jazper's Software
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #8 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

LuckMan212

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 137
    • View Profile
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #9 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

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • View Profile
    • Jazper's Software
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #10 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


Thanks!

jazper

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • View Profile
    • Jazper's Software
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #11 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>

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: commandline/console program to calculate sunrise/sunset times
« Reply #12 on: November 21, 2005, 01:03 AM »
i'll change the topic and icon :)

LuckMan212

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 137
    • View Profile
    • Donate to Member
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! ;)
« Last Edit: November 21, 2005, 09:46 PM by LuckMan212 »

jazper

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 92
    • View Profile
    • Jazper's Software
    • Donate to Member
LuckMan212,
   Here is a link to my donation info, again only donate if you want to.



jazper

LuckMan212

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 137
    • View Profile
    • Donate to Member
thanks, I just sent it  :D