This requires you use the Astro::Sunrise package...also, replace it with your latitude and longitude!

You can also play with an online sunrise calculator here

#!/usr/bin/perl -w

use Time::localtime;
use Time::gmtime;
use Astro::Sunrise;

# Sunrise Usage:
#  ($sunrise, $sunset) = sunrise(YYYY,MM,DD,longitude,latitude,Time Zone,DST);

($sunrise, $sunset) = sunrise(   1900 + localtime->year(),
                                 localtime->mon() + 1,
                                 localtime->mday(),
                                 -122.3, 37.5,
                                 -8,                  # PST, -8 hrs from GMT
                                 localtime->isdst()); # Is Daylight savings?

print "Sunrise @ $sunrise\n";
print "Sunset @ $sunset\n";

# create 2 jobs to turn on/off lights at the right times
system("echo \"br a3 off\" | at $sunrise");
system("echo \"br a3 on\" | at $sunset");

-- MattWalsh - 31 May 2003

Topic revision: r2 - 01 Jun 2003 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback