-
Notifications
You must be signed in to change notification settings - Fork 5
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
API-7308 sparkql date function support for day_of_week, day_of_year, and weekdays. #71
Conversation
assert_equal '2012-10-27', value[:value] | ||
end | ||
|
||
test 'weekdays()' do |
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 is the main test I was concerned about.
:value => "'#{string.to_s.upcase}'" | ||
} | ||
end | ||
def weekdays(number_of_days) |
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.
And here is the new function. It turned out rather well, just don't look at my first implementation 🤣
today = current_date | ||
weekend_start = today.saturday? || today.sunday? | ||
direction = number_of_days.positive? ? 1 : -1 | ||
weeks = (number_of_days / 5.0).to_i |
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.
Shout out to Mr. Lobdell who helped me realize -4/5 == -1
. This is the workaround I came up with to drop the remainder.
[-6, '2012-10-12'], | ||
[-5, '2012-10-15'], | ||
[-1, '2012-10-19'], | ||
[0, '2012-10-22'], |
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.
Oh right, I did make an opinionated decision here on what to do with zero on a weekend. My take is to move it to the following Monday. I've compared this with some online calculators, and they just didn't support zero, which I would be OK with as well.
I'm having a hard time following with the rubocop changes here. From the description, what I had imagined was something like:
I think I'm missing some context here, is all. How does this:
get reduced to this?
Doh, I should have read the next sentence before continuing to try and decipher the code
Looking now. |
Sorry, that was some bad copy-pasta from my conversations with Marcy. I've corrected my summary to use the |
Alright, I think I've gotten the gist here. I do like the shortening of the query for the client. My main concern is, the same with the |
@joshcom and @codygustafson, I needed to make one last change here, as I forgot that sparkql doesn't support underscores for field or function names. I could add that in, but thought renaming my functions to be consistent with what's already here may be reasonable. Does 'dayofyear' or 'doy' and 'dayofweek' or 'dow' fit the bill? |
I would vote for dayofyear but I'll let @joshcom speak up. |
|
Thanks guys, I'll update that and merge this on through! |
When I brought up this feature in grooming, my understanding of the business need here was simply that the queries needed to know if a date was a specific day of the week (e.g. no Tuesday's allowed). However, it seems the more needed feature was actually to articulate a query using a range of weekdays from a date. The specific use case that just came in could still have been accomplished with the original functions, but it would have been a nasty db query:
Would now be:
I steered outside the original estimate to add in this brain teaser of a problem. I believe I've tested the bounds fairly well, but I'm hoping you all would nitpick my approach, or point out some logical or testing holes.
I've also included some project cleanup and rubocop'd the files I touched. These should be in separate commits, so focus on: e5be999 + ac7a0b8. Link for the shift+click struggle bus
One last note: Marcy and I did discuss support for some sort of automatic exclusion for holidays. This seems like a much bigger feature than what we have discussed so far, and we've managed to push back on that as a need for now. This is why I explicitly used the function
weekdays()
even though the ideal feature would amount to a function forbusiness_days()
. I'm booting that idea down the road as far as I can send it.