From: "headius (Charles Nutter)" Date: 2013-04-16T14:10:29+09:00 Subject: [ruby-core:54318] [CommonRuby - Feature #8096] introduce Time.current_timestamp Issue #8096 has been updated by headius (Charles Nutter). phluid61 (Matthew Kerwin) wrote: > There is this: https://github.com/phluid61/timestamp-gem > > The java stuff is experimentation on my part, published version of the gem > has none of that. You're pretty close. System.nanoTime is probably the closes thing to your "timestamp", but as kosaki points out it's not guaranteed to be monotonic (even your impl is not monotonic). Why? Because on some Linux or BSD, monotonic time may not be supported. Time is then per-CPU, which means it can appear to go backward if read from one CPU and then read from another CPU. On Solaris, the old gethrtime has the same problem, but Java attempts to do a monotonic version with some processor tricks. Here's the Windows impl from OpenJDK: =begin jlong os::javaTimeNanos() { if (!has_performance_count) { return javaTimeMillis() * NANOSECS_PER_MILLISEC; // the best we can do. } else { LARGE_INTEGER current_count; QueryPerformanceCounter(¤t_count); double current = as_long(current_count); double freq = performance_frequency; jlong time = (jlong)((current/freq) * NANOSECS_PER_SEC); return time; } } =end Where javaTimeMillis is: =begin jlong os::javaTimeMillis() { if (UseFakeTimers) { return fake_time++; } else { FILETIME wt; GetSystemTimeAsFileTime(&wt); return windows_to_java_time(wt); } } =end Obviously getting "true time" is much more complicated than just finding the right call. Your implementation for MRI is probably just fine. I can help make the JRuby version "correct" using nanoTime and proper method binding. But a few questions remain: * Do we want a single Time.timestamp method? * If so, which timestamp is it? * If not, how many representations of timestamp do we want? It seems to me that our timestamp and Time.now.to_i should probably be derived the same way. ---------------------------------------- Feature #8096: introduce Time.current_timestamp https://bugs.ruby-lang.org/issues/8096#change-38599 Author: vipulnsward (Vipul Amler) Status: Feedback Priority: Low Assignee: Category: Target version: =begin A lot of scenarios and applications require the use of (({Time.now.to_i})) which is used as current_timestamp in systems. The introduction of (({Time.current_timestamp})) {or something with similar with different name} would provide implicit integer timestamp instead of going from (({Time.now})) -> time_object -> to_i -> integer timestamp value So instead of Time.now.to_i # Outputs => 1363274618 one could use Time.current_timestamp # Outputs => 1363274618 =end -- http://bugs.ruby-lang.org/