time_jawn 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OGI5Yzg3MTkzOWQ3NjE3YjliYzg1NWY5ODY0NDNjNDMxOWU2OTJhZg==
5
- data.tar.gz: !binary |-
6
- YmUxNDQ0NGE0MzZlN2RhMzU3NjJhZTMxM2MxNDExNzhiZDc2OWNkNA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NWY2MjhkMTc0N2Y4ODFkMDY5YTMyYTRiYTViYjE3YmViMWQ4YmQyYTdhZTg3
10
- ZmU3OTA4ZTNjNjk4ZGM4MTVmZmZjOGM0MDBiMmFhZTU1NWUwYzU1MDBkMjFk
11
- MDM3NzhiYTJiOTg0OWU2MTAyMTBiNDgyNWNkYTc2YmY2Y2JhYjY=
12
- data.tar.gz: !binary |-
13
- ZTc3OWUxOGQzZDQ0ODAzMjgyMWE5MTM3NzYwZTk3YzU4Zjc3ZGYyYjBkNmUy
14
- MjJmOTYyZWQwOGI4ODk4ODkzN2YxZGM2YzRjMjgwYzhmODk3YTZkMTkzNmVh
15
- NTZiNjg1NjM1ZTIyMWQ5ZjdiMjc2N2I4YTc5OWYwMTM5MGYwNmM=
2
+ SHA1:
3
+ metadata.gz: a6a4e6f180be9199ca277acb30b77eb1c669e5d2
4
+ data.tar.gz: 7d4358869e51cdc0c2beabca8d190b88b0d413e3
5
+ SHA512:
6
+ metadata.gz: 267b4c81102f5f0802a19fd994588328e9dd58c5ea7f01f3b070cc36c33a0e885d3da624c6bad842a816dc47d64a2af0627ad2e404cd15faeddd6dd0425fb53e
7
+ data.tar.gz: cad1e579ac4eacce73346c287be8d4d95bd3dfec0ec173b5852311ac46ec71038eaecb423f5d5e8183a64fd6b0de4e7d97c5a415e630c04e4328af9482070f22
@@ -2,11 +2,14 @@
2
2
  # in a attribute name time_zone or has been delegating one to somewhere else.
3
3
  module TimeJawn
4
4
  require 'time_jawn/time_jawn_private_class_methods'
5
+
6
+ DATE_FORMAT = '%a, %d %b %Y %H:%M:%S'
7
+
5
8
  # Automatically runs and adds ClassMethods to ActiveRecord::Base
6
9
  def self.included(base)
7
10
  base.send :extend, ClassMethods
8
11
  end
9
-
12
+
10
13
  # Defines methods that will attached to all ActiveRecord classes.
11
14
  module ClassMethods
12
15
  include TimeJawnPrivateClassMethods
@@ -15,11 +18,10 @@ module TimeJawn
15
18
  # It is typically included in a model's rb file so that instances of that class gain the InstanceMethods at each instantiation.
16
19
  # class Event<ActiveRecord::Base
17
20
  # has_time_zone
18
- # end
21
+ # end
19
22
  # Optionally you may pass the name of your time zone attribute in as a symbol.
20
23
  # class Event<ActiveRecord::Base
21
24
  # has_time_zone :this_is_my_time_zone
22
- # end
23
25
  def has_time_zone(time_zone_attribute_name=:time_zone, options_hash={})
24
26
  _set_instance_variables(time_zone_attribute_name, options_hash)
25
27
  send :include, InstanceMethods
@@ -31,28 +33,28 @@ module TimeJawn
31
33
  # This method generates a series of methods on instances by calling the _generate_to_local and
32
34
  # _generate_to_local_with_assignment that are private on teh parent class. The methods that are created are called
33
35
  # local_#{attribue} and local_#{attribute}= the attribute portion their names are completed by enumerating
34
- # the datetime_attributes of the class. Twice as many methods as there are DateTime attributes will
36
+ # the datetime_attributes of the class. Twice as many methods as there are DateTime attributes will
35
37
  # be created.
36
- #
38
+ #
37
39
  # :created_at, and :updated_at
38
- #
40
+ #
39
41
  # local_created_at
40
42
  # local_updated_at
41
43
  # local_created_at=
42
44
  # local_updated_at=
43
- #
45
+ #
44
46
  # The local_#{attribue} methods will take the value stored in the attribute indicated by the methods name
45
47
  # and apply a time zone conversion to it. This is useful for displaying the local time (according to the object).
46
- #
48
+ #
47
49
  # local_#{attribute}= methods are assignment shortcuts. They behave a little differently than you would expect.
48
- # They do not take a local time and convert it into utc (or whatever, ActiveSupport will handle that for us),
49
- # what these assigment methods do is take any sort of string that looks like a time, or any sort of time or datetime
50
- # object lop off whatever timezone is being fed in and glue the instances local timezone on the end before applying
51
- # it to the appropriate attribute. This is convenient for some one in one time zone setting a value for an instance
50
+ # They do not take a local time and convert it into utc (or whatever, ActiveSupport will handle that for us),
51
+ # what these assigment methods do is take any sort of string that looks like a time, or any sort of time or datetime
52
+ # object lop off whatever timezone is being fed in and glue the instances local timezone on the end before applying
53
+ # it to the appropriate attribute. This is convenient for some one in one time zone setting a value for an instance
52
54
  # that represents a different time zone. For example:
53
55
  #
54
- # I am in Philadelphia (EST), my application is set to UTC, and I want to set the time on an Alarm instance that
55
- # goes off in San Francisco (PST). I want that time to be 6PM. In Philadlephia I choose 6PM (local), the applications assumes I
56
+ # I am in Philadelphia (EST), my application is set to UTC, and I want to set the time on an Alarm instance that
57
+ # goes off in San Francisco (PST). I want that time to be 6PM. In Philadlephia I choose 6PM (local), the applications assumes I
56
58
  # meant 6PM UTC (2PM EST and 11AM PST). That is not what I intended, I intended on 6PM PST, and now my Alarm is all wrong.
57
59
  # The assignment methods turn 6PM (set in EST, and processed in UTC) into 6PM PST (or 9PM EST, 1AM UTC) the expected time. The
58
60
  # Alarm goes off as expected!*
@@ -76,19 +78,19 @@ module TimeJawn
76
78
  ActiveSupport::Deprecation.warn "_to_local will be made private in a future version."
77
79
  time.in_time_zone(self.send(self.class.time_zone_attribute_name))
78
80
  end
79
-
81
+
80
82
  # Given a string that looks like a time. It will convert that string into a time object that matches the time but with
81
83
  # the instances time zone appended.
82
84
  def _add_zone(time_string)
83
85
  ActiveSupport::Deprecation.warn "_add_zone will be made private in a future version."
84
86
  Time.zone = self.send(self.class.time_zone_attribute_name)
85
- Time.zone.parse(Time.parse(time_string).strftime('%a, %d %b %Y %H:%M:%S'))
87
+ Time.zone.parse(Time.parse(time_string).strftime(DATE_FORMAT))
86
88
  end
87
89
 
88
90
  # Returns a string representation of a time object suitable for consumption by add_zone.
89
91
  def _change_zone(time)
90
92
  ActiveSupport::Deprecation.warn "_change_zone will be made private in a future version."
91
- _add_zone(time.strftime('%a, %d %b %Y %H:%M:%S'))
93
+ _add_zone(time.strftime(DATE_FORMAT))
92
94
  end
93
95
  end
94
96
  end
@@ -1,4 +1,4 @@
1
- # Defines private methods necessary for TimeJawn to work.
1
+ # Defines private methods necessary for TimeJawn to work.
2
2
  module TimeJawnPrivateClassMethods
3
3
  # Locates all of an ActiveRecord class' DateTime Attributes and returns them as an array of symbols.
4
4
  def _datetime_attributes
@@ -9,7 +9,7 @@ module TimeJawnPrivateClassMethods
9
9
  klass.columns.each do |column|
10
10
  datetime_attributes << column.name.to_sym if column.type == :datetime
11
11
  end
12
- return datetime_attributes
12
+ datetime_attributes
13
13
  end
14
14
 
15
15
  private
@@ -56,10 +56,6 @@ module TimeJawnPrivateClassMethods
56
56
 
57
57
  # returns all of the date_time attributes for a class unless it is specified in the class.
58
58
  def _class_date_attributes_or_arguments
59
- if @time_jawn_date_time_attributes
60
- @time_jawn_date_time_attributes
61
- else
62
- _datetime_attributes
63
- end
59
+ @time_jawn_date_time_attributes || _datetime_attributes
64
60
  end
65
61
  end
@@ -9,7 +9,7 @@ describe Happening do
9
9
  context 'class method' do
10
10
  describe "datetime_attributes" do
11
11
  it "returns an array of all datetime objects for the class" do
12
- expect(Happening._datetime_attributes).to eq [:start_time, :created_at, :updated_at]
12
+ expect(Happening._datetime_attributes).to eq [:start_time, :created_at, :updated_at]
13
13
  end
14
14
  end
15
15
  describe "has_time_zone" do
@@ -22,9 +22,9 @@ describe Happening do
22
22
  expect(Happening.instance_methods.include? :local_updated_at=).to eq false
23
23
  end
24
24
  it "has instance methods once called " do
25
-
25
+
26
26
  Happening.has_time_zone
27
-
27
+
28
28
  expect(Happening.instance_methods.include? :local_start_time).to eq true
29
29
  expect(Happening.instance_methods.include? :local_created_at).to eq true
30
30
  expect(Happening.instance_methods.include? :local_updated_at).to eq true
@@ -126,7 +126,7 @@ describe Happening do
126
126
  describe "local_start_time=(time_or_string)" do
127
127
  it "sets start_time on the instance to a time_with_zone object only modifying the time zone" do
128
128
  expect(@happening1.start_time).to eq 'Mon, 01 Apr 2013 00:01:00 UTC +00:00'
129
-
129
+
130
130
  @happening1.local_start_time = Time.parse("Thu, 29 Aug 2013 02:40:12 HST -10:00")
131
131
  expect(@happening1.start_time).to eq Time.parse("2013-08-29 02:40:12 -0400")
132
132
 
@@ -148,7 +148,7 @@ describe Happening do
148
148
  describe "local_updated_at=(time_or_string)" do
149
149
  it "sets updated_at on the instance to a time_with_zone object only modifying the time zone" do
150
150
  expect(@happening1.updated_at).to eq 'Tue, 01 Jan 2013 00:01:00 +0000'
151
-
151
+
152
152
  @happening1.local_updated_at = Time.parse("Thu, 29 Aug 2013 02:40:12 HST -10:00")
153
153
  expect(@happening1.updated_at).to eq Time.parse("2013-08-29 02:40:12 -0400")
154
154
 
@@ -170,7 +170,7 @@ describe Happening do
170
170
  describe "local_created_at=(time_or_string)" do
171
171
  it "sets created_at on the instance to a time_with_zone object only modifying the time zone" do
172
172
  expect(@happening1.created_at).to eq ' Tue, 01 Jan 2013 00:01:00 +0000'
173
-
173
+
174
174
  @happening1.local_created_at = Time.parse("Thu, 29 Aug 2013 02:40:12 HST -10:00")
175
175
  expect(@happening1.created_at).to eq Time.parse("2013-08-29 02:40:12 -0400")
176
176
 
@@ -215,7 +215,7 @@ describe Occurrence do
215
215
  before do
216
216
  @occurrence1 = Occurrence.find_by_name('Eastern Time (US & Canada)')
217
217
  end
218
-
218
+
219
219
  context "Ocurrence instance attribute accessor" do
220
220
  describe "time_zone_attribute_name" do
221
221
  it 'should respond with the time_zone attribute name as defined in the class.' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_jawn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Platt
@@ -14,76 +14,76 @@ dependencies:
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
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: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.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
40
  version: '3.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
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: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3-ruby
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: timecop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: TimeJawn makes class instances time zone aware. It doesn't care one iota
84
84
  about system, application or database time as far as I can tell. It has some expectations
85
85
  and adds some useful methods.
86
- email: mplatt@tammantech.com
86
+ email: mark@mrkplt.com
87
87
  executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
@@ -92,7 +92,7 @@ files:
92
92
  - lib/time_jawn/time_jawn.rb
93
93
  - lib/time_jawn/time_jawn_private_class_methods.rb
94
94
  - spec/time_jawn_spec.rb
95
- homepage: http://tammantech.com
95
+ homepage: https://github.com/mrkplt/time_jawn
96
96
  licenses:
97
97
  - MIT
98
98
  metadata: {}
@@ -102,17 +102,17 @@ require_paths:
102
102
  - lib
103
103
  required_ruby_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ! '>='
105
+ - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: 1.9.3
108
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ! '>='
110
+ - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.0.7
115
+ rubygems_version: 2.2.2
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: TimeJawn makes time zone aware class instances.