timestamp 0.3.0 → 1.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/ext/timestamp/Timestamp.c +80 -13
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fad73a196958d666f5bab820ab2079d733273915
4
- data.tar.gz: 8802615c4538ae3fac8a6552449e160db3a23728
3
+ metadata.gz: bc008a9363a9c26447094ca046df57a8b852fdbd
4
+ data.tar.gz: 281dafc2af4e211c9b62a448e54f6d0978185001
5
5
  SHA512:
6
- metadata.gz: a4582283b0d921b1942b029637d618c0b22c0a8e1a008a587b23d8bdbb32af34f6366dad9d1fcfe69bbfc6c1e8e967b7f2bdf38cdd3264aefb29b9abdcd4963d
7
- data.tar.gz: 497584ec3c6169d9640610969ed1f96a8921ecfaf1653c0b443a195191e885ba0cd096c2233c642c17ea445a0b5e0e91ef2d8c5de629aa3681c51afdbd2dad45
6
+ metadata.gz: fc93f38b4f32bdc2499156ec830ae1c40f620641634e11a4b96aa72f0657ef9b6566b8ab384333e2a5d37b5a8906902e93a688a605730d00498a139daffa63f3
7
+ data.tar.gz: a2d3d8aaf764f80d7b2198f55a21558a912ece7190a2240c3fd9f5f9ecfcf0762227d58fdefd9660e22b20c815d2ef7e71ea19d5f7eda60b9ab562bec1d42b53
@@ -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.current_timestamp -> int
7
- * Time.timestamp -> int
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.current_timestamp #=> 1363352771
13
- * Time.timestamp #=> 1363352771
71
+ * Time.unix_timestamp #=> 1363352771
14
72
  */
15
73
 
16
74
  static VALUE
17
- time_s_current_timestamp(VALUE klass)
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.microtime -> float
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.microtime #=> 1363352771.315240
87
+ * Time.unix_microtime #=> 1363352771.315240
30
88
  */
31
89
 
32
90
  static VALUE
33
- time_s_microtime(VALUE klass)
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
- rb_sys_fail("gettimeofday");
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, "current_timestamp", time_s_current_timestamp, 0);
47
- rb_define_singleton_method(rb_cTime, "timestamp", time_s_current_timestamp, 0);
48
- rb_define_singleton_method(rb_cTime, "microtime", time_s_microtime, 0);
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.3.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-15 00:00:00.000000000 Z
11
+ date: 2013-03-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Defines Time.current_timestamp , from https://bugs.ruby-lang.org/issues/8096
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.current_timestamp
46
+ summary: Time.timestamp
47
47
  test_files: []