teasy 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +2 -0
- data/README.md +1 -6
- data/Rakefile +3 -1
- data/lib/teasy.rb +2 -0
- data/lib/teasy/floating_time.rb +11 -9
- data/lib/teasy/time_with_zone.rb +14 -10
- data/lib/teasy/version.rb +3 -1
- data/teasy.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53f5f0b964d3834bca1c2b758e319f63d51f9d1b
|
4
|
+
data.tar.gz: e29dd57251904a1ad26ce7d122fe66a87f54aac0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d481cbb6b0966e20565b745b446d0703e19b6cf0238ea10b71994756167c84e68b3e158f1ce0f9d9841ce2c7e5cb1fbcbf7b7a1bca9d469b042bcad0d43be689
|
7
|
+
data.tar.gz: 6de90fda2fea2a0dc8e95ed89e0711303e3c697082a2459ddde8971e79c8b1b731c2370df63e2ac2af58f589db2aa2c0b9f5843dc0d8b54cf7ec4caf61df2f74
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -20,11 +20,6 @@ That was reported [here](https://github.com/rails/rails/issues/14178) a few year
|
|
20
20
|
|
21
21
|
This gem also comes with a FloatingTime class, which is time without a zone. I.e., 5 a.m. in New York is the same as 5 a.m. in Berlin with regards to floating time. This is useful for events that should occur at a certain time irrespective of time zone. E.g., your wake up call at 8 a.m. which you wouldn't want to ring at 2 in the morning just because you switched time zones.
|
22
22
|
|
23
|
-
## Why you should use this tentatively
|
24
|
-
|
25
|
-
It's tested and I spend much thought on it. But I'm not perfect and there's bound to be bugs. I'll start using this gem productively which will give me some feedback. But right now I have only what my tests tell me.
|
26
|
-
I'm sure there is room for improvement and there will be refactorings. However for now I need to use it and I'd be happy if you did too! So that I can get some feedback and see what needs to change.
|
27
|
-
|
28
23
|
## Installation
|
29
24
|
|
30
25
|
Add this line to your application's Gemfile:
|
@@ -143,7 +138,7 @@ floating_time == other_ny_time # -> false
|
|
143
138
|
|
144
139
|
## Contributing
|
145
140
|
|
146
|
-
1. Fork it ( https://github.com/
|
141
|
+
1. Fork it ( https://github.com/kaikuchn/teasy/fork )
|
147
142
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
148
143
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
149
144
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubocop/rake_task'
|
2
4
|
require 'rake/testtask'
|
3
5
|
require 'bundler/gem_tasks'
|
@@ -8,4 +10,4 @@ Rake::TestTask.new do |t|
|
|
8
10
|
t.pattern = 'test/**/*_test.rb'
|
9
11
|
end
|
10
12
|
|
11
|
-
task default: [
|
13
|
+
task default: %i[test rubocop]
|
data/lib/teasy.rb
CHANGED
data/lib/teasy/floating_time.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tzinfo'
|
2
4
|
require 'forwardable'
|
3
5
|
|
@@ -36,7 +38,7 @@ module Teasy
|
|
36
38
|
strftime('%Y-%m-%d %H:%M:%S')
|
37
39
|
end
|
38
40
|
|
39
|
-
|
41
|
+
alias to_s inspect
|
40
42
|
|
41
43
|
def strftime(format)
|
42
44
|
format = prefix_zone_info(format) if includes_zone_directive?(format)
|
@@ -47,7 +49,7 @@ module Teasy
|
|
47
49
|
strftime('%a %b %e %T %Y')
|
48
50
|
end
|
49
51
|
|
50
|
-
|
52
|
+
alias ctime asctime
|
51
53
|
|
52
54
|
def <=>(other)
|
53
55
|
return nil unless other.respond_to?(:to_time) &&
|
@@ -73,7 +75,7 @@ module Teasy
|
|
73
75
|
elsif other.respond_to? :to_time
|
74
76
|
to_time - other.to_time
|
75
77
|
else
|
76
|
-
|
78
|
+
raise TypeError, "#{other.class} can't be coerced into FloatingTime"
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
@@ -85,7 +87,7 @@ module Teasy
|
|
85
87
|
time.dup
|
86
88
|
end
|
87
89
|
|
88
|
-
|
90
|
+
alias utc to_time
|
89
91
|
|
90
92
|
def utc_offset
|
91
93
|
0
|
@@ -93,21 +95,21 @@ module Teasy
|
|
93
95
|
|
94
96
|
private
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
-
def self.zone_directives_matcher
|
98
|
+
def zone_directives_matcher
|
99
99
|
@zone_directives_matcher ||= Regexp.union(
|
100
100
|
/(?<!%)%Z/, /(?<!%)%z/, /(?<!%)%:z/, /(?<!%)%::z/
|
101
101
|
)
|
102
102
|
end
|
103
103
|
|
104
|
+
attr_reader :time
|
105
|
+
|
104
106
|
def includes_zone_directive?(format)
|
105
|
-
|
107
|
+
zone_directives_matcher =~ format
|
106
108
|
end
|
107
109
|
|
108
110
|
def prefix_zone_info(format)
|
109
111
|
# prefixes zone directives with a % s.t. they are ignored in strftime
|
110
|
-
format.gsub(
|
112
|
+
format.gsub(zone_directives_matcher) { |m| '%' + m }
|
111
113
|
end
|
112
114
|
end
|
113
115
|
# rubocop:enable Metrics/ClassLength
|
data/lib/teasy/time_with_zone.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tzinfo'
|
2
4
|
require 'forwardable'
|
3
5
|
|
@@ -93,7 +95,7 @@ module Teasy
|
|
93
95
|
strftime(format)
|
94
96
|
end
|
95
97
|
|
96
|
-
|
98
|
+
alias to_s inspect
|
97
99
|
|
98
100
|
def strftime(format)
|
99
101
|
format = replace_zone_info(format) if includes_zone_directive?(format)
|
@@ -104,7 +106,7 @@ module Teasy
|
|
104
106
|
strftime('%a %b %e %T %Y')
|
105
107
|
end
|
106
108
|
|
107
|
-
|
109
|
+
alias ctime asctime
|
108
110
|
|
109
111
|
def +(other)
|
110
112
|
TimeWithZone.from_utc(utc_time + other, @zone.identifier)
|
@@ -116,7 +118,7 @@ module Teasy
|
|
116
118
|
elsif other.respond_to? :to_time
|
117
119
|
to_time - other.to_time
|
118
120
|
else
|
119
|
-
|
121
|
+
raise TypeError, "#{other.class} can't be coerced into TimeWithZone"
|
120
122
|
end
|
121
123
|
end
|
122
124
|
|
@@ -139,7 +141,7 @@ module Teasy
|
|
139
141
|
|
140
142
|
def to_time
|
141
143
|
return @local_time unless @local_time.nil?
|
142
|
-
params = %i
|
144
|
+
params = %i[year mon day hour min].map! { |m| @time.send(m) }
|
143
145
|
params << @time.sec + @time.subsec
|
144
146
|
@local_time = utc? ? Time.utc(*params) : Time.new(*params, utc_offset)
|
145
147
|
end
|
@@ -158,33 +160,35 @@ module Teasy
|
|
158
160
|
ZONE_COLON_OFFSET = /(?<!%)%:z/
|
159
161
|
ZONE_COLONS_OFFSET = /(?<!%)%::z/
|
160
162
|
|
161
|
-
def
|
163
|
+
def zone_directives_matcher
|
162
164
|
@zone_directives_matcher ||= Regexp.union(
|
163
165
|
ZONE_ABBREV, ZONE_NO_COLON_OFFSET, ZONE_COLON_OFFSET, ZONE_COLONS_OFFSET
|
164
166
|
)
|
165
167
|
end
|
166
168
|
|
167
169
|
def includes_zone_directive?(format)
|
168
|
-
|
170
|
+
zone_directives_matcher =~ format
|
169
171
|
end
|
170
172
|
|
171
173
|
def replace_zone_info(format)
|
172
174
|
format_with_zone = format.gsub(ZONE_ABBREV, period.abbreviation.to_s)
|
173
175
|
format_with_zone.gsub!(ZONE_NO_COLON_OFFSET, formatted_offset(utc_offset))
|
174
176
|
format_with_zone.gsub!(
|
175
|
-
ZONE_COLON_OFFSET, formatted_offset(utc_offset, :with_colon)
|
177
|
+
ZONE_COLON_OFFSET, formatted_offset(utc_offset, :with_colon)
|
178
|
+
)
|
176
179
|
format_with_zone.gsub!(
|
177
180
|
ZONE_COLONS_OFFSET,
|
178
|
-
formatted_offset(utc_offset, :with_colon, :with_seconds)
|
181
|
+
formatted_offset(utc_offset, :with_colon, :with_seconds)
|
182
|
+
)
|
179
183
|
format_with_zone
|
180
184
|
end
|
181
185
|
|
182
186
|
def formatted_offset(offset_in_seconds, colon = false, seconds = false)
|
183
|
-
string_format = '%s%02d:%02d'
|
187
|
+
string_format = +'%s%02d:%02d'
|
184
188
|
string_format.concat(':%02d') if seconds
|
185
189
|
string_format.delete!(':') unless colon
|
186
190
|
|
187
|
-
sign = offset_in_seconds
|
191
|
+
sign = offset_in_seconds.negative? ? '-' : '+'
|
188
192
|
hours = offset_in_seconds.abs / 3600
|
189
193
|
minutes = (offset_in_seconds.abs % 3600) / 60
|
190
194
|
seconds = (offset_in_seconds.abs % 60)
|
data/lib/teasy/version.rb
CHANGED
data/teasy.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.required_ruby_version = '> 2.0'
|
24
24
|
|
25
25
|
spec.add_runtime_dependency 'tzinfo', '~> 1.2'
|
26
|
-
spec.add_runtime_dependency 'tzinfo-data', '~> 1.
|
26
|
+
spec.add_runtime_dependency 'tzinfo-data', '~> 1.2017.2'
|
27
27
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
29
29
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teasy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kai Kuchenbecker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.2017.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.2017.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.5.1
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Teasy intends to make handling time zones easy.
|