Sunrise time from Ruby script is a little different from Sketchup application?

Hi, every body.

I have been trying to produce shadow of an entity with Ruby API.
But, I noticed that sunrise time got with Ruby script is a little different from Sketchup application.
For example, with the same sketchup entity, I got sunrise is 6:59 in the interface of Sketchup application and 7:00 by script based Ruby API.

Would somebody do me a favor?
Thanks.

The follows are the code:

#get model representing the Sketchup file
model = Sketchup.active_model
#get view the user are facing
view = model.active_view
#get shadow information
shadow =model.shadow_info

#City of the model
puts "My city is: " + shadow[“City”].to_s

#shadows ON
shadow[“DisplayShadows”] = true
#shadows on Faces are ON
shadow[“DisplayOnAllFaces”] = true
#shadows on Ground are ON
shadow[“DisplayOnGroundPlane”] = true

#first day to produce images is initialized with 5th Apr 2016 as a sample
firstDay = Date.new(2016,4,5)
#last day to produce images is initialized with 15th Apr 2016 as a sample
lastDay = Date.new(2016,4,15)

#get the timeZone(measured by second) to eliminate the effect by the local time
timeZoneOffsetInSecond = firstDay.to_time.utc_offset

#this showTime is just to calculate the time of sunrise instead of producing the shadow image
#this time is adjusted by the time zone(timeZoneOffsetInSecond)
shadowTimeForSunrise = Time.new(currentDay.year,currentDay.month,currentDay.day,0,0,0)
+ timeZoneOffsetInSecond
#set the shadow time
shadow[“ShadowTime”] = shadowTimeForSunrise
#get the sun rise time
sunRise = shadow[‘SunRise’] - timeZoneOffsetInSecond
#get the sun set time
sunSet = shadow[‘SunSet’] - timeZoneOffsetInSecond

sunRiseHour = sunRise.hour
sunRiseMin = sunRise.min

sunSetHour = sunSet.hour
sunSetMin = sunSet.min

puts “sunRiseHour=#{sunRise.hour},min=#{sunRiseMin},sunSetHour=#{sunSet.hour},sunSetMin=#{sunSetMin}”

`

You see your code is apparently hardly readable. Did you not mark it as code? Then you can edit your post, select the code and click the </> button.

Assuming you require "date" in SketchUp with ruby >= 2.0…

In which part of the UI did you check the time?
Can you share an (empty) SketchUp file with the location/time settings?

1 Like

As Aerilius mentions, please ensure the code blocks are formatted to be readable.

#get model representing the Sketchup file
model =  Sketchup.active_model
#get view the user are facing
view  = model.active_view
#get shadow information
shadow =model.shadow_info

#City of the model
puts "My city is: " + shadow["City"].to_s

#shadows ON
shadow["DisplayShadows"] = true
#shadows on Faces are ON
shadow["DisplayOnAllFaces"] = true
#shadows on Ground are ON
shadow["DisplayOnGroundPlane"] = true

#first day to produce images is initialized with 5th Apr 2016 as a sample
firstDay = Date.new(2016,4,5)
#last day to produce images is initialized with 15th Apr 2016 as a sample
lastDay = Date.new(2016,4,15)

#get the timeZone(measured by second) to eliminate the effect by the local time
timeZoneOffsetInSecond=firstDay.to_time.utc_offset

#interval days of the succesive images
interval = 1
#fulfil all the images production
for currentDay in (firstDay..lastDay).step(interval)
 
  #this showTime is just to calculate the time of sunrise instead of producing the shadow image
  #this time is adjusted by the time zone(timeZoneOffsetInSecond)
  shadowTimeForSunrise = Time.new(currentDay.year,currentDay.month,currentDay.day,0,0,0) 
						+ timeZoneOffsetInSecond   						
  
  #set the shadow time
  shadow["ShadowTime"] = shadowTimeForSunrise
  #get the sun rise time
  sunRise = shadow['SunRise'] - timeZoneOffsetInSecond
  #get the sun set time
  sunSet = shadow['SunSet'] - timeZoneOffsetInSecond
	
  #puts "hour=#{hour},showTime=#{shadowTime},sunRise=#{sunRise}"
  sunRiseHour = sunRise.hour
  sunRiseMin = sunRise.min
  
  sunSetHour = sunSet.hour
  sunSetMin = sunSet.min

  puts "time=#{shadowTimeForSunrise}sunRiseHour=#{sunRise.hour},min=#{sunRiseMin},sunSetHour=#{sunSet.hour},sunSetMin=#{sunSetMin}"      

#end of the  for-loop  
end

Thanks, everybody!
2016-02-03.skp (875.0 KB)

The Sketchup file contains location information:China, +8:00.
The script runs in Melbourne, Australia, +11:00(After 5th Apr, +10:00 due to daylight saving).

I found that the sunrise time produced by Ruby API is that of the previous day shown in Sketchup UI.

I am a newbie and really confused by the time.

Thanks.

Check this link can give you a check point http://www.sunearthtools.com/solar/sunrise-sunset-calendar.php. My guess is the geo of model is China which =north lat while you state tool runs for Austria which is = south lat. Since zero is ascending node for the first point of Aries at equator does not script have to account for that more than just the utc off set??. The program will take the actual geo location and actual model ( x,y,z) and use the UTM to convert to lat and log will it not??, do same for Australia to make cal. NOA in there cal account for atmospheric bending in their time estimate?? So there is probably not one truth down to a very accurate number unless you want to use Julian time and some sat predicts :wink:

Thanks, Mac7595. I try to figure it out with your suggestion.