-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure character birth century #208
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b8d4a62
remove unused method
jkisor cf374c1
method to ensure century for dates
jkisor ae4f717
ensure century for birth on character page
jkisor 835b984
ensure century for birth on account page
jkisor 0cf84cf
ensure century on upload
jkisor 6667820
ensure century for birth on rankings page
jkisor 78e872d
ensure century for birth from json character endpoint
jkisor cbacb79
rake task to cleanup birth dates in DB
jkisor 4cd0303
move method
jkisor 43aa186
remove duplication from date parsing
jkisor a1872e0
remove nil check
jkisor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module DateHelper | ||
|
||
FORMATS = [ | ||
"%m/%d/%Y %H:%M:%S %p %Z", | ||
"%m/%d/%Y %H:%M:%S %Z" | ||
] | ||
|
||
def self.ensure_century(date) | ||
adjustment = (date.year < 1999) ? 2000 : 0 | ||
date + adjustment.years | ||
end | ||
|
||
def self.parse(date_string) | ||
results = FORMATS.lazy.map do |format| | ||
begin | ||
parsed = DateTime.strptime("#{date_string} EST", format) | ||
ensure_century(parsed) | ||
rescue ArgumentError | ||
puts "ArgumentError caught trying to parse '#{date_string} EST' as a DateTime with format #{format}" | ||
puts "Error was `#{$!}`" | ||
end | ||
end | ||
|
||
results.detect { |date| !date.nil? } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require_relative '../spec_helper' | ||
require './helpers/date_helper' | ||
|
||
describe DateHelper do | ||
describe '.ensure_century' do | ||
before do | ||
date = Date.strptime(date_string, '%m/%d/%Y') | ||
@result = DateHelper.ensure_century(date) | ||
end | ||
|
||
describe 'when date string contains century' do | ||
let(:date_string) { '10/07/2021' } | ||
|
||
it 'returns date with correct century' do | ||
assert_equal(2021, @result.year) | ||
end | ||
end | ||
|
||
describe 'when date string does NOT contain century' do | ||
let(:date_string) { '10/07/21' } | ||
|
||
it 'returns date with correct century' do | ||
assert_equal(2021, @result.year) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is unused.