dateless_time 0.0.4 → 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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZjQ4NTk5MGE2ZWVmMWRmNGU1NjUxZDk4ODRhMmRmYzViZjFhMmEwZA==
5
- data.tar.gz: !binary |-
6
- OGQyMDYzMzMxNDQxNDllNmIwNzk3ZjdkMzNmZjJlZjU2YmU4NDI5MQ==
2
+ SHA1:
3
+ metadata.gz: bbe2b44e02e4194d806aa04a9cfa911a4a223385
4
+ data.tar.gz: 00f469012a6eb6a00e1d53f85032a3e321942085
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MmNhYWJjYTgyNTFjNDU0ODY1YTUzOWY0OTAwYTI3M2U5ZmJhMDc0YTQzNTYx
10
- ZDM3Mzc1ZGIzYzhhN2E3NDBkYzVkMzdhZGYyMGFjMTE2YWMxNDQwNDliNGE1
11
- MWRjZDlkYjA2ZmU3NGUwZmI1NTBiZjRiZDM1MTU4NmZhOWU0MDg=
12
- data.tar.gz: !binary |-
13
- ZTk3YTY5NWQ0ZmViYWQ1NDdjNTVhYzYyMDkwM2VkZjI2MWJmNjgxZTEwNDAx
14
- MDE3MDJiMWJlZTMzNGQzNjQwYTc1Mjc1M2UxODlkNzJhYzJkMDYxMDkyNzJl
15
- NTRhN2MwNmJkMWM1MjlhMjFiNmViM2Y5OTQ1MDI0NjJkOTkwOWI=
6
+ metadata.gz: e3eb28671b034fa1fd58ec92c91c24ecc49c54e3157ba2f5db91815ccfc981b5f71b174dc3fee7fbeff13c11d312435de745ebb873629c2da7a8c063f71df023
7
+ data.tar.gz: f06462a8feb45a5eb8cb55433cd9c944d3892bbddaf850416fc035cb6f02c9b2c321de8455afc338e39694be6c64d458b1813fee550450e4598db5c8d284b684
@@ -0,0 +1,50 @@
1
+ # DatelessTime Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ The gem graduates from `0.0.x`. The basic functionality is stable and not going to change. The other additions that go into this release are small incremental changes.
6
+
7
+ #### New Features
8
+
9
+ * Added a changelog.
10
+ * The method `#to_time` now also accepts `DateTime` objects as base values, in addition to `Time` and `Date`.
11
+ * Added `#to_datetime` method, with semantics similar to `#to_time`.
12
+
13
+ #### Changes
14
+
15
+ * Small internal improvements.
16
+
17
+ ## 0.0.4
18
+ #### New Features
19
+
20
+ * Added methos aliases for `hour`, `min` and `sec`, to make the interface more consistent with the default `Time` class.
21
+ * The method `#to_time` now also accepts `Date` objects as base values, in addition to `Time` objects.
22
+
23
+ ## 0.0.3
24
+ #### New Features
25
+
26
+ * Added support to initialize new `DatelessTime` objects with other existing `DatelessTime` objects as sources.
27
+ * Added support to initizlize new `DatelessTime` objects with `DateTime` objects as sources.
28
+ * Offical support for sorting in arrays (just added tests to make sure it works).
29
+
30
+ #### Changes
31
+
32
+ * The gem now explicitly requires `date` from the standard library.
33
+
34
+ #### Bug Fixes
35
+
36
+ * Inizializing `DatelessTime` objects with strings like `"12:01 am"` or `"12:01 pm"` was generating invalid data.
37
+
38
+ ## 0.0.2
39
+
40
+ #### New Features
41
+
42
+ * Implemented support for the `Comparable` module. `DatelessTime` objects now support comparison operators: `==`, `<`, etc.
43
+
44
+ #### Bug Fixes
45
+
46
+ * The return value of `#to_time` was memoized, this made it impossible to use it moltiple times with different base values.
47
+
48
+ ## 0.0.1
49
+
50
+ The initial release.
data/README.md CHANGED
@@ -28,9 +28,9 @@ No external gems.
28
28
 
29
29
  Tested with:
30
30
 
31
- * MRI `1.9.3`, `2.0.0`, `2.1.0`, `2.1.1` and `2.1.2`
32
- * Rubinius `2.2.4`
33
- * JRuby `1.7.10`
31
+ * MRI `>= 1.9.3`
32
+ * Rubinius `>= 2.2`
33
+ * JRuby `>= 1.7`
34
34
 
35
35
 
36
36
  ## How
@@ -75,7 +75,7 @@ require 'dateless_time'
75
75
  time = DatelessTime.new "13:37:42"
76
76
 
77
77
  time.hours
78
- tome.hour
78
+ time.hour
79
79
  #=> 13
80
80
 
81
81
  time.minutes
@@ -87,7 +87,6 @@ time.sec
87
87
  #=> 42
88
88
 
89
89
  time.seconds_since_midnight
90
- # or
91
90
  time.to_i
92
91
  # => 49062
93
92
 
@@ -99,13 +98,21 @@ time.to_time
99
98
  time.to_time(Time.new(1985, 10, 25, 0, 0, 0, "-08:00"))
100
99
  # => 1985-10-25 13:37:42 -0800
101
100
 
102
- # or a base Date
101
+ # or a base Date or DateTime
103
102
  time.to_time(Date.new(1985, 10, 25))
104
103
  # => 1985-10-25 13:37:42 +0100
105
104
 
106
105
  time.to_time.class
107
106
  # => Time
108
107
 
108
+ # this uses DateTime.now to fill the date-related bits
109
+ time.to_datetime
110
+ # => #<DateTime: 2015-11-11T13:37:42+00:00 ((2457338j,49062s,0n),+0s,2299161j)>
111
+
112
+ # but here, too, you can supply a base object instead (Date, Time or DateTime)
113
+ time.to_datetime(Date.new(1985, 10, 25))
114
+ # => #<DateTime: 1985-10-25T13:37:42+00:00 ((2446364j,49062s,0n),+0s,2299161j)>
115
+
109
116
  time.strftime("%-l:%M %P")
110
117
  # => "1:37 pm"
111
118
 
@@ -189,6 +196,7 @@ end
189
196
 
190
197
  1. implement the `+` and `-` artimetic operators, in a way consistent with Ruby's `Time`
191
198
  2. nice to have: other methods from `Time`'s public interface
199
+ 3. using `DateTime` objects as base for `#to_time` and `#to_datetime` does not support fractional utc offsets (e.g. Australia)
192
200
 
193
201
 
194
202
 
@@ -36,8 +36,33 @@ class DatelessTime
36
36
 
37
37
  def to_time(base = Time.now)
38
38
  args = [base.year, base.month, base.day, @hours, @minutes, @seconds]
39
- args << base.utc_offset if base.is_a?(Time)
40
- @time_value = Time.new(*args)
39
+
40
+ if base.is_a?(Time)
41
+ args << base.utc_offset
42
+ elsif base.is_a?(DateTime)
43
+ args << (base.offset * SECONDS_IN_24_HOURS)
44
+ end
45
+
46
+ Time.new(*args)
47
+ rescue
48
+ nil
49
+ end
50
+
51
+
52
+ def to_datetime(base = DateTime.now)
53
+ args = [base.year, base.month, base.day, @hours, @minutes, @seconds]
54
+
55
+ normalized_offset = begin
56
+ if base.is_a?(DateTime)
57
+ base.offset * 24
58
+ elsif base.is_a?(Time)
59
+ base.utc_offset / 3600
60
+ end
61
+ end
62
+
63
+ normalized_offset && args << sprintf("%+d", normalized_offset)
64
+
65
+ DateTime.new(*args)
41
66
  rescue
42
67
  nil
43
68
  end
@@ -1,3 +1,3 @@
1
1
  class DatelessTime
2
- VERSION = "0.0.4"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -27,6 +27,15 @@ class QueryTest < Minitest::Test
27
27
  end
28
28
 
29
29
 
30
+ def test_to_time_with_time_with_offset_base
31
+ base = Time.new(1990, 11, 10, 12, 13, 14, '+04:00')
32
+ @to_time = @dl_time.to_time(base)
33
+
34
+ assert_equal Time, @to_time.class
35
+ assert_equal Time.new(1990, 11, 10, 13, 37, 42, '+04:00'), @to_time
36
+ end
37
+
38
+
30
39
  def test_to_time_with_date_base
31
40
  base = Date.new(1990, 11, 10)
32
41
  @to_time = @dl_time.to_time(base)
@@ -36,6 +45,25 @@ class QueryTest < Minitest::Test
36
45
  end
37
46
 
38
47
 
48
+
49
+ def test_to_time_with_datetime_base
50
+ base = DateTime.new(1990, 11, 10, 12, 13, 14)
51
+ @to_time = @dl_time.to_time(base)
52
+
53
+ assert_equal Time, @to_time.class
54
+ assert_equal Time.new(1990, 11, 10, 13, 37, 42), @to_time
55
+ end
56
+
57
+
58
+ def test_to_time_with_datetime_with_offset_base
59
+ base = DateTime.new(1990, 11, 10, 12, 13, 14, '+4')
60
+ @to_time = @dl_time.to_time(base)
61
+
62
+ assert_equal Time, @to_time.class
63
+ assert_equal Time.new(1990, 11, 10, 13, 37, 42, '+04:00'), @to_time
64
+ end
65
+
66
+
39
67
  def test_to_time_with_different_bases_should_change
40
68
  @to_time = @dl_time.to_time
41
69
  now = Time.now
@@ -53,6 +81,87 @@ class QueryTest < Minitest::Test
53
81
  end
54
82
 
55
83
 
84
+
85
+
86
+
87
+
88
+
89
+ def test_to_datetime_without_base
90
+ @to_datetime = @dl_time.to_datetime
91
+ now = DateTime.now
92
+ expected = DateTime.new(now.year, now.month, now.day, 13, 37, 42)
93
+
94
+ assert_equal DateTime, @to_datetime.class
95
+ assert_equal expected, @to_datetime
96
+ end
97
+
98
+
99
+ def test_to_datetime_with_time_base
100
+ base = Time.new(1990, 11, 10, 12, 13, 14)
101
+ @to_datetime = @dl_time.to_datetime(base)
102
+
103
+ assert_equal DateTime, @to_datetime.class
104
+ assert_equal DateTime.new(1990, 11, 10, 13, 37, 42), @to_datetime
105
+ end
106
+
107
+
108
+ def test_to_datetime_with_time_with_offset_base
109
+ base = Time.new(1990, 11, 10, 12, 13, 14, '+04:00')
110
+ @to_datetime = @dl_time.to_datetime(base)
111
+
112
+ assert_equal DateTime, @to_datetime.class
113
+ assert_equal DateTime.new(1990, 11, 10, 13, 37, 42, '+4'), @to_datetime
114
+ end
115
+
116
+
117
+ def test_to_datetime_with_date_base
118
+ base = Date.new(1990, 11, 10)
119
+ @to_datetime = @dl_time.to_datetime(base)
120
+
121
+ assert_equal DateTime, @to_datetime.class
122
+ assert_equal DateTime.new(1990, 11, 10, 13, 37, 42), @to_datetime
123
+ end
124
+
125
+
126
+
127
+ def test_to_datetime_with_datetime_base
128
+ base = DateTime.new(1990, 11, 10, 12, 13, 14)
129
+ @to_datetime = @dl_time.to_datetime(base)
130
+
131
+ assert_equal DateTime, @to_datetime.class
132
+ assert_equal DateTime.new(1990, 11, 10, 13, 37, 42), @to_datetime
133
+ end
134
+
135
+
136
+ def test_to_datetime_with_datetime_with_offset_base
137
+ base = DateTime.new(1990, 11, 10, 12, 13, 14, '+4')
138
+ @to_datetime = @dl_time.to_datetime(base)
139
+
140
+ assert_equal DateTime, @to_datetime.class
141
+ assert_equal DateTime.new(1990, 11, 10, 13, 37, 42, '+4'), @to_datetime
142
+ end
143
+
144
+
145
+ def test_to_datetime_with_different_bases_should_change
146
+ @to_datetime = @dl_time.to_datetime
147
+ now = Time.now
148
+ expected = DateTime.new(now.year, now.month, now.day, 13, 37, 42)
149
+
150
+ assert_equal DateTime, @to_datetime.class
151
+ assert_equal expected, @to_datetime
152
+
153
+
154
+ base = Time.new(1990, 11, 10, 12, 13, 14)
155
+ @to_datetime = @dl_time.to_datetime(base)
156
+
157
+ assert_equal DateTime, @to_datetime.class
158
+ assert_equal DateTime.new(1990, 11, 10, 13, 37, 42), @to_datetime
159
+ end
160
+
161
+
162
+
163
+
164
+
56
165
  def test_to_s
57
166
  assert_equal "13:37:42", @dl_time.to_s
58
167
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dateless_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommaso Pavese
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-04 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '5.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.3'
55
55
  description: A class to handle dateless time values. DatelessTime objects are a lightweight
@@ -59,7 +59,8 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
+ - CHANGELOG.md
63
64
  - Gemfile
64
65
  - LICENSE.txt
65
66
  - README.md
@@ -81,17 +82,17 @@ require_paths:
81
82
  - lib
82
83
  required_ruby_version: !ruby/object:Gem::Requirement
83
84
  requirements:
84
- - - ! '>='
85
+ - - ">="
85
86
  - !ruby/object:Gem::Version
86
87
  version: '0'
87
88
  required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  requirements:
89
- - - ! '>='
90
+ - - ">="
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
93
  requirements: []
93
94
  rubyforge_project:
94
- rubygems_version: 2.2.2
95
+ rubygems_version: 2.4.5.1
95
96
  signing_key:
96
97
  specification_version: 4
97
98
  summary: A class to handle dateless time values.
@@ -100,3 +101,4 @@ test_files:
100
101
  - test/creation_test.rb
101
102
  - test/query_test.rb
102
103
  - test/test_helper.rb
104
+ has_rdoc: