Skip to content
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

Jl form functionality cleanup #157

Merged
merged 8 commits into from Mar 28, 2017
Merged

Conversation

jleonardw9
Copy link

No description provided.

modifier = ''
((time.first == '0') || (time[0..1] == '10') || (time[0..1] == '11')) ? modifier = ' AM' : modifier = ' PM'

DateTime.strptime(time.gsub(':', ''), '%H%M').strftime('%l:%M') + modifier

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a placeholder for AM/PM in DateTime.strptime. %p should do it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of like my modifier code, so I think I'm going to leave it in.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what the modifier is doing? I'm a bit confused about the '0' || '10' || '11' part

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's converting military time to regular time. So if a time string has either '0', '10', or '11' as the leading characters then it is in the morning. All else are PM.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use DateTime.strptime(time, '%H:%M').strftime('%l:%M %p') to do the same thing all in 1 line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally missed this comment last week. Your suggestion worked great, should be up there now.

@bmic-development
Copy link
Owner

bmic-development commented Mar 20, 2017 via email

modifier = ''
((time.first == '0') || (time[0..1] == '10') || (time[0..1] == '11')) ? modifier = ' AM' : modifier = ' PM'

DateTime.strptime(time.gsub(':', ''), '%H%M').strftime('%l:%M') + modifier

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use DateTime.strptime(time, '%H:%M').strftime('%l:%M %p') to do the same thing all in 1 line

@amcates
Copy link
Collaborator

amcates commented Mar 27, 2017

@jleonardw9 I have to agree with Kyle. Using the strptime method instead of custom code would be better in this case.

@jleonardw9
Copy link
Author

Yeah, I agree as well. Just changed it.

- elsif item.item_type == 'time'
= convert_time(qr.content)
- elsif item.item_type == 'checkbox'
= qr.content.gsub(/["\[\]]/, '')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested qr.content.delete('[]').delete('\"') and qr.content.gsub(/["\[\]]/, '') and they appear to be doing the same thing: Replacing/removing the characters []". We should combine this block and the if block into a single statement.
if ['checkbox', 'multiple_dropdown'].include?(item.item_type)
qr.content.delete('[]\"') or qr.content.gsub(/["\[\]]/, '')

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would label that a refactor and make another pull request. Not necessary to proceed. In the same thought you could change 'qr.content.gsub' to another method call similar to convert_time.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

@amcates amcates dismissed kayla-glick’s stale review March 27, 2017 17:56

Code can be refactored after the fact. Works fine the way it is currently written.

@Stuart-Johnson Stuart-Johnson merged commit 8dd1347 into master Mar 28, 2017
@Stuart-Johnson Stuart-Johnson deleted the jl-form-functionality-cleanup branch March 28, 2017 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants