datemaster 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 99849aac4a3014898bf888508c7c6735aeaa5e2e3b6e66bdd89e2182d102dee3
4
+ data.tar.gz: f7030d59731ffec2f9af9c3f8053fc6d603ea07e3fb87d5170f3055a78d866ac
5
+ SHA512:
6
+ metadata.gz: 6199c70a987ecd2e2e1b142210b530b392c60f037a3e371d8912bfebefdf6bf2e64f7063102dea01d4d9be74f0b34c209a8d9244e578851009973d74b7794699
7
+ data.tar.gz: 0d119d4fffc65029d45f91cfe1b4ce44d759240763001bc42e3dfe0ecdf855b6df5017c8c22ae8bef5f19a1f0e345a11d8d85b386e3298dca1ab633e70b1dc98
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in datemaster.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ datemaster (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.5.1)
10
+ rake (13.2.1)
11
+ rspec (3.13.0)
12
+ rspec-core (~> 3.13.0)
13
+ rspec-expectations (~> 3.13.0)
14
+ rspec-mocks (~> 3.13.0)
15
+ rspec-core (3.13.2)
16
+ rspec-support (~> 3.13.0)
17
+ rspec-expectations (3.13.3)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.13.0)
20
+ rspec-mocks (3.13.2)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.13.0)
23
+ rspec-support (3.13.2)
24
+
25
+ PLATFORMS
26
+ x86_64-darwin-19
27
+
28
+ DEPENDENCIES
29
+ datemaster!
30
+ rake (~> 13.0)
31
+ rspec (~> 3.0)
32
+
33
+ BUNDLED WITH
34
+ 2.2.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Seann Branchfield
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Timemaster
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/timemaster`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'timemaster'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install timemaster
22
+
23
+ ## Usage
24
+
25
+ Here are the basic methods:
26
+
27
+ Converting strings to and from date and datetime:
28
+
29
+ string_to_date
30
+ string_to_datetime
31
+ date_to_string
32
+ datetime_to_string
33
+ date_to_string_european_format
34
+ datetime_to_string_european_format
35
+
36
+ When converting to string, you may pass a second argument as "/", "-", or "" to define separator. "/" is the default.
37
+
38
+ Converting iso strings to and from datetime:
39
+
40
+ iso_string_to_date
41
+ iso_string_to_datetime
42
+ date_to_iso_string
43
+ datetime_to_iso_string
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/timemaster. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
58
+
59
+ ## Code of Conduct
60
+
61
+ Everyone interacting in the Timemaster project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/timemaster/blob/master/CODE_OF_CONDUCT.md).
62
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "datemaster"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/datemaster/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "datemaster"
7
+ spec.version = Datemaster::VERSION
8
+ spec.authors = ["Seann Branchfield"]
9
+ spec.email = ["eselbeus@gmail.com"]
10
+
11
+ spec.summary = "Convert between string and date/datetime formats."
12
+ spec.description = "A gem for time conversions"
13
+ spec.homepage = "https://github.com/Eselbeus/datemaster"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/Eselbeus/datemaster"
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ # spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ # `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ # end
28
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f|
30
+ f.match(%r{\A(?:test|spec|features)/}) || f.match(/\.gem$/)
31
+ }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ # Uncomment to register a new dependency of your gem
38
+ # spec.add_dependency "example-gem", "~> 1.0"
39
+
40
+ # For more information and examples about making a new gem, checkout our
41
+ # guide at: https://bundler.io/guides/creating_gem.html
42
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datemaster
4
+ VERSION = "0.1.0"
5
+ end
data/lib/datemaster.rb ADDED
@@ -0,0 +1,219 @@
1
+ require_relative "datemaster/version" # Adjust the path based on where the file is located
2
+ require 'date'
3
+
4
+ module Datemaster
5
+ class Error < StandardError; end
6
+
7
+ def self.calculate_format(input)
8
+ case input.length
9
+ when 8
10
+ "%m%d%Y"
11
+ when 10
12
+ if input.include?('/')
13
+ "%m/%d/%Y"
14
+ elsif input.include?('-')
15
+ "%m-%d-%Y"
16
+ else
17
+ raise ArgumentError, "Invalid date format"
18
+ end
19
+ when 6
20
+ "%m%d%y"
21
+ when 8
22
+ if input.include?('/')
23
+ "%m/%d/%y"
24
+ elsif input.include?('-')
25
+ "%m-%d-%y"
26
+ else
27
+ raise ArgumentError, "Invalid date format"
28
+ end
29
+ else
30
+ raise ArgumentError, "Invalid date format"
31
+ end
32
+ end
33
+
34
+ def self.calculate_format_european(input)
35
+ case input.length
36
+ when 8
37
+ "%d%m%Y"
38
+ when 10
39
+ if input.include?('/')
40
+ "%d/%m/%Y"
41
+ elsif input.include?('-')
42
+ "%d-%m-%Y"
43
+ else
44
+ raise ArgumentError, "Invalid date format"
45
+ end
46
+ when 6
47
+ "%d%m%y"
48
+ when 8
49
+ if input.include?('/')
50
+ "%d/%m/%y"
51
+ elsif input.include?('-')
52
+ "%d-%m-%y"
53
+ else
54
+ raise ArgumentError, "Invalid date format"
55
+ end
56
+ else
57
+ raise ArgumentError, "Invalid date format"
58
+ end
59
+ end
60
+
61
+ def self.string_to_date(input)
62
+ format = calculate_format(input)
63
+ converted = Date.strptime(input, format)
64
+ puts converted
65
+ return converted
66
+ end
67
+
68
+ def self.iso_string_to_date(iso_string)
69
+ converted = DateTime.iso8601(iso_string).to_date
70
+ puts converted
71
+ return converted
72
+ end
73
+
74
+ def self.string_to_datetime(input)
75
+ format = calculate_format(input)
76
+ converted = DateTime.strptime(input, format)
77
+ puts converted
78
+ return converted
79
+ end
80
+
81
+ def self.iso_string_to_datetime(iso_string)
82
+ converted = DateTime.iso8601(iso_string)
83
+ puts converted
84
+ return converted
85
+ end
86
+
87
+ def self.string_to_date_european(input)
88
+ format = calculate_format_european(input)
89
+ converted = Date.strptime(input, format)
90
+ puts converted
91
+ return converted
92
+ end
93
+
94
+ def self.string_to_datetime_european(input)
95
+ format = calculate_format_european(input)
96
+ converted = DateTime.strptime(input, format)
97
+ puts converted
98
+ return converted
99
+ end
100
+
101
+ def self.date_to_string(input, format="/")
102
+ begin
103
+ case format
104
+ when "/"
105
+ formatted_date = "%02d/%02d/%04d" % [input.month, input.day, input.year]
106
+ when "-"
107
+ formatted_date = "%02d-%02d-%04d" % [input.month, input.day, input.year]
108
+ when ""
109
+ formatted_date = "%02d%02d%04d" % [input.month, input.day, input.year]
110
+ else
111
+ raise ArgumentError, "Invalid format: #{format}"
112
+ end
113
+ puts formatted_date
114
+ return formatted_date
115
+ rescue
116
+ puts "Invalid date format: #{input}"
117
+ end
118
+ end
119
+
120
+ def self.date_to_iso_string(input)
121
+ if input.is_a?(Date) || input.is_a?(DateTime)
122
+ iso_string = input.iso8601
123
+ puts iso_string
124
+ return iso_string
125
+ else
126
+ raise ArgumentError, "Input must be a Date or DateTime object"
127
+ end
128
+ end
129
+
130
+ class << self
131
+ alias_method :datetime_to_iso_string, :date_to_iso_string
132
+ end
133
+
134
+ def self.date_to_string_european_format(input, format="/")
135
+ begin
136
+ case format
137
+ when "/"
138
+ formatted_date = "%02d/%02d/%04d" % [input.day, input.month, input.year]
139
+ when "-"
140
+ formatted_date = "%02d-%02d-%04d" % [input.day, input.month, input.year]
141
+ when ""
142
+ formatted_date = "%02d%02d%04d" % [input.day, input.month, input.year]
143
+ else
144
+ raise ArgumentError, "Invalid format: #{format}"
145
+ end
146
+ puts formatted_date
147
+ return formatted_date
148
+ rescue
149
+ puts "Invalid date format: #{input}"
150
+ end
151
+ end
152
+
153
+ def self.datetime_to_string(input, format="/", full=true)
154
+ begin
155
+ if full
156
+ case format
157
+ when "/"
158
+ formatted_datetime = "%02d/%02d/%04d %02d:%02d:%02d" % [input.month, input.day, input.year, input.hour, input.min, input.sec]
159
+ when "-"
160
+ formatted_datetime = "%02d-%02d-%04d %02d:%02d:%02d" % [input.month, input.day, input.year, input.hour, input.min, input.sec]
161
+ when ""
162
+ formatted_datetime = "%02d%02d%04d%02d%02d%02d" % [input.month, input.day, input.year, input.hour, input.min, input.sec]
163
+ else
164
+ raise ArgumentError, "Invalid format: #{format}"
165
+ end
166
+ else
167
+ case format
168
+ when "/"
169
+ formatted_datetime = "%02d/%02d/%04d" % [input.month, input.day, input.year]
170
+ when "-"
171
+ formatted_datetime = "%02d-%02d-%04d" % [input.month, input.day, input.year]
172
+ when ""
173
+ formatted_datetime = "%02d%02d%04d" % [input.month, input.day, input.year]
174
+ else
175
+ raise ArgumentError, "Invalid format: #{format}"
176
+ end
177
+ end
178
+
179
+ puts formatted_datetime
180
+ return formatted_datetime
181
+ rescue
182
+ puts "Invalid datetime format: #{input}"
183
+ end
184
+ end
185
+
186
+ def self.datetime_to_string_european_format(input, format="/", full=true)
187
+ begin
188
+ if full
189
+ case format
190
+ when "/"
191
+ formatted_datetime = "%02d/%02d/%04d %02d:%02d:%02d" % [input.day, input.month, input.year, input.hour, input.min, input.sec]
192
+ when "-"
193
+ formatted_datetime = "%02d-%02d-%04d %02d:%02d:%02d" % [input.day, input.month, input.year, input.hour, input.min, input.sec]
194
+ when ""
195
+ formatted_datetime = "%02d%02d%04d%02d%02d%02d" % [input.day, input.month, input.year, input.hour, input.min, input.sec]
196
+ else
197
+ raise ArgumentError, "Invalid format: #{format}"
198
+ end
199
+ else
200
+ case format
201
+ when "/"
202
+ formatted_datetime = "%02d/%02d/%04d" % [input.day, input.month, input.year]
203
+ when "-"
204
+ formatted_datetime = "%02d-%02d-%04d" % [input.day, input.month, input.year]
205
+ when ""
206
+ formatted_datetime = "%02d%02d%04d" % [input.day, input.month, input.year]
207
+ else
208
+ raise ArgumentError, "Invalid format: #{format}"
209
+ end
210
+ end
211
+
212
+ puts formatted_datetime
213
+ return formatted_datetime
214
+ rescue
215
+ puts "Invalid datetime format: #{input}"
216
+ end
217
+ end
218
+
219
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datemaster
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Seann Branchfield
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-12-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem for time conversions
14
+ email:
15
+ - eselbeus@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - datemaster.gemspec
30
+ - lib/datemaster.rb
31
+ - lib/datemaster/version.rb
32
+ homepage: https://github.com/Eselbeus/datemaster
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ allowed_push_host: https://rubygems.org
37
+ homepage_uri: https://github.com/Eselbeus/datemaster
38
+ source_code_uri: https://github.com/Eselbeus/datemaster
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.2.3
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Convert between string and date/datetime formats.
58
+ test_files: []