dtg 3.0.2 → 4.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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47fcb47b9cfc284a3b42dbcc6d24c0410aa118ecd2042927a03d257a603fd418
4
- data.tar.gz: 74290a6d0acbe433ba776eb30a54276a3cff61e3d7c9bf940777d8b6278e0800
3
+ metadata.gz: 9baca4fefe520ca79708b64acb9ff54caa9dc5f5e4757af1da08040afe1310cd
4
+ data.tar.gz: 366d56c174427106189bfcbf316b1b366bdb47de0f7319a5fb7685d907e17cbb
5
5
  SHA512:
6
- metadata.gz: '0559e9975d5cba18e10097ba63781ce6db455724d8c8d1b40f4c03811a27279c04aaef16a4e58e8545b34fe384410d5f02a3e81666ec9e7fec2c6b0edb8a1b0c'
7
- data.tar.gz: f76fa8ab12623ddfe75a047705b8d3deae5999408eda1c0ef12cd29b5a0c3f81cec2f510b4bfe0d317b1787cdaab9a2ed8bc9c6bc1763b5c2465f9d3f0a0798c
6
+ metadata.gz: 2d90ad0ef678fe647a554bb38ad1f1b4ccfe7acd4b4005855422259f1d4c5ae8690ff385c949109bf8f0480dbf37d8c5ffd4d647e897f9313f7f3886988e07b5
7
+ data.tar.gz: c228294640713a51dcc3c1d5f63af0106643b29b38afe0e8e1c1c3cc07aa2f796caacfa4543077782cc4f738212b06792cf5cada51cc9cfd3ab22f1b92c62eaa
data/Gemfile ADDED
@@ -0,0 +1,49 @@
1
+ source "https://rubygems.org"
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in dtg.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
13
+
14
+ # Used to test this gem for compatability and functionality
15
+ group :development, :test do
16
+ gem "cadre"
17
+
18
+ # Used for test suite reporting
19
+ gem 'coveralls', require: false
20
+
21
+ # Find places where code can be sped up
22
+ gem "fasterer"
23
+
24
+ # Code quality
25
+ gem "guard"
26
+ gem "guard-reek"
27
+ gem "guard-rspec"
28
+ gem "guard-rubocop"
29
+
30
+ # Check code quality extensions on git actions
31
+ gem "overcommit"
32
+
33
+ # Detect code smells for bad/strage code
34
+ gem "reek"
35
+
36
+ # RSpec for testing suite
37
+ gem "rspec"
38
+ gem "rspec-core"
39
+ gem "rspec-expectations"
40
+ gem "rspec-mocks"
41
+ gem "rspec-support"
42
+
43
+ # Code quality enforcer
44
+ gem "rubocop", "0.65.0"
45
+ gem "rubocop-rspec"
46
+
47
+ # StandardRB checks for consistent ruby conventions
48
+ gem "standard"
49
+ end
data/Rakefile CHANGED
@@ -1,27 +1,4 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'Dtg'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.md')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
- require 'bundler/gem_tasks'
18
-
19
- # RSpec rake task to run rspec on default - needed by travis
20
- begin
21
- require 'rspec/core/rake_task'
22
- RSpec::Core::RakeTask.new(:spec)
23
-
24
- task :default => :spec
25
- rescue LoadError
26
- # no rspec available
27
- end
1
+ # desc "Explaining what the task does"
2
+ # task :dtg do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,47 @@
1
+ # Ensure all of library added to gem
2
+ $:.push File.expand_path("lib", __dir__)
3
+
4
+ # Maintain your gem's version:
5
+ require "dtg/version"
6
+
7
+ # Describe your gem and declare its dependencies:
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "dtg"
10
+ spec.version = Dtg::VERSION
11
+ spec.authors = ["SolarisFlare"]
12
+ spec.email = ["shadowbomb20@gmail.com"]
13
+ spec.homepage = "https://github.com/SolarisFlare/dtg/"
14
+ spec.summary = "DTG converts from a DateTime to a DTG"
15
+ spec.description = "A DTG is a DateTimeGroup which is used in the military to save time. DTG
16
+ are saved in the format DDHHMML MMM YY, where D is day, H is hour, L is
17
+ letter, M is month, and Y is year. The Month is the 3 character
18
+ representation such as JAN for January, MAY for May, DEC for December and so
19
+ on. Year is only the last two digits of the year e.g. 2019 is just 19. The
20
+ letter is the zone code such as W for whiskey which is HST, Z for zulu which
21
+ is GMT, A-Z are the zones used."
22
+ spec.license = "MIT"
23
+ spec.required_rubygems_version = Gem::Requirement.new(">= 0") if spec.respond_to? \
24
+ :required_rubygems_version=
25
+ spec.files = Dir["Gemfile", "dtg.gemspec", "Rakefile", "lib/**/*"]
26
+ spec.test_files = Dir["spec/**/*"]
27
+ spec.rubygems_version = %q{1.6.2}
28
+
29
+ # Active support is necessary for ActiveSupport::TimeWithZone integration
30
+ spec.add_dependency "activesupport"
31
+
32
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
33
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
34
+ if spec.respond_to?(:metadata)
35
+ spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
36
+ else
37
+ raise "RubyGems 2.0 or newer is required to protect against " \
38
+ "public gem pushes."
39
+ end
40
+
41
+ if spec.respond_to? :specification_version then
42
+ spec.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ end
46
+ end
47
+ end
data/lib/dtg.rb CHANGED
@@ -1,35 +1,15 @@
1
- require "dtg/railtie"
2
- require "dtg/zones"
3
- require "dtg/date_time_ext"
4
- require "dtg/time_ext"
5
- require "dtg/active_support/time_with_zone_ext"
1
+ require_relative "dtg/version"
2
+ require_relative "dtg/date_time_group"
3
+ require_relative "dtg/zones"
4
+ require_relative "dtg/time_ext"
5
+ require_relative "dtg/date_time_ext"
6
+ require_relative "dtg/active_support/time_with_zone_ext"
6
7
 
7
8
  module Dtg
8
- # Zones module has timezones (UTC_Zones) as dtg listings
9
- include Zones
9
+ # Time zone safety setting
10
+ Time.zone ||= 'UTC'
10
11
 
11
- # DTG Test to determine if was injected properly into class
12
- def dtg
13
- "DTG gem is natively integrated with this class: #{self.class}"
14
- end
15
-
16
- # Convert the object to the proper zone and then format as dtg in zone
17
- def to_dtg(zone = :z)
18
- convert(zone).format(zone)
19
- end
20
-
21
- # Format the object into specified zone (as dtg)
22
- def format(zone = :z)
23
- key = zone.downcase.to_sym
24
- raise "Error: #{zone} is not a valid zone" unless UTC_ZONES.key?(key)
25
- dtg = "%d%H%M#{key.upcase.to_s} %b %y"
26
- strftime(dtg)
27
- end
28
-
29
- # Convert the object into the proper zone specified
30
- def convert(zone = :z)
31
- key = zone.downcase.to_sym
32
- raise "Error: #{zone} is not a valid zone" unless UTC_ZONES.key?(key)
33
- key == :j ? self.dup : self.in_time_zone(UTC_ZONES[key])
12
+ def self.dtg
13
+ "DTG gem is active"
34
14
  end
35
15
  end
@@ -1,6 +1,7 @@
1
- require 'dtg'
1
+ require_relative "../date_time_group"
2
+ require "active_support/time"
2
3
 
3
4
  class ActiveSupport::TimeWithZone
4
5
  # Insert DTG Methods into this class
5
- include Dtg
6
+ include DateTimeGroup
6
7
  end
@@ -1,6 +1,9 @@
1
- require 'dtg'
1
+ require_relative "date_time_group"
2
+ require "date"
3
+ require "active_support/core_ext/date"
4
+ # require "active_support/core_ext/date_and_time"
2
5
 
3
6
  class DateTime
4
7
  # Insert DTG Methods into this class
5
- include Dtg
8
+ include DateTimeGroup
6
9
  end
@@ -0,0 +1,31 @@
1
+ require_relative "zones"
2
+
3
+ module DateTimeGroup
4
+ # Zones module has timezones (UTC_Zones) as dtg listings
5
+ include Zones
6
+
7
+ # Convert the object to the proper zone and then format as dtg in zone
8
+ def to_dtg(zone = :z)
9
+ convert(zone).format(zone)
10
+ end
11
+
12
+ # DTG Test to determine if was injected properly into class
13
+ def dtg
14
+ "DTG gem is natively integrated with this class: #{self.class}"
15
+ end
16
+
17
+ # Format the object into specified zone (as dtg)
18
+ def format(zone = :z)
19
+ key = zone.downcase.to_sym
20
+ raise "Error: #{zone} is not a valid zone" unless UTC_ZONES.key?(key)
21
+ dtg = "%d%H%M#{key.upcase.to_s} %b %y"
22
+ strftime(dtg)
23
+ end
24
+
25
+ # Convert the object into the proper zone specified
26
+ def convert(zone = :z)
27
+ key = zone.downcase.to_sym
28
+ raise "Error: #{zone} is not a valid zone" unless UTC_ZONES.key?(key)
29
+ key == :j ? self.dup : self.in_time_zone(UTC_ZONES[key])
30
+ end
31
+ end
@@ -1,6 +1,7 @@
1
- require 'dtg'
1
+ require_relative "date_time_group"
2
+ require "active_support/core_ext/time"
2
3
 
3
4
  class Time
4
5
  # Insert DTG Methods into this class
5
- include Dtg
6
+ include DateTimeGroup
6
7
  end
@@ -1,4 +1,4 @@
1
1
  module Dtg
2
2
  # DTG version of gem
3
- VERSION = "3.0.2"
3
+ VERSION = "4.0.0"
4
4
  end
@@ -0,0 +1,164 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe ActiveSupport::TimeWithZone do
4
+ # ActiveSupport::TimeWithZone preferred method of instantiation is with Time.zone.now, not new
5
+ let(:time) { Time.zone.now { include DateTimeGroup }}
6
+
7
+ describe "#to_dtg" do
8
+ context "when zone is a symbol" do
9
+ context "when symbol is lowercase" do
10
+ it "converts and formats as dtg" do
11
+ (:a..:z).to_set.delete(:j).each do |zone|
12
+ expect(time.to_dtg(zone)).to eq(time.in_time_zone(
13
+ Zones::UTC_ZONES[zone])
14
+ .strftime(
15
+ "%d%H%M#{zone.upcase.to_s} %b %y"))
16
+ end
17
+ # :j is separate because there is no local timezone identifier,
18
+ # it just gets returned and formatted
19
+ expect(time.to_dtg(:j)).to eq(time.format(:j))
20
+ end
21
+ end
22
+
23
+ context "when symbol is uppercase" do
24
+ it "converts and formats as dtg" do
25
+ (:A..:Z).to_set.delete(:J).each do |zone|
26
+ expect(time.to_dtg(zone)).to eq(time.in_time_zone(
27
+ Zones::UTC_ZONES[zone.downcase])
28
+ .strftime(
29
+ "%d%H%M#{zone.to_s} %b %y"))
30
+ end
31
+ # :J is separate because there is no local timezone identifier,
32
+ # it just gets returned and formatted
33
+ expect(time.to_dtg(:J)).to eq(time.format(:j))
34
+ end
35
+ end
36
+ end
37
+
38
+ context "when zone is a single character string" do
39
+ context "when string is lowercase" do
40
+ it "converts and formats as dtg" do
41
+ ('a'..'z').to_set.delete('j').each do |zone|
42
+ expect(time.to_dtg(zone)).to eq(time.in_time_zone(
43
+ Zones::UTC_ZONES[zone.to_sym])
44
+ .strftime(
45
+ "%d%H%M#{zone.upcase} %b %y"))
46
+ end
47
+ # 'j' is separate because there is no local timezone identifier
48
+ # it just gets returned and formatted
49
+ expect(time.to_dtg('j')).to eq(time.format(:j))
50
+ end
51
+ end
52
+
53
+ context "when string is uppercase" do
54
+ it "converts and formats as dtg" do
55
+ ('A'..'Z').to_set.delete('J').each do |zone|
56
+ expect(time.to_dtg(zone)).to eq(time.in_time_zone(
57
+ Zones::UTC_ZONES[zone.downcase.to_sym])
58
+ .strftime(
59
+ "%d%H%M#{zone} %b %y"))
60
+ end
61
+ # 'J' is separate because there is no local timezone identifier,
62
+ # it just gets returned and formatted
63
+ expect(time.to_dtg('J')).to eq(time.format(:j))
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "#format" do
70
+ context "when zone is a symbol" do
71
+ context "when symbol is lowercase" do
72
+ it "formats to dtg standard" do
73
+ (:a..:z).each do |zone|
74
+ expect(time.format(zone)).to eq(time.strftime(
75
+ "%d%H%M#{zone.upcase.to_s} %b %y"))
76
+ end
77
+ end
78
+ end
79
+
80
+ context "when symbol is uppercase" do
81
+ it "formats to dtg standard" do
82
+ (:A..:Z).each do |zone|
83
+ expect(time.format(zone)).to eq(time.strftime(
84
+ "%d%H%M#{zone.to_s} %b %y"))
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ context "when zone is a single character string" do
91
+ context "when string is lowercase" do
92
+ it "formats to dtg standard" do
93
+ ('a'..'z').each do |zone|
94
+ expect(time.format(zone)).to eq(time.strftime(
95
+ "%d%H%M#{zone.upcase} %b %y"))
96
+ end
97
+ end
98
+ end
99
+
100
+ context "when string is uppercase" do
101
+ it "formats to dtg standard" do
102
+ ('A'..'Z').each do |zone|
103
+ expect(time.format(zone)).to eq(time.strftime(
104
+ "%d%H%M#{zone} %b %y"))
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "#convert" do
112
+ context "when zone is a symbol" do
113
+ context "when symbol is lowercase" do
114
+ it "returns converted time to new zone" do
115
+ (:a..:z).to_set.delete(:j).each do |zone|
116
+ expect(time.convert(zone)).to eq(time.in_time_zone(
117
+ Zones::UTC_ZONES[zone]))
118
+ end
119
+ # :j is separate because there is no local timezone identifier,
120
+ # it just gets returned and formatted
121
+ expect(time.convert(:j)).to eq(time)
122
+ end
123
+ end
124
+
125
+ context "when symbol is uppercase" do
126
+ it "returns converted time to new zone" do
127
+ (:A..:Z).to_set.delete(:J).each do |zone|
128
+ expect(time.convert(zone)).to eq(time.in_time_zone(
129
+ Zones::UTC_ZONES[zone.downcase]))
130
+ end
131
+ # :J is separate because there is no local timezone identifier,
132
+ # it just gets returned and formatted
133
+ expect(time.convert(:J)).to eq(time)
134
+ end
135
+ end
136
+ end
137
+
138
+ context "when zone is a single character string" do
139
+ context "when string is lowercase" do
140
+ it "returns converted time to new zone" do
141
+ ('a'..'z').to_set.delete('j').each do |zone|
142
+ expect(time.convert(zone)).to eq(time.in_time_zone(
143
+ Zones::UTC_ZONES[zone.to_sym]))
144
+ end
145
+ # 'j' is separate because there is no local timezone identifier,
146
+ # it just gets returned and formatted
147
+ expect(time.convert('j')).to eq(time)
148
+ end
149
+ end
150
+
151
+ context "when string is uppercase" do
152
+ it "returns converted time to new zone" do
153
+ ('A'..'Z').to_set.delete('J').each do |zone|
154
+ expect(time.convert(zone)).to eq(time.in_time_zone(
155
+ Zones::UTC_ZONES[zone.downcase.to_sym]))
156
+ end
157
+ # 'J' is separate because there is no local timezone identifier,
158
+ # it just gets returned and formatted
159
+ expect(time.convert('J')).to eq(time)
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,163 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe DateTime do
4
+ let(:time) { described_class.now { include DateTimeGroup } }
5
+
6
+ describe "#to_dtg" do
7
+ context "when zone is a symbol" do
8
+ context "when symbol is lowercase" do
9
+ it "converts and formats as dtg" do
10
+ (:a..:z).to_set.delete(:j).each do |zone|
11
+ expect(time.to_dtg(zone)).to eq(time.in_time_zone(
12
+ Zones::UTC_ZONES[zone])
13
+ .strftime(
14
+ "%d%H%M#{zone.upcase.to_s} %b %y"))
15
+ end
16
+ # :j is separate because there is no local timezone identifier,
17
+ # it just gets returned and formatted
18
+ expect(time.to_dtg(:j)).to eq(time.format(:j))
19
+ end
20
+ end
21
+
22
+ context "when symbol is uppercase" do
23
+ it "converts and formats as dtg" do
24
+ (:A..:Z).to_set.delete(:J).each do |zone|
25
+ expect(time.to_dtg(zone)).to eq(time.in_time_zone(
26
+ Zones::UTC_ZONES[zone.downcase])
27
+ .strftime(
28
+ "%d%H%M#{zone.to_s} %b %y"))
29
+ end
30
+ # :J is separate because there is no local timezone identifier,
31
+ # it just gets returned and formatted
32
+ expect(time.to_dtg(:J)).to eq(time.format(:j))
33
+ end
34
+ end
35
+ end
36
+
37
+ context "when zone is a single character string" do
38
+ context "when string is lowercase" do
39
+ it "converts and formats as dtg" do
40
+ ('a'..'z').to_set.delete('j').each do |zone|
41
+ expect(time.to_dtg(zone)).to eq(time.in_time_zone(
42
+ Zones::UTC_ZONES[zone.to_sym])
43
+ .strftime(
44
+ "%d%H%M#{zone.upcase} %b %y"))
45
+ end
46
+ # 'j' is separate because there is no local timezone identifier
47
+ # it just gets returned and formatted
48
+ expect(time.to_dtg('j')).to eq(time.format(:j))
49
+ end
50
+ end
51
+
52
+ context "when string is uppercase" do
53
+ it "converts and formats as dtg" do
54
+ ('A'..'Z').to_set.delete('J').each do |zone|
55
+ expect(time.to_dtg(zone)).to eq(time.in_time_zone(
56
+ Zones::UTC_ZONES[zone.downcase.to_sym])
57
+ .strftime(
58
+ "%d%H%M#{zone} %b %y"))
59
+ end
60
+ # 'J' is separate because there is no local timezone identifier,
61
+ # it just gets returned and formatted
62
+ expect(time.to_dtg('J')).to eq(time.format(:j))
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "#format" do
69
+ context "when zone is a symbol" do
70
+ context "when symbol is lowercase" do
71
+ it "formats to dtg standard" do
72
+ (:a..:z).each do |zone|
73
+ expect(time.format(zone)).to eq(time.strftime(
74
+ "%d%H%M#{zone.upcase.to_s} %b %y"))
75
+ end
76
+ end
77
+ end
78
+
79
+ context "when symbol is uppercase" do
80
+ it "formats to dtg standard" do
81
+ (:A..:Z).each do |zone|
82
+ expect(time.format(zone)).to eq(time.strftime(
83
+ "%d%H%M#{zone.to_s} %b %y"))
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ context "when zone is a single character string" do
90
+ context "when string is lowercase" do
91
+ it "formats to dtg standard" do
92
+ ('a'..'z').each do |zone|
93
+ expect(time.format(zone)).to eq(time.strftime(
94
+ "%d%H%M#{zone.upcase} %b %y"))
95
+ end
96
+ end
97
+ end
98
+
99
+ context "when string is uppercase" do
100
+ it "formats to dtg standard" do
101
+ ('A'..'Z').each do |zone|
102
+ expect(time.format(zone)).to eq(time.strftime(
103
+ "%d%H%M#{zone} %b %y"))
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ describe "#convert" do
111
+ context "when zone is a symbol" do
112
+ context "when symbol is lowercase" do
113
+ it "returns converted time to new zone" do
114
+ (:a..:z).to_set.delete(:j).each do |zone|
115
+ expect(time.convert(zone)).to eq(time.in_time_zone(
116
+ Zones::UTC_ZONES[zone]))
117
+ end
118
+ # :j is separate because there is no local timezone identifier,
119
+ # it just gets returned and formatted
120
+ expect(time.convert(:j)).to eq(time)
121
+ end
122
+ end
123
+
124
+ context "when symbol is uppercase" do
125
+ it "returns converted time to new zone" do
126
+ (:A..:Z).to_set.delete(:J).each do |zone|
127
+ expect(time.convert(zone)).to eq(time.in_time_zone(
128
+ Zones::UTC_ZONES[zone.downcase]))
129
+ end
130
+ # :J is separate because there is no local timezone identifier,
131
+ # it just gets returned and formatted
132
+ expect(time.convert(:J)).to eq(time)
133
+ end
134
+ end
135
+ end
136
+
137
+ context "when zone is a single character string" do
138
+ context "when string is lowercase" do
139
+ it "returns converted time to new zone" do
140
+ ('a'..'z').to_set.delete('j').each do |zone|
141
+ expect(time.convert(zone)).to eq(time.in_time_zone(
142
+ Zones::UTC_ZONES[zone.to_sym]))
143
+ end
144
+ # 'j' is separate because there is no local timezone identifier,
145
+ # it just gets returned and formatted
146
+ expect(time.convert('j')).to eq(time)
147
+ end
148
+ end
149
+
150
+ context "when string is uppercase" do
151
+ it "returns converted time to new zone" do
152
+ ('A'..'Z').to_set.delete('J').each do |zone|
153
+ expect(time.convert(zone)).to eq(time.in_time_zone(
154
+ Zones::UTC_ZONES[zone.downcase.to_sym]))
155
+ end
156
+ # 'J' is separate because there is no local timezone identifier,
157
+ # it just gets returned and formatted
158
+ expect(time.convert('J')).to eq(time)
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end