timestamp 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/timestamp/Timestamp.c +16 -22
- data/ext/timestamp/Timestamp.java +85 -0
- data/ext/timestamp/extconf.rb +4 -3
- data/lib/timestamp.rb +33 -0
- metadata +81 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf5d7af58ef3dde79bd60d34bfc99a8fdeb77254
|
4
|
+
data.tar.gz: 7b166d887f7596277906c7a38e70948126349981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddb40b424daaa99e69bd3f009edefb07b6f741fbcb83a2a626b879ace085bcaef8ff68938d1240ba9f4bda64149ad31647089e09009c4e147bcdf03740607814
|
7
|
+
data.tar.gz: ff35f9ea6f552c118ac9f8a8eba5d13e82f4a231c5192c83f1a3a07e8d4c1b8cbabcebfcd4d487111874cc70d7af5251166248494afd9184b2928306eb78a6f5
|
data/ext/timestamp/Timestamp.c
CHANGED
@@ -1,26 +1,17 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c) 2013, Matthew Kerwin
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
18
|
-
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
19
|
-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
20
|
-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
21
|
-
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2
|
+
* Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
|
3
|
+
*
|
4
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
5
|
+
* purpose with or without fee is hereby granted, provided that the above
|
6
|
+
* copyright notice and this permission notice appear in all copies.
|
7
|
+
*
|
8
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
24
15
|
*/
|
25
16
|
|
26
17
|
#include "ruby.h"
|
@@ -64,11 +55,13 @@ time_s_timestamp(VALUE klass)
|
|
64
55
|
/*
|
65
56
|
* call-seq:
|
66
57
|
* Time.unix_timestamp -> int
|
58
|
+
* Time.unix_time -> int
|
67
59
|
*
|
68
60
|
* Returns the current time as an integer number of seconds
|
69
61
|
* since the Epoch.
|
70
62
|
*
|
71
63
|
* Time.unix_timestamp #=> 1363352771
|
64
|
+
* Time.unix_time #=> 1363352771
|
72
65
|
*/
|
73
66
|
|
74
67
|
static VALUE
|
@@ -111,6 +104,7 @@ time_s_unix_microtime(VALUE klass)
|
|
111
104
|
|
112
105
|
void Init_timestamp() {
|
113
106
|
rb_define_singleton_method(rb_cTime, "timestamp", time_s_timestamp, 0);
|
107
|
+
rb_define_singleton_method(rb_cTime, "unix_time", time_s_unix_timestamp, 0);
|
114
108
|
rb_define_singleton_method(rb_cTime, "unix_timestamp", time_s_unix_timestamp, 0);
|
115
109
|
rb_define_singleton_method(rb_cTime, "unix_microtime", time_s_unix_microtime, 0);
|
116
110
|
}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
|
3
|
+
*
|
4
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
5
|
+
* purpose with or without fee is hereby granted, provided that the above
|
6
|
+
* copyright notice and this permission notice appear in all copies.
|
7
|
+
*
|
8
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
|
+
*/
|
16
|
+
|
17
|
+
//package au.net.kerwin.jruby;
|
18
|
+
|
19
|
+
import java.io.IOException;
|
20
|
+
import org.jruby.Ruby;
|
21
|
+
import org.jruby.RubyClass;
|
22
|
+
import org.jruby.RubyInteger;
|
23
|
+
import org.jruby.RubyFloat;
|
24
|
+
import org.jruby.RubyModule;
|
25
|
+
import org.jruby.anno.JRubyMethod;
|
26
|
+
import org.jruby.runtime.load.BasicLibraryService;
|
27
|
+
|
28
|
+
public class Timestamp implements BasicLibraryService {
|
29
|
+
private Ruby runtime;
|
30
|
+
|
31
|
+
public boolean basicLoad(final Ruby runtime) throws IOException {
|
32
|
+
this.runtime = runtime;
|
33
|
+
RubyClass rb_cTime = runtime.getClass("Time");
|
34
|
+
rb_cTime.defineAnnotatedMethods(Timestamp.class);
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
/*
|
39
|
+
* call-seq:
|
40
|
+
* Time.timestamp -> int
|
41
|
+
*
|
42
|
+
* Returns a nanosecond timestamp on the system's monotonic clock.
|
43
|
+
*
|
44
|
+
* Time.timestamp #=> 17817203921822
|
45
|
+
*/
|
46
|
+
|
47
|
+
@JRubyMethod( name = "timestamp", meta = true )
|
48
|
+
public RubyInteger timestamp() {
|
49
|
+
return runtime.newFixnum(System.nanoTime());
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* call-seq:
|
54
|
+
* Time.unix_timestamp -> int
|
55
|
+
* Time.unix_time -> int
|
56
|
+
*
|
57
|
+
* Returns the current time as an integer number of seconds
|
58
|
+
* since the Epoch.
|
59
|
+
*
|
60
|
+
* Time.unix_timestamp #=> 1363352771
|
61
|
+
* Time.unix_time #=> 1363352771
|
62
|
+
*/
|
63
|
+
|
64
|
+
@JRubyMethod( name = {"unix_timestamp", "unix_time"}, meta = true )
|
65
|
+
public RubyInteger unix_timestamp() {
|
66
|
+
return runtime.newFixnum(System.currentTimeMillis() / 1000);
|
67
|
+
}
|
68
|
+
|
69
|
+
/*
|
70
|
+
* call-seq:
|
71
|
+
* Time.unix_microtime -> float
|
72
|
+
*
|
73
|
+
* Returns the current time as a floating-point number of seconds
|
74
|
+
* since the Epoch.
|
75
|
+
*
|
76
|
+
* Time.unix_microtime #=> 1363352771.315240
|
77
|
+
*/
|
78
|
+
|
79
|
+
@JRubyMethod( name = "unix_microtime", meta = true )
|
80
|
+
public RubyFloat unix_microtime() {
|
81
|
+
return RubyFloat.newFloat(runtime, System.currentTimeMillis() / 1000.0);
|
82
|
+
}
|
83
|
+
|
84
|
+
}
|
85
|
+
|
data/ext/timestamp/extconf.rb
CHANGED
data/lib/timestamp.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
if defined?(JRUBY_VERSION)
|
3
|
+
require 'jruby'
|
4
|
+
require File.expand_path('../timestamp.jar', __FILE__)
|
5
|
+
require 'timestamp'
|
6
|
+
|
7
|
+
class Time
|
8
|
+
@@timestamp = Java::Default::Timestamp.new.tap{|ts| ts.java_send :basicLoad, [org.jruby.Ruby], org.jruby.Ruby.getGlobalRuntime }
|
9
|
+
class << self
|
10
|
+
def timestamp
|
11
|
+
@@timestamp.java_send :timestamp, []
|
12
|
+
end
|
13
|
+
def unix_timestamp
|
14
|
+
@@timestamp.java_send :unix_timestamp, []
|
15
|
+
end
|
16
|
+
alias :unix_time :unix_timestamp
|
17
|
+
def unix_microtime
|
18
|
+
@@timestamp.java_send :unix_microtime, []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
else
|
23
|
+
begin
|
24
|
+
require 'timestamp/timestamp'
|
25
|
+
rescue LoadError
|
26
|
+
begin
|
27
|
+
require "timestamp/timestamp.#{RbConfig::CONFIG['DLEXT']}"
|
28
|
+
rescue LoadError
|
29
|
+
require "timestamp.#{RbConfig::CONFIG['DLEXT']}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
metadata
CHANGED
@@ -1,16 +1,89 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timestamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Kerwin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |
|
56
|
+
== Time.timestamp
|
57
|
+
|
58
|
+
Defines <tt>Time::timestamp</tt> and <tt>Time::unix_timestamp</tt>.
|
59
|
+
|
60
|
+
See the original discussion at {Ruby-Lang}[https://bugs.ruby-lang.org/issues/8096]
|
61
|
+
|
62
|
+
:call-seq:
|
63
|
+
Time::timestamp -> Integer
|
64
|
+
|
65
|
+
Returns a nanosecond-precision timestamp from the system's monotonic
|
66
|
+
clock. Note that the resolution of the measured time is system-
|
67
|
+
dependent (i.e. while the value displayed is always an integer number
|
68
|
+
of nanoseconds, the values may not necessarily change in increments of
|
69
|
+
exactly one).
|
70
|
+
|
71
|
+
This time value does not correlate to any absolute, real-world time
|
72
|
+
system; it is only useful for measuring relative (or elapsed) times at
|
73
|
+
a high granularity. For example, benchmark measurements.
|
74
|
+
|
75
|
+
:call-seq:
|
76
|
+
Time::unix_timestamp -> Integer
|
77
|
+
Time::unix_time -> Integer
|
78
|
+
|
79
|
+
Returns the current real-world time as a whole number of seconds since
|
80
|
+
the Epoch (1-Jan-1970).
|
81
|
+
|
82
|
+
:call-seq:
|
83
|
+
Time::unix_microtime -> Float
|
84
|
+
|
85
|
+
Returns the current real-world time as a floating-point number of
|
86
|
+
seconds since the Epoch (1-Jan-1970).
|
14
87
|
email:
|
15
88
|
- matthew@kerwin.net.au
|
16
89
|
executables: []
|
@@ -19,10 +92,12 @@ extensions:
|
|
19
92
|
extra_rdoc_files: []
|
20
93
|
files:
|
21
94
|
- ext/timestamp/Timestamp.c
|
95
|
+
- ext/timestamp/Timestamp.java
|
22
96
|
- ext/timestamp/extconf.rb
|
23
|
-
|
97
|
+
- lib/timestamp.rb
|
98
|
+
homepage: http://phluid61.github.com/timestamp-gem/
|
24
99
|
licenses:
|
25
|
-
-
|
100
|
+
- ISC License
|
26
101
|
metadata: {}
|
27
102
|
post_install_message:
|
28
103
|
rdoc_options: []
|