ignore_nsec 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be45015634ef3b453c087b0a42506df7beb18179
4
+ data.tar.gz: 165ec182423b7905a9ba0f056b828215e8574d42
5
+ SHA512:
6
+ metadata.gz: a09d81851252ed2577484a5f6c1d2b95375b4b1df1f839aaab22fce65af3e939de92182c59a8f203c5b97fad0c23c4656bd30b1ba918eb54eaebb479d6a58ac6
7
+ data.tar.gz: e9be5bafa488788bef891dc02f4f4a1d913735fbdd71999e7e86166626667bd5b903587b7d571942583c83d5d854695966ca18399d985c9e19820ce60667a52f
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 FineLine Prototyping, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ ## Ignore Nsec
2
+
3
+ Have ever run into a strange problem in Ruby where two Time instances that looked the same were different? You may have run into the nanosecond precision problem.
4
+
5
+ The ignore_nsec gem takes care of that. With the gem, nanoseconds are still available via the `nsec` and other methods, but the `<=>` method on Time instances will ignore nanoseconds, which resolves problems caused by some operating systems providing nanosecond precision that is more precise than what the database accepts, so when you compare a time before persisting, then retrieve the record and compare times, the times will be different. For example, let's setup two times with different nanoseconds:
6
+
7
+ ```ruby
8
+ # note: We are manually setting Time nsec here, so it isn't checking that
9
+ # your OS is returning nsec in the current time, nor is it checking your
10
+ # database stores or does not store nsec with (date)time.
11
+ #
12
+ a = Time.at(421.158888888)
13
+ b = Time.at(421.15888888)
14
+ a == b # => false
15
+ ```
16
+
17
+ While using this gem, Time instances will return `to_i <=> other.to_i` if the object that a Time is being compared to looks like a Time (i.e. responds to `nsec`). Using the same example:
18
+
19
+ ```ruby
20
+ a == b # => true
21
+ ```
22
+
23
+ ### Checking nsec
24
+
25
+ Run Time.now a few times in `irb` and see if it always seems to return the last three as '0' or if it has 6 or fewer significant digits (non-zero digits to the right of the decimal point). In OS X 10.9, I see that it does not support nanosecond precision in Time (by default, at least), e.g.:
26
+
27
+ ```ruby
28
+ Time.now # => 220359000
29
+ ```
30
+
31
+ In my Linux VM, it does use nsec precision, e.g.:
32
+
33
+ ```ruby
34
+ Time.now # => 543686757
35
+ ```
36
+
37
+ ### Setup
38
+
39
+ In your Gemfile:
40
+
41
+ gem 'ignore_nsec'
42
+
43
+ Then run:
44
+
45
+ bundle install
46
+
47
+ ### Performance
48
+
49
+ In testing, the revised `<=>` method only for the Time object seemed to be about 10x slower (0.00001029 sec vs. 0.00000105 sec). This is probably not a problem for small numbers of calls, but would become a concern if you were doing anything that required a lot of date comparisons, such as sorting millions of records in Ruby by time (vs. sorting in the database via query, which hopefully you would be able to do instead).
50
+
51
+ ### License
52
+
53
+ Copyright (c) 2014 FineLine Prototyping, Inc., released under the [MIT license][lic].
54
+
55
+ [lic]: http://github.com/garysweaver/ignore_nsec/blob/master/LICENSE
@@ -0,0 +1,9 @@
1
+ require 'ignore_nsec/version'
2
+
3
+ class Time
4
+ alias_method '___<=>'.to_sym, :<=>
5
+
6
+ def <=>(other)
7
+ other.respond_to?(:nsec) ? to_i <=> other.to_i : send('___<=>'.to_sym, other)
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module IgnoreNsec
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ignore_nsec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gary S. Weaver
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Some versions of OS's and databases only support microsecond precision.
14
+ Using this gem makes Ruby ignore nanoseconds in Time comparisons to hopefully help
15
+ avoid the time != time problem.
16
+ email:
17
+ - garysweaver@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ - lib/ignore_nsec.rb
25
+ - lib/ignore_nsec/version.rb
26
+ homepage: https://github.com/garysweaver/ignore_nsec
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.2.2
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Ignore nanosecond precision in Time comparisons.
50
+ test_files: []