example/sunriset.rb in calc_sun-0.1.1 vs example/sunriset.rb in calc_sun-1.2.6

- old
+ new

@@ -1,35 +1,23 @@ -require 'benchmark' +#!/usr/bin/env ruby + lib = File.expand_path('../../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + +lat = 39.742476 +lon = -105.1786 + require 'calc_sun' cs = CalcSun.new -require 'date' -DJ00 = DateTime.parse('2000-01-01T12:00:00').jd +# require 'date' is included in CalcSun class +ajd = DateTime.new(2003, 10, 17, 12, 30, 30).ajd.to_f +puts cs.ajd2dt(ajd) -lat = 41.95 -lon = -88.75 -day = Date.parse('2016-12-25') -jd = day.jd - DJ00 - lon / 360.0 -rise = cs.t_rise(jd, lon, lat) -midday = cs.t_mid_day(jd, lon, lat) -set = cs.t_set(jd, lon, lat) +# set the date/time with #set_datetime as date and time string. +# this just creates a DateTime object and you could create your own. +day = cs.set_datetime('2003-10-17 12:30:30') +puts day -printf("\n") - -printf("\tSun rises \t\t\t : %2.0f:%02.0f UTC\n", - rise.floor, (rise % 1 * 60.0).floor) - -printf("\tSun midday \t\t\t : %2.0f:%02.0f UTC\n", - midday.floor, ((midday % 1.0) * 60).floor) - -printf("\tSun sets \t\t\t : %2.0f:%02.0f UTC\n", - set.floor, (set % 1 * 60.0).floor) - -n = 1_000_000 -puts 'running three method calls 1_000_000 times' -Benchmark.bm(7) do |x| - x.report('rise:') { n.times { ; cs.t_rise(jd, lon, lat); } } - x.report('midday:') { n.times { ; cs.t_mid_day(jd, lon, lat); } } - x.report('set:') { n.times { ; cs.t_set(jd, lon, lat); } } -end +puts "Sun rise: #{cs.rise(day.ajd, lat, lon).httpdate}" +puts "Sun noon: #{cs.noon(day.ajd, lat, lon).httpdate}" +puts "Sun set: #{cs.set(day.ajd, lat, lon).httpdate}"