Hi, David Sabine hat gesagt: // David Sabine wrote:
In any case, I don't think this object will be of any use to anybody because PD returns the following number: 1.03777e+009 (or something like it) which can't be used very reliably. I mean it works, but I can't see the seconds pass -- i can only observe the passage of time every 64 seconds or so. (What I mean is that the object will output the same number for about 64 seconds, then it outputs another number which is slightly higher.)
This has to do with the exponential display of large numbers. Depending on what you want you could make an object with outlets for the 'real' time, like outlets for struct tm { int tm_sec; /* Seconds. [0-60] (1 leap second) */ int tm_min; /* Minutes. [0-59] */ int tm_hour; /* Hours. [0-23] */ int tm_mday; /* Day. [1-31] */ int tm_mon; /* Month. [0-11] */ int tm_year; /* Year - 1900. */ int tm_wday; /* Day of week. [0-6] */ int tm_yday; /* Days in year.[0-365] */ int tm_isdst; /* DST. [-1/0/1]*/ ...
I didn't follow your problems with difftime, but I think difftime
should work as well, if you for example would start the 'clock' at
creation time:
typedef struct _epochtime {
t_object x_obj;
time_t t, starttime;
} t_epochtime;
void *epochtime_new(void)
{
t_epochtime *x = (t_epochtime *)pd_new(epochtime_class);
x->starttime=time();
outlet_new(&x->x_obj, &s_float);
return (x);
}
and on a bang you'd take the current time and do a diff:
x->t=time();
outlet_float(x->x_obj.ob_outlet,
(t_float) (difftime(x->starttime, x->t)));
This should work, but I didn't test it. I use a [bang~] and a counter for timing.
Frank Barknecht _ ______footils.org__