ext/czmq/src/zclock.c in rbczmq-1.7.1 vs ext/czmq/src/zclock.c in rbczmq-1.7.2
- old
+ new
@@ -123,10 +123,24 @@
fflush (stdout);
}
// --------------------------------------------------------------------------
+// Return formatted date/time as fresh string.
+
+char *
+zclock_timestr (void)
+{
+ time_t curtime = time (NULL);
+ struct tm *loctime = localtime (&curtime);
+ char formatted [20];
+ strftime (formatted, 20, "%Y-%m-%d %H:%M:%S", loctime);
+ return strdup (formatted);
+}
+
+
+// --------------------------------------------------------------------------
// Self test of this class
int
zclock_test (bool verbose)
{
@@ -134,9 +148,13 @@
// @selftest
int64_t start = zclock_time ();
zclock_sleep (10);
assert ((zclock_time () - start) >= 10);
+ char *timestr = zclock_timestr ();
+ if (verbose)
+ puts (timestr);
+ free (timestr);
// @end
printf ("OK\n");
return 0;
}