dateless_time 0.0.3 → 0.0.4
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 +13 -5
- data/README.md +10 -1
- data/lib/dateless_time.rb +7 -18
- data/lib/dateless_time/version.rb +1 -1
- data/test/query_test.rb +29 -1
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjQ4NTk5MGE2ZWVmMWRmNGU1NjUxZDk4ODRhMmRmYzViZjFhMmEwZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OGQyMDYzMzMxNDQxNDllNmIwNzk3ZjdkMzNmZjJlZjU2YmU4NDI5MQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmNhYWJjYTgyNTFjNDU0ODY1YTUzOWY0OTAwYTI3M2U5ZmJhMDc0YTQzNTYx
|
10
|
+
ZDM3Mzc1ZGIzYzhhN2E3NDBkYzVkMzdhZGYyMGFjMTE2YWMxNDQwNDliNGE1
|
11
|
+
MWRjZDlkYjA2ZmU3NGUwZmI1NTBiZjRiZDM1MTU4NmZhOWU0MDg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZTk3YTY5NWQ0ZmViYWQ1NDdjNTVhYzYyMDkwM2VkZjI2MWJmNjgxZTEwNDAx
|
14
|
+
MDE3MDJiMWJlZTMzNGQzNjQwYTc1Mjc1M2UxODlkNzJhYzJkMDYxMDkyNzJl
|
15
|
+
NTRhN2MwNmJkMWM1MjlhMjFiNmViM2Y5OTQ1MDI0NjJkOTkwOWI=
|
data/README.md
CHANGED
@@ -75,10 +75,15 @@ require 'dateless_time'
|
|
75
75
|
time = DatelessTime.new "13:37:42"
|
76
76
|
|
77
77
|
time.hours
|
78
|
+
tome.hour
|
78
79
|
#=> 13
|
80
|
+
|
79
81
|
time.minutes
|
82
|
+
time.min
|
80
83
|
#=> 37
|
84
|
+
|
81
85
|
time.seconds
|
86
|
+
time.sec
|
82
87
|
#=> 42
|
83
88
|
|
84
89
|
time.seconds_since_midnight
|
@@ -90,10 +95,14 @@ time.to_i
|
|
90
95
|
time.to_time
|
91
96
|
# => 2014-04-01 13:37:42 +0100
|
92
97
|
|
93
|
-
# but you can supply a base
|
98
|
+
# but you can supply a base Time object instead
|
94
99
|
time.to_time(Time.new(1985, 10, 25, 0, 0, 0, "-08:00"))
|
95
100
|
# => 1985-10-25 13:37:42 -0800
|
96
101
|
|
102
|
+
# or a base Date
|
103
|
+
time.to_time(Date.new(1985, 10, 25))
|
104
|
+
# => 1985-10-25 13:37:42 +0100
|
105
|
+
|
97
106
|
time.to_time.class
|
98
107
|
# => Time
|
99
108
|
|
data/lib/dateless_time.rb
CHANGED
@@ -19,7 +19,9 @@ class DatelessTime
|
|
19
19
|
|
20
20
|
|
21
21
|
attr_reader :hours, :minutes, :seconds
|
22
|
-
|
22
|
+
alias hour hours
|
23
|
+
alias min minutes
|
24
|
+
alias sec seconds
|
23
25
|
|
24
26
|
def self.now
|
25
27
|
new
|
@@ -33,8 +35,9 @@ class DatelessTime
|
|
33
35
|
|
34
36
|
|
35
37
|
def to_time(base = Time.now)
|
36
|
-
|
37
|
-
|
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)
|
38
41
|
rescue
|
39
42
|
nil
|
40
43
|
end
|
@@ -83,13 +86,11 @@ private
|
|
83
86
|
|
84
87
|
def conditional_init(source)
|
85
88
|
case source
|
86
|
-
when Time
|
87
|
-
when DateTime then init_with_datetime(source)
|
89
|
+
when Time, DateTime, DatelessTime then init_with_time(source)
|
88
90
|
when String then init_with_string(source)
|
89
91
|
when Fixnum then init_with_seconds(source)
|
90
92
|
when Hash then init_with_hash(source)
|
91
93
|
when Array then init_with_array(source)
|
92
|
-
when DatelessTime then init_with_dateless_time(source)
|
93
94
|
else raise DatelessTime::InitializationError, "DatelessTime objects cannot be initialized with instances of #{source.class}."
|
94
95
|
end
|
95
96
|
end
|
@@ -103,13 +104,6 @@ private
|
|
103
104
|
end
|
104
105
|
|
105
106
|
|
106
|
-
def init_with_datetime(datetime)
|
107
|
-
@hours = datetime.hour
|
108
|
-
@minutes = datetime.min
|
109
|
-
@seconds = datetime.sec
|
110
|
-
seconds_since_midnight
|
111
|
-
end
|
112
|
-
|
113
107
|
|
114
108
|
def init_with_string(string)
|
115
109
|
validate_time_string string
|
@@ -144,11 +138,6 @@ private
|
|
144
138
|
end
|
145
139
|
|
146
140
|
|
147
|
-
def init_with_dateless_time(source)
|
148
|
-
init_with_array([source.hours, source.minutes, source.seconds])
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
141
|
|
153
142
|
def calculate_seconds_since_midnight
|
154
143
|
if @hours && @minutes && @seconds
|
data/test/query_test.rb
CHANGED
@@ -18,7 +18,7 @@ class QueryTest < Minitest::Test
|
|
18
18
|
end
|
19
19
|
|
20
20
|
|
21
|
-
def
|
21
|
+
def test_to_time_with_time_base
|
22
22
|
base = Time.new(1990, 11, 10, 12, 13, 14)
|
23
23
|
@to_time = @dl_time.to_time(base)
|
24
24
|
|
@@ -27,6 +27,15 @@ class QueryTest < Minitest::Test
|
|
27
27
|
end
|
28
28
|
|
29
29
|
|
30
|
+
def test_to_time_with_date_base
|
31
|
+
base = Date.new(1990, 11, 10)
|
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), @to_time
|
36
|
+
end
|
37
|
+
|
38
|
+
|
30
39
|
def test_to_time_with_different_bases_should_change
|
31
40
|
@to_time = @dl_time.to_time
|
32
41
|
now = Time.now
|
@@ -95,6 +104,25 @@ class QueryTest < Minitest::Test
|
|
95
104
|
end
|
96
105
|
|
97
106
|
|
107
|
+
def test_alias_hour
|
108
|
+
assert @dl_time.respond_to?(:hour)
|
109
|
+
assert_equal 13, @dl_time.hour
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def test_alias_min
|
114
|
+
assert @dl_time.respond_to?(:min)
|
115
|
+
assert_equal 37, @dl_time.min
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def test_alias_sec
|
120
|
+
assert @dl_time.respond_to?(:sec)
|
121
|
+
assert_equal 42, @dl_time.sec
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
|
98
126
|
def test_strftime
|
99
127
|
assert_equal "13:37", @dl_time.strftime("%H:%M")
|
100
128
|
assert_equal "13:37:42", @dl_time.strftime("%H:%M:%S")
|
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
|
+
version: 0.0.4
|
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-
|
11
|
+
date: 2014-07-04 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,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
-
|
62
|
+
- .gitignore
|
63
63
|
- Gemfile
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
@@ -81,12 +81,12 @@ require_paths:
|
|
81
81
|
- lib
|
82
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- -
|
84
|
+
- - ! '>='
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- -
|
89
|
+
- - ! '>='
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
@@ -100,4 +100,3 @@ test_files:
|
|
100
100
|
- test/creation_test.rb
|
101
101
|
- test/query_test.rb
|
102
102
|
- test/test_helper.rb
|
103
|
-
has_rdoc:
|