timestamp 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/timestamp/Timestamp.c +80 -13
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc008a9363a9c26447094ca046df57a8b852fdbd
|
4
|
+
data.tar.gz: 281dafc2af4e211c9b62a448e54f6d0978185001
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc93f38b4f32bdc2499156ec830ae1c40f620641634e11a4b96aa72f0657ef9b6566b8ab384333e2a5d37b5a8906902e93a688a605730d00498a139daffa63f3
|
7
|
+
data.tar.gz: a2d3d8aaf764f80d7b2198f55a21558a912ece7190a2240c3fd9f5f9ecfcf0762227d58fdefd9660e22b20c815d2ef7e71ea19d5f7eda60b9ab562bec1d42b53
|
data/ext/timestamp/Timestamp.c
CHANGED
@@ -1,49 +1,116 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2013, Matthew Kerwin
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
* list of conditions and the following disclaimer.
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
* this list of conditions and the following disclaimer in the documentation
|
12
|
+
* and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
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.
|
24
|
+
*/
|
25
|
+
|
1
26
|
#include "ruby.h"
|
2
27
|
#include <time.h>
|
3
28
|
|
29
|
+
#if defined(HAVE_SYS_TIME_H)
|
30
|
+
#include <sys/time.h>
|
31
|
+
#endif
|
32
|
+
|
4
33
|
/*
|
5
34
|
* call-seq:
|
6
|
-
* Time.
|
7
|
-
*
|
35
|
+
* Time.timestamp -> int
|
36
|
+
*
|
37
|
+
* Returns a nanosecond timestamp on the system's monotonic clock.
|
38
|
+
*
|
39
|
+
* Time.timestamp #=> 17817203921822
|
40
|
+
*/
|
41
|
+
|
42
|
+
static VALUE
|
43
|
+
time_s_timestamp(VALUE klass)
|
44
|
+
{
|
45
|
+
VALUE t;
|
46
|
+
|
47
|
+
#ifdef HAVE_CLOCK_GETTIME
|
48
|
+
struct timespec ts;
|
49
|
+
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
|
50
|
+
rb_sys_fail("clock_gettime");
|
51
|
+
}
|
52
|
+
t = rb_uint2big(ts.tv_sec*1000000000 + ts.tv_nsec);
|
53
|
+
#else
|
54
|
+
struct timeval tv;
|
55
|
+
if (gettimeofday(&tv, 0) < 0) {
|
56
|
+
rb_sys_fail("gettimeofday");
|
57
|
+
}
|
58
|
+
t = rb_uint2big(tv.tv_sec*1000000000 + tv.tv_usec*1000);
|
59
|
+
#endif
|
60
|
+
|
61
|
+
return t;
|
62
|
+
}
|
63
|
+
|
64
|
+
/*
|
65
|
+
* call-seq:
|
66
|
+
* Time.unix_timestamp -> int
|
8
67
|
*
|
9
68
|
* Returns the current time as an integer number of seconds
|
10
69
|
* since the Epoch.
|
11
70
|
*
|
12
|
-
* Time.
|
13
|
-
* Time.timestamp #=> 1363352771
|
71
|
+
* Time.unix_timestamp #=> 1363352771
|
14
72
|
*/
|
15
73
|
|
16
74
|
static VALUE
|
17
|
-
|
75
|
+
time_s_unix_timestamp(VALUE klass)
|
18
76
|
{
|
19
77
|
return INT2NUM( time(NULL) );
|
20
78
|
}
|
21
79
|
|
22
80
|
/*
|
23
81
|
* call-seq:
|
24
|
-
* Time.
|
82
|
+
* Time.unix_microtime -> float
|
25
83
|
*
|
26
84
|
* Returns the current time as a floating-point number of seconds
|
27
85
|
* since the Epoch.
|
28
86
|
*
|
29
|
-
* Time.
|
87
|
+
* Time.unix_microtime #=> 1363352771.315240
|
30
88
|
*/
|
31
89
|
|
32
90
|
static VALUE
|
33
|
-
|
91
|
+
time_s_unix_microtime(VALUE klass)
|
34
92
|
{
|
35
|
-
struct timeval tv;
|
36
93
|
double t;
|
94
|
+
#ifdef HAVE_CLOCK_GETTIME
|
95
|
+
struct timespec ts;
|
96
|
+
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
|
97
|
+
rb_sys_fail("clock_gettime");
|
98
|
+
}
|
99
|
+
t = (double)ts.tv_sec;
|
100
|
+
t += ((double)ts.tv_nsec / 1000000000.0);
|
101
|
+
#else
|
102
|
+
struct timeval tv;
|
37
103
|
if (gettimeofday(&tv, 0) < 0) {
|
38
|
-
|
104
|
+
rb_sys_fail("gettimeofday");
|
39
105
|
}
|
40
106
|
t = (double)tv.tv_sec;
|
41
107
|
t += ((double)tv.tv_usec / 1000000.0);
|
108
|
+
#endif
|
42
109
|
return rb_float_new(t);
|
43
110
|
}
|
44
111
|
|
45
112
|
void Init_timestamp() {
|
46
|
-
rb_define_singleton_method(rb_cTime, "
|
47
|
-
rb_define_singleton_method(rb_cTime, "
|
48
|
-
rb_define_singleton_method(rb_cTime, "
|
113
|
+
rb_define_singleton_method(rb_cTime, "timestamp", time_s_timestamp, 0);
|
114
|
+
rb_define_singleton_method(rb_cTime, "unix_timestamp", time_s_unix_timestamp, 0);
|
115
|
+
rb_define_singleton_method(rb_cTime, "unix_microtime", time_s_unix_microtime, 0);
|
49
116
|
}
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timestamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
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-03-
|
11
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Defines Time.
|
13
|
+
description: Defines Time.timestamp and .unix_timestamp , from https://bugs.ruby-lang.org/issues/8096
|
14
14
|
email:
|
15
15
|
- matthew@kerwin.net.au
|
16
16
|
executables: []
|
@@ -43,5 +43,5 @@ rubyforge_project:
|
|
43
43
|
rubygems_version: 2.0.2
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
|
-
summary: Time.
|
46
|
+
summary: Time.timestamp
|
47
47
|
test_files: []
|