aboutsummaryrefslogtreecommitdiff
path: root/src/z_datetime.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2003-06-18 13:53:44 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2003-06-18 13:53:44 +0000
commit3b5bf6e92a1e638697666fc51780be05c5c1ab4a (patch)
treedd42b1c871af25c9b64dca6063a164092bc68bd7 /src/z_datetime.c
parentdff74800d391a08e024cabb8ec13f96223a44601 (diff)
use "gettimeofday()" instead of "ftime()"
svn path=/trunk/externals/zexy/; revision=707
Diffstat (limited to 'src/z_datetime.c')
-rw-r--r--src/z_datetime.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/z_datetime.c b/src/z_datetime.c
index d6b59a3..db2da5e 100644
--- a/src/z_datetime.c
+++ b/src/z_datetime.c
@@ -1,5 +1,6 @@
/*
(c) 1202:forum::für::umläute:2000
+ 1506:forum::für::umläute:2003: use timeb only if needed (like on windoze)
"time" gets the current time from the system
"date" gets the current date from the system
@@ -9,6 +10,7 @@
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
+#define USE_TIMEB
#endif
#ifdef MACOSX
@@ -19,7 +21,12 @@
#include "zexy.h"
#include <time.h>
+#ifdef USE_TIMEB
#include <sys/timeb.h>
+#else
+#include <sys/time.h>
+#endif
+
/* ----------------------- time --------------------- */
@@ -59,13 +66,21 @@ static void *time_new(t_symbol *s, int argc, t_atom *argv)
static void time_bang(t_time *x)
{
- struct timeb mytime;
struct tm *resolvetime;
-
+ float ms = 0.f;
+#ifdef USE_TIMEB
+ struct timeb mytime;
ftime(&mytime);
resolvetime = (x->GMT)?gmtime(&mytime.time):localtime(&mytime.time);
-
- outlet_float(x->x_outlet4, (t_float)(mytime.millitm));
+ ms=mytime.millitm;
+#else
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ resolvetime = (x->GMT)?gmtime(&tv.tv_sec):localtime(&tv.tv_sec);
+ ms = tv.tv_usec*0.001;
+#endif
+ // outlet_float(x->x_outlet4, (t_float)(mytime.millitm));
+ outlet_float(x->x_outlet4, (t_float)(ms));
outlet_float(x->x_outlet3, (t_float)resolvetime->tm_sec);
outlet_float(x->x_outlet2, (t_float)resolvetime->tm_min);
outlet_float(x->x_outlet1, (t_float)resolvetime->tm_hour);
@@ -126,12 +141,16 @@ static void *date_new(t_symbol *s, int argc, t_atom *argv)
static void date_bang(t_date *x)
{
- struct timeb mytime;
struct tm *resolvetime;
-
+#ifdef USE_TIMEB
+ struct timeb mytime;
ftime(&mytime);
resolvetime=(x->GMT)?gmtime(&mytime.time):localtime(&mytime.time);
-
+#else
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ resolvetime = (x->GMT)?gmtime(&tv.tv_sec):localtime(&tv.tv_sec);
+#endif
outlet_float(x->x_outlet3, (t_float)resolvetime->tm_mday);
outlet_float(x->x_outlet2, (t_float)resolvetime->tm_mon + 1);
outlet_float(x->x_outlet1, (t_float)resolvetime->tm_year + 1900);