units-time 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85825ae67f49319633b3464c0a752a720d9a8a4c
4
- data.tar.gz: 86166febad3c6aa8cae454ac4ca9e0e5363bf7ce
3
+ metadata.gz: 0f4434428e744835697e7787669aa746664a0273
4
+ data.tar.gz: 7e1d04423f3135839ebc5098b0eb9afc147bbeb4
5
5
  SHA512:
6
- metadata.gz: eeb084bd4553ca0f1f0f446e1832c22e3cd5a9893ffd160bee4d6b7eec2d537ee5270f61b2cbdc720bbd3fab702377be18986e69a7237b1d403fa7daf958fc02
7
- data.tar.gz: d53de4ff638e3e0bbd527d4a8451b2aac67b8d58d60ab851f0ef1e7d0dd2df92012a3a1ce6aeb67e0d44873db249b0ca7a7e2b7b4848d7f25025d26c95694130
6
+ metadata.gz: 54d9206a1d4ff9ccd803867fe7b00bae3e448addc93c57089d9437a36d6bc02ade415786e843fcb65d8c9b7110e3f625ae443d370328cff72d5e0ccbff1160cf
7
+ data.tar.gz: 852713aa82ad2ab0d9fa55c02b69b6ada32e4193097b57234bbc0b4819225cdbc86d68679e007cb7aea07267e42d4608010a52fba4b5ce53f945b3067cc6a545
@@ -21,37 +21,23 @@ require 'units-time/timedelta'
21
21
  # - you CAN only compare (<=>) timedelta to timedelta but NOT timestamp !!
22
22
 
23
23
 
24
- ### "global" converter functions use like
25
- ## Timestamp(0) or Timedelta(0)
26
- def Timestamp(arg) Timestamp.new( arg ); end
27
- def Timedelta(arg) Timedelta.new( arg ); end
28
-
24
+ ### "global" Kernel converter functions use like
25
+ ## Timestamp(0) or Timedelta(0)
26
+ module Kernel
27
+ def Timestamp(arg) Timestamp.new( arg ); end
28
+ def Timedelta(arg) Timedelta.new( arg ); end
29
+ end
29
30
 
30
31
 
31
32
  module TimeUnits
32
- ######################################
33
- ## note: there's NO month (for now)!!!
34
- ## why? month might be 28,29,30,31 days
35
- ## use days e.g. 30.days or 31.days etc.
36
-
37
-
38
- HOUR_IN_SECONDS = 60 * 60 # 60 minutes * 60 seconds
39
- DAY_IN_SECONDS = 24 * HOUR_IN_SECONDS # 24 hours * 60 * 60
40
- WEEK_IN_SECONDS = 7 * DAY_IN_SECONDS # 7 days * 24 * 60 * 60
41
- FORTNIGHT_IN_SECONDS = 14 * DAY_IN_SECONDS # 14 days * 24 * 60 * 60
42
-
43
- #####
44
- # note: for year use 365 days for now and NOT 365.25 (1/4)
45
- # - why? why not? discuss
46
- YEAR_IN_SECONDS = 365 * DAY_IN_SECONDS # 365 days * 24 * 60 * 60
47
-
48
- def second() Timedelta.new( self ); end
49
- def minute() Timedelta.new( self * 60 ); end
50
- def hour() Timedelta.new( self * HOUR_IN_SECONDS ); end
51
- def day() Timedelta.new( self * DAY_IN_SECONDS ); end
52
- def week() Timedelta.new( self * WEEK_IN_SECONDS ); end
53
- def fortnight() Timedelta.new( self * FORTNIGHT_IN_SECONDS ); end
54
- def year() Timedelta.new( self * YEAR_IN_SECONDS ); end
33
+
34
+ def second() Timedelta.seconds( self ); end
35
+ def minute() Timedelta.minutes( self ); end
36
+ def hour() Timedelta.hours( self ); end
37
+ def day() Timedelta.days( self ); end
38
+ def week() Timedelta.weeks( self ); end
39
+ def fortnight() Timedelta.weeks( self * 2 ); end
40
+ def year() Timedelta.years( self ); end
55
41
 
56
42
 
57
43
  ########################################################
@@ -3,6 +3,29 @@
3
3
 
4
4
  class Timedelta
5
5
 
6
+ ######################################
7
+ ## note: there's NO month (for now)!!!
8
+ ## why? month might be 28,29,30,31 days
9
+ ## use days e.g. 30.days or 31.days etc.
10
+
11
+ HOUR_IN_SECONDS = 60 * 60 # 60 minutes * 60 seconds
12
+ DAY_IN_SECONDS = 24 * HOUR_IN_SECONDS # 24 hours * 60 * 60
13
+ WEEK_IN_SECONDS = 7 * DAY_IN_SECONDS # 7 days * 24 * 60 * 60
14
+ ## FORTNIGHT_IN_SECONDS = 14 * DAY_IN_SECONDS # 14 days * 24 * 60 * 60
15
+
16
+ #####
17
+ # note: for year use 365 days for now and NOT 365.25 (1/4)
18
+ # - why? why not? discuss
19
+ YEAR_IN_SECONDS = 365 * DAY_IN_SECONDS # 365 days * 24 * 60 * 60
20
+
21
+ def self.seconds( seconds ) new( seconds ); end
22
+ def self.minutes( minutes ) new( minutes * 60 ); end
23
+ def self.hours( hours ) new( hours * HOUR_IN_SECONDS ); end
24
+ def self.days( days ) new( days * DAY_IN_SECONDS ); end
25
+ def self.weeks( weeks ) new( weeks * WEEK_IN_SECONDS ); end
26
+ def self.years( years ) new( years * YEAR_IN_SECONDS ); end
27
+
28
+
6
29
  attr_reader :seconds
7
30
 
8
31
  def initialize( seconds=0 )
@@ -81,6 +104,8 @@ class Timedelta
81
104
  end
82
105
 
83
106
 
107
+ def zero?() self == self.class.zero; end ## note: compares values (e.g. 0==0) - not object_id (or frozen) etc.
108
+
84
109
  ## todo/fix: always freeze by default (timedelta is immutable) - why? why not?
85
110
  def self.zero() @@zero ||= new(0).freeze; end
86
111
 
@@ -51,6 +51,7 @@ class Timestamp
51
51
  end
52
52
  end
53
53
 
54
+ def zero?() self == self.class.zero; end ## note: compares values (e.g. 0==0) - not object_id (or frozen) etc.
54
55
 
55
56
  ## todo/fix: always freeze by default (timestamp is immutable) - why? why not?
56
57
  def self.zero() @@zero ||= new(0).freeze; end
@@ -3,8 +3,8 @@
3
3
  module UnitsTime
4
4
 
5
5
  MAJOR = 1
6
- MINOR = 0
7
- PATCH = 2
6
+ MINOR = 1
7
+ PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -112,4 +112,19 @@ def test_conv
112
112
  assert_equal 0.secs, Timedelta(0)
113
113
  end
114
114
 
115
+ def test_zero
116
+ assert_equal true, Timestamp(0).zero?
117
+ assert_equal true, Timedelta(0).zero?
118
+
119
+ assert_equal true, Timestamp.zero.zero?
120
+ assert_equal true, Timedelta.zero.zero?
121
+
122
+ assert_equal true, Timestamp.new(0).zero?
123
+ assert_equal true, Timedelta.new(0).zero?
124
+
125
+ assert_equal false, Timestamp.new(1).zero?
126
+ assert_equal false, Timestamp.new.zero?
127
+ assert_equal false, Timedelta.new(1).zero?
128
+ end
129
+
115
130
  end # class TestUnitsTime
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: units-time
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-10 00:00:00.000000000 Z
11
+ date: 2019-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc