This might be correct as using the "ShadowTime_time_t"
argument is synonymous with calling the Ruby core Time#to_i
method. (Note that the C API’s docs call it “Epoch Time” which is weird. I’ve never heard it called that anywhere else.)
Basically it returns the Integer number of seconds since the beginning of the current Epoch.
In the Ruby API …
model = Sketchup.active_model
shadowinfo = model.shadow_info
#<Sketchup::ShadowInfo:0x00021e483cb870>
t = shadowinfo["ShadowTime_time_t"]
#=> 1573219800
t.class
#=> Bignum
t.is_a?(Integer)
#=> true
In the Ruby core Time
class introduction find this …
Since Ruby 1.9.2, Time implementation uses a signed 63 bit integer, Bignum or Rational. The integer is a number of nanoseconds since the Epoch which can represent 1823-11-12 to 2116-02-20. When Bignum or Rational is used (before 1823, after 2116, under nanosecond), Time works slower as when integer is used.
At one time (no pun intended) I thought that Ruby was using the UNIX epoch …
Wikipedia:
The Unix epoch is the time 00:00:00 UTC on 1 January 1970.
And the C API also says …
SUTypedValueGetTime
…
Retrieves the time value of a typed value object.
The time value is in seconds since January 1, 1970.
This is correct. An integer number of seconds is not equal to an object that represents Time. In the Ruby API it uses the Ruby core Time
class.
I don’t see a file in the C API for time like I’d expect.
You need to call this with the typed value out from the call to SUShadowInfoGetValue
function.
I’ve got no idea how to actually get today’s date or time with the C API. It’s easy with Ruby using the Time
class.
You can do this from C if you need to. (EDIT / ADD: Something like this):
#include "ruby.h"
static int getCurrentTime() {
int t;
VALUE time = rb_eval_string("Time.now.to_i");
t = NUM2INT(time);
return t;
}
If it’s a long
instead of an int
, then use the Ruby C macro NUM2LONG
instead.
(All the numeric conversion macros are listed on pg 11 of the “Writing Ruby Extensions in C” book.)