예제 #1
1
// Show sunrise and sunset for first 5 days of June in LA
func ExampleSunrise() {
	var s sunrise.Sunrise

	// Start time is June 1, 2013 PST
	location, _ := time.LoadLocation("America/Los_Angeles")
	startTime := time.Date(2013, 6, 1, 0, 0, 0, 0, location)

	// Coordinates of LA are 34.05N 118.25W
	s.Around(34.05, -118.25, startTime)

	for s.Sunrise().Before(startTime) {
		s.AddDays(1)
	}

	formatStr := "Jan 2 15:04:05"
	for i := 0; i < 5; i++ {
		fmt.Printf("Sunrise: %s Sunset: %s\n", s.Sunrise().Format(formatStr), s.Sunset().Format(formatStr))
		s.AddDays(1)
	}
	// Output:
	// Sunrise: Jun 1 05:44:01 Sunset: Jun 1 20:00:42
	// Sunrise: Jun 2 05:43:45 Sunset: Jun 2 20:01:17
	// Sunrise: Jun 3 05:43:30 Sunset: Jun 3 20:01:52
	// Sunrise: Jun 4 05:43:17 Sunset: Jun 4 20:02:25
	// Sunrise: Jun 5 05:43:05 Sunset: Jun 5 20:02:57
}
예제 #2
0
func TestDarkAllDay(t *testing.T) {
	var s sunrise.Sunrise
	location, _ := time.LoadLocation("America/Los_Angeles")
	startTime := time.Date(2014, 12, 20, 0, 0, 0, 0, location)

	// Above tropic of cancer should be dark all day
	s.Around(68, -118.25, startTime)
	dayLen := s.Sunset().Sub(s.Sunrise())
	if dayLen != 0 {
		t.Errorf("Expected dark all day, but light %v", dayLen)
	}
	dayOrNight, _, _ := sunrise.DayOrNight(68, -118.25, startTime)
	if dayOrNight != sunrise.Night {
		t.Error("Expected phase to be night")
	}
}