mug 0.5 → 0.5.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mug.rb +1 -0
  3. data/lib/mug/time.rb +70 -0
  4. data/test/test-time.rb +39 -0
  5. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 312309b5648e3c0bcf0f20a78b1f2e8967a8c407
4
- data.tar.gz: 36928e26dc4bbc52d6f4a8ef58a6a8faca5f6879
3
+ metadata.gz: 21d1b6c8247c41a14924f50e55653bfe7bb87493
4
+ data.tar.gz: 37d41621cb3ca18807a2c936493c785c7ed63dd7
5
5
  SHA512:
6
- metadata.gz: 8728a0f1d3fdfaf985ba2ef0201d0895e0ac47963c214ca45713bb11526fbcd6622e3f712ab58ae4a32dc98596220981c898ad43391d1cd152c8aee56a720c3b
7
- data.tar.gz: 4d347c516b264cffc9da8b80b19f168d0a1946db18df8f74c76a1443dc39876b1e7d69249ccd557fa5da494f89af81658d268d7277862f5860b8e8d9495d122e
6
+ metadata.gz: 66dcd7f92b6bd1d1130f36df8283d05e7b0c7b5d7ebb9bc8d9d11c8d01fb65b4b6b6afa584a5f83c762b9fa8d3c39258c8accbdb533f507307b21efb516858e1
7
+ data.tar.gz: bc82837df41887914560e947239fe2499737fbf82afa5dc2ea717466dc69cd135a7ac804e5aba5bb3da015b6570defea49336df3bb893aded73b9d4d869c833e
data/lib/mug.rb CHANGED
@@ -21,5 +21,6 @@ require_relative 'mug/not'
21
21
  require_relative 'mug/rexproc'
22
22
  require_relative 'mug/self'
23
23
  require_relative 'mug/tau'
24
+ require_relative 'mug/time'
24
25
  require_relative 'mug/top'
25
26
 
@@ -0,0 +1,70 @@
1
+
2
+ class Time
3
+
4
+ #
5
+ # Returns the number of seconds since the time represented by
6
+ # this Time object.
7
+ #
8
+ # start = Time.now
9
+ # #...
10
+ # duration = start.to_now
11
+ #
12
+ def to_now
13
+ #if Time.respond_to? :unix_timestamp
14
+ # Time.unix_timestamp - to_i
15
+ #else
16
+ self.class.now - self
17
+ #end
18
+ end
19
+
20
+ #
21
+ # Returns the number of seconds until the time represented by
22
+ # this Time object.
23
+ #
24
+ # target = Time.new 2017, 1, 1, 0, 0, 0
25
+ # sleep target.from_now
26
+ #
27
+ def from_now
28
+ #if time.respond_to? :unix_timestamp
29
+ # to_i - Time.unix_timestamp
30
+ #else
31
+ self - self.class.now
32
+ #end
33
+ end
34
+
35
+ class << self
36
+
37
+ #
38
+ # Returns the number of seconds until +t+
39
+ #
40
+ def until t
41
+ t.from_now
42
+ end
43
+
44
+ #
45
+ # Returns the number of since since +t+
46
+ #
47
+ def since t
48
+ t.to_now
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ =begin
56
+ Copyright (c) 2016, Matthew Kerwin <matthew@kerwin.net.au>
57
+
58
+ Permission to use, copy, modify, and/or distribute this software for any
59
+ purpose with or without fee is hereby granted, provided that the above
60
+ copyright notice and this permission notice appear in all copies.
61
+
62
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
63
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
64
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
65
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
66
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
67
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
68
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
69
+ =end
70
+
@@ -0,0 +1,39 @@
1
+ require 'test/unit'
2
+ $VERBOSE = true
3
+
4
+ $past = Time.new 1970, 1, 1, 0, 0, 0
5
+ $future = Time.new 2170, 1, 1, 0, 0, 0
6
+
7
+ require_relative '../lib/mug/time'
8
+ class Test_time < Test::Unit::TestCase
9
+
10
+ def test__to_now
11
+ assert_kind_of( Numeric, $past.to_now )
12
+ assert_operator( 0.0, :<, $past.to_now )
13
+ assert_operator( 0.0, :>, $future.to_now )
14
+ assert_equal( 0, Time.now.to_now.to_i ) # racey
15
+ end
16
+
17
+ def test__from_now
18
+ assert_kind_of( Numeric, $future.from_now )
19
+ assert_operator( 0.0, :>, $past.from_now )
20
+ assert_operator( 0.0, :<, $future.from_now )
21
+ assert_equal( 0, Time.now.from_now.to_i ) # racey
22
+ end
23
+
24
+ def test__until
25
+ assert_kind_of( Numeric, Time.until($future) )
26
+ assert_operator( 0.0, :>, Time.until($past) )
27
+ assert_operator( 0.0, :<, Time.until($future) )
28
+ assert_equal( 0, Time.until(Time.now).to_i ) # racey
29
+ end
30
+
31
+ def test__since
32
+ assert_kind_of( Numeric, Time.since($past) )
33
+ assert_operator( 0.0, :<, Time.since($past) )
34
+ assert_operator( 0.0, :>, Time.since($future) )
35
+ assert_equal( 0, Time.since(Time.now).to_i ) # racey
36
+ end
37
+
38
+ end
39
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mug
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Kerwin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-26 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  == MUG: Matty's Ultimate Gem
@@ -52,6 +52,7 @@ files:
52
52
  - lib/mug/rexproc.rb
53
53
  - lib/mug/self.rb
54
54
  - lib/mug/tau.rb
55
+ - lib/mug/time.rb
55
56
  - lib/mug/to_h.rb
56
57
  - lib/mug/top.rb
57
58
  - test/test-and-or.rb
@@ -76,6 +77,7 @@ files:
76
77
  - test/test-rexproc.rb
77
78
  - test/test-self.rb
78
79
  - test/test-tau.rb
80
+ - test/test-time.rb
79
81
  - test/test-top.rb
80
82
  homepage: http://phluid61.github.com/mug
81
83
  licenses:
@@ -114,6 +116,7 @@ test_files:
114
116
  - test/test-and-or.rb
115
117
  - test/test-any-and-all.rb
116
118
  - test/test-self.rb
119
+ - test/test-time.rb
117
120
  - test/test-counts.rb
118
121
  - test/test-negativity.rb
119
122
  - test/test-bool.rb